Files
regorus/tests/interpreter/cases/builtins/numbers/div.yaml
Anand Krishnamoorthi a8a3a9809b feat!: Use num-bigint for large numbers (#500)
- Supply chain: Use the popular num-bigint crate for handling large integers
- Optimization: Handle f64, i64, u64 directly. These will be the most common instances of a number.

OPA number semantics isn't clear.
https://github.com/open-policy-agent/opa/issues/6281

As part of this change, we update the following failing tests:
- A local test that relies on what 15.3/3 evaluates to.
 With our current change, we round in a different direction than what OPA does, but consistent
 with Rust. We produce 5.1000000000000005 where as the OPA test expects 5.1.
 There is no clear definition in Rego of what the right answer is. Moreover, policies should not
 rely on exact floating point value comparison. Therefore this deviations is justified.
 The test is patched to pass.
- Another local vm test that exercised 1.1 + 2.2
- Another local vm test that exercises 5.5 - 2.2
- An OPA test that expects that a large integer number say 10e308 is printed in exponent notation.
 num-bigint does not print using scientific notation and instead prints all the digits.
 The benefit of preserving this compatibility is not clear. We skip this test.
- Doc tests that exercised handling floating point numbers with more than 15 (what f64 supports)
  digits of precision. There is no usecase for this scenario. The tests are updated to reflect
  the behavior.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
2025-12-01 13:25:02 -06:00

49 lines
985 B
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cases:
- note: div
data: {}
modules:
- |
package test
import future.keywords.if
# Undefined
y if false
b = y / 1
c = 1 / y
d = 15.3 / 3
e = 13 / 4
z {
x = 1/3
y = 0.3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
x == y
}
query: data.test
want_result:
d: 5.1000000000000005 # 15.3/3 in IEEE754 rounds slightly above 5.1; keep the literal parsed value for parity with runtime results.
e: 3.25
- note: non-numeric
data: {}
modules:
- |
package test
x = "1" / 9
query: data.test.x
error: "`div` expects numeric argument."
- note: div by zero
data: {}
modules:
- |
package test
a = 1/ 0
query: data.test
error: divide by zero