tvl-depot/users/sterni/nix/num/default.nix
sterni 55a3b3eb81 feat(sterni/nix): add trivial float library
Only implements the different conversion types from and to ints for now.
Unfortunately very reliant on builtins.{floor,ceil} which can't be
implemented purely except very inefficiently (to my knowledge), so it
only really works for C++ Nix >= 2.4. Tests are thus skipped for
C++ Nix 2.3.

Change-Id: Idcb1a11df11e214cdba3f2a0715472b370daa7dc
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9008
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
2023-08-09 12:12:47 +00:00

17 lines
233 B
Nix

{ ... }:
rec {
inherit (builtins)
mul
div
add
sub
;
sign = i: if i < 0 then -1 else 1;
abs = i: if i < 0 then -i else i;
inRange = a: b: x: x >= a && x <= b;
sum = builtins.foldl' (a: b: a + b) 0;
}