8000 `Integer.pow` with a negative exponent uses integer division (`2.pow(-1) == 0`) · Issue #706 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

Integer.pow with a negative exponent uses integer division (2.pow(-1) == 0) #706

Open

Description

@akoskovacs

Integer.pow with a negative exponent (src/stdlib/number.kex ~l.200) returns 1 / this.pow(0 - exponent), which is integer division:

  • 2.pow(-1) == 0, 10.pow(-2) == 0
  • 1.pow(-n) == 1, (-1).pow(-n) == ±1
  • 0.pow(-1) raises division by zero

Is this intended? Alternatives: reject negative exponents with a domain error, or return a Float/Rational for them. Whatever the choice, document it and pin it with a spec.

Unrelated cleanup noticed nearby: Time.floorDiv (src/stdlib/time.kex ~l.515, used in date_time.kex and time.kex) reimplements Integer.div (floored quotient). Replace it with .div if the semantics match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0