From 984ea69386a47e753c4129e2a6230aa60b4584cd Mon Sep 17 00:00:00 2001 From: sterni Date: Sat, 5 Aug 2023 15:39:56 +0200 Subject: refactor(users/sterni/nix): move generic number operation into num We omit type checks for performance reasons in most places currently, so the library grouping is important in showing people what to use for what sort of input. The moved functions make sense to use with floats as well, so we'll move them to the num library. Some of the remaining functions could theoretically be adapted and moved, but aren't for now. Change-Id: Ifdecaa60be594f4438b2a58b9ea6445e2da080e3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9007 Tested-by: BuildkiteCI Reviewed-by: sterni --- users/sterni/nix/num/default.nix | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 users/sterni/nix/num/default.nix (limited to 'users/sterni/nix/num/default.nix') diff --git a/users/sterni/nix/num/default.nix b/users/sterni/nix/num/default.nix new file mode 100644 index 000000000000..640493083722 --- /dev/null +++ b/users/sterni/nix/num/default.nix @@ -0,0 +1,16 @@ +{ ... }: + +rec { + inherit (builtins) + mul + div + add + sub + ; + + 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; +} -- cgit 1.4.1