Project notes

0001: Exact integers and explicit division

Status: Implemented in 0.2.0-dev. This is a development version, not a released artifact.

Problem

The previous evaluator converted integer arithmetic to float64, losing precision above 2^53. Parsing ignored conversion errors. Integer division silently truncated results, so (72 / 100) * 100 produced zero.

Decision

  • Integers are signed 64-bit values. Integer +, -, *, %, unary negation, and abs() preserve exact values and report overflow.
  • / always returns a finite Float. Binary floating-point rounding still applies; explicit floating-point operations are not arbitrary-precision calculations.
  • div(a, b) requires two integers and truncates the quotient toward zero. A result outside int64 is an error.
  • Integer remainder follows the dividend sign: -7 % 2 is -1. Minimum-int remainder by -1 is zero.
  • Numeric comparisons, equality, min(), max(), and numeric sorting compare actual represented values without first rounding integers to float64.
  • Literals outside the integer range and nonfinite floats are rejected. The minimum signed integer can be written as -9223372036854775808.
  • int() truncates a finite float only if its value is inside the signed range. floor(), ceil(), and round() preserve integer input exactly and reject out-of-range float results.
  • Exponentiation and transcendental math return finite floats or errors. float(integer) explicitly allows rounding to the nearest representable float.

Alternatives

Keeping implicit integer division would reduce compatibility changes but retain surprising percentage calculations. Making all numbers float64 would be simpler but incorrect for identifiers, addresses, and counters. Arbitrary-precision language integers would change the declared type contract and need a separate design.

Compatibility

7 / 2 now produces 3.5; 4 / 2 produces 2.0. Use div(7, 2) for 3. Overflow and nonfinite results now fail instead of wrapping, saturating, or returning special values. See the migration guide.

Regression tests cover exactness, mixed comparisons, negative division/remainder, minimum/maximum values, conversions, and located failures.

Found something to improve?Edit this page on GitHub ↗
Search guides, language features, and APIs ↵ to open first result