refactor(nix/sterni/int): rename div & mod to quot & rem
This mirrors the terminology Haskell uses: quot and rem truncate towards zero which is also the case for builtins.div. We can give us the option to introduce Haskell-style int.div and int.mod (to complete the confusion) which would truncate towards negative infinity. Change-Id: Ibebb0a01a73c9718cd62121b2fc2a19c3a4be0de Reviewed-on: https://cl.tvl.fyi/c/depot/+/9009 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
parent
55a3b3eb81
commit
81fc87e29e
2 changed files with 28 additions and 23 deletions
|
@ -23,7 +23,7 @@ let
|
|||
bitShiftR = bit: count:
|
||||
if count == 0
|
||||
then bit
|
||||
else div (bitShiftR bit (count - 1)) 2;
|
||||
else (bitShiftR bit (count - 1)) / 2;
|
||||
|
||||
bitShiftL = bit: count:
|
||||
if count == 0
|
||||
|
@ -85,8 +85,13 @@ let
|
|||
odd = x: bitAnd x 1 == 1;
|
||||
even = x: bitAnd x 1 == 0;
|
||||
|
||||
inherit (builtins) div;
|
||||
mod = a: b: let res = a / b; in a - (res * b);
|
||||
quot' = builtins.div; # no typecheck
|
||||
rem = a: b:
|
||||
assert builtins.isInt a && builtins.isInt b;
|
||||
let res = quot' a b; in a - (res * b);
|
||||
quot = a: b:
|
||||
assert builtins.isInt a && builtins.isInt b;
|
||||
quot' a b;
|
||||
|
||||
in
|
||||
{
|
||||
|
@ -96,8 +101,8 @@ in
|
|||
exp
|
||||
odd
|
||||
even
|
||||
div
|
||||
mod
|
||||
quot
|
||||
rem
|
||||
bitShiftR
|
||||
bitShiftL
|
||||
bitOr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue