Skip to content

Commit a8a3a98

Browse files
authored
feat!: Use num-bigint for large numbers (microsoft#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. open-policy-agent/opa#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>
1 parent 14deaaa commit a8a3a98

14 files changed

Lines changed: 949 additions & 440 deletions

File tree

Cargo.lock

Lines changed: 23 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ doctest = false
2222
[features]
2323
default = ["full-opa", "arc", "rvm"]
2424

25-
arc = ["scientific/arc"]
25+
arc = []
2626
ast = []
2727
azure_policy = ["dep:jsonschema", "arc", "dashmap"]
2828
azure-rbac = []
@@ -101,7 +101,8 @@ lazy_static = { version = "1.4.0", default-features = false }
101101
thiserror = { version = "2.0", default-features = false }
102102

103103
data-encoding = { version = "2.8.0", optional = true, default-features=false, features = ["alloc"] }
104-
scientific = { version = "0.5.3", default-features = false }
104+
num-bigint = { version = "0.4", default-features = false }
105+
num-traits = { version = "0.2", default-features = false }
105106

106107
globset = { version = "0.4.16", features = ["simd-accel"], default-features = false, optional = true }
107108
regex = {version = "1.11.1", optional = true, default-features = false }

bindings/ffi/Cargo.lock

Lines changed: 19 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)