about summary refs log tree commit diff
path: root/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2023-08-05T15·58+0200
committerclbot <clbot@tvl.fyi>2023-08-11T22·22+0000
commit8fb4c949dc267050b75b2efbcfdff1ca1b307fc5 (patch)
treeff41cc6cef0c321a11fd759e4d9e162a81f9ea1a /tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix
parent81fc87e29ebee143aa27ff6167556db76a803d12 (diff)
test(tvix/eval): check truncation direction of builtins.div r/6480
builtins.div ought to truncate towards zero so that

    -(builtins.div a b) == builtins.div (-a) b
    -(builtins.div a b) == builtins.div a (-b)

Change-Id: I8b7c08cd7f4fa8a1363c786d42c8d484f6cd133d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9006
Autosubmit: sterni <sternenseemann@systemli.org>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix')
-rw-r--r--tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix23
1 files changed, 23 insertions, 0 deletions
diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix
index 98b8b74bdf2b..dc6ce2781593 100644
--- a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix
+++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-div.nix
@@ -8,4 +8,27 @@
   (builtins.div 1 2.0)
   (builtins.div 1.0 2.0)
   (builtins.div (builtins.div 84 4) 0.5)
+
+  # builtins.div should truncate towards 0
+  (builtins.div 3 2)
+  (builtins.div (-3) (-2))
+  (builtins.div (-3) 2)
+  (builtins.div 3 (-2))
+  (-(builtins.div 3 2))
+
+  (builtins.div 4 3)
+  (builtins.div (-4) (-3))
+  (builtins.div (-4) 3)
+  (builtins.div 4 (-3))
+  (-(builtins.div 4 3))
+
+  (builtins.div 5 3)
+  (builtins.div (-5) (-3))
+  (builtins.div (-5) 3)
+  (builtins.div 5 (-3))
+  (-(builtins.div 5 3))
+
+  (builtins.div 2147812578 (-28748))
+  (builtins.div (-2147812578) 28748)
+  (-(builtins.div 2147812578 28748))
 ]