mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-04-19 00:19:11 +00:00
bahaghari/lib: add floor and ceil for math subset
Even though they're already available from the builtins, we still want the library subset to feel consistent.
This commit is contained in:
parent
14049db2e4
commit
817ec35b02
@ -48,5 +48,6 @@ pkgs.lib.makeExtensible
|
||||
isNumber scale;
|
||||
|
||||
inherit (self.hex) isHexString;
|
||||
inherit (self.math) abs pow percentage factorial round round' summate product;
|
||||
inherit (self.math) abs pow percentage factorial floor ceil round round'
|
||||
summate product;
|
||||
})
|
||||
|
@ -4,6 +4,10 @@
|
||||
{ pkgs, lib, self }:
|
||||
|
||||
rec {
|
||||
# We have the rounding functions here anyways so we may as well include the
|
||||
# rest of the decimal place changing functions here for consistency.
|
||||
inherit (builtins) floor ceil;
|
||||
|
||||
pi = 3.141592653589793238462643383279502884197;
|
||||
e = 2.7182818284590452353602874713527;
|
||||
|
||||
@ -173,7 +177,7 @@ rec {
|
||||
nearest = pow 10.0 tens;
|
||||
difference = number / nearest;
|
||||
in
|
||||
builtins.floor (difference + 0.5) * nearest;
|
||||
floor (difference + 0.5) * nearest;
|
||||
|
||||
/* Adds all of the given items on the list starting from a sum of zero.
|
||||
|
||||
|
@ -81,6 +81,26 @@ lib.runTests {
|
||||
expected = 0;
|
||||
};
|
||||
|
||||
testMathFloor = {
|
||||
expr = self.math.floor 3.467;
|
||||
expected = 3;
|
||||
};
|
||||
|
||||
testMathFloor2 = {
|
||||
expr = self.math.floor 3.796;
|
||||
expected = 3;
|
||||
};
|
||||
|
||||
testMathCeil = {
|
||||
expr = self.math.ceil 3.469;
|
||||
expected = 4;
|
||||
};
|
||||
|
||||
testMathCeil2 = {
|
||||
expr = self.math.ceil 3.796;
|
||||
expected = 4;
|
||||
};
|
||||
|
||||
testMathRoundDown = {
|
||||
expr = self.math.round 2.3;
|
||||
expected = 2;
|
||||
|
Loading…
Reference in New Issue
Block a user