mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-30 22:57:55 +00:00
bahaghari/lib: add radian <-> degree conversion in math subset
This commit is contained in:
parent
5003d9723a
commit
cf23a92548
@ -50,5 +50,5 @@ pkgs.lib.makeExtensible
|
||||
|
||||
inherit (self.hex) isHexString;
|
||||
inherit (self.math) abs pow percentage factorial floor ceil round round'
|
||||
summate product sqrt;
|
||||
summate product sqrt remainder mod radiansToDegrees degreesToRadians;
|
||||
})
|
||||
|
@ -313,4 +313,35 @@ rec {
|
||||
=> 24
|
||||
*/
|
||||
product = builtins.foldl' builtins.mul 1;
|
||||
|
||||
/* Given a number in radians, convert it to degrees.
|
||||
|
||||
Type: radiansToDegrees :: Number -> Number
|
||||
|
||||
Example:
|
||||
radiansToDegrees bahaghariLib.math.constants.pi
|
||||
=> 180
|
||||
|
||||
radiansToDegrees 180
|
||||
=> 10313.240312355
|
||||
*/
|
||||
radiansToDegrees = x:
|
||||
x * 180.0 / constants.pi;
|
||||
|
||||
/* Given a number in degrees unit, convert it to radians.
|
||||
|
||||
Type: degreesToRadians :: Number -> Number
|
||||
|
||||
Example:
|
||||
degreesToRadians 180
|
||||
=> 3.141592653589793238462643383279502884197
|
||||
|
||||
degreesToRadians 360
|
||||
=> 6.283185307
|
||||
|
||||
degreesToRadians 95
|
||||
=> 1.658062789
|
||||
*/
|
||||
degreesToRadians = x:
|
||||
x * constants.pi / 180.0;
|
||||
}
|
||||
|
@ -332,4 +332,34 @@ lib.runTests {
|
||||
expr = round' (self.math.exp 2);
|
||||
expected = 7.3890560989;
|
||||
};
|
||||
|
||||
testDegreesToRadians = {
|
||||
expr = self.math.degreesToRadians 180;
|
||||
expected = self.math.constants.pi;
|
||||
};
|
||||
|
||||
testDegreesToRadians2 = {
|
||||
expr = self.math.degreesToRadians 360;
|
||||
expected = self.math.constants.pi * 2;
|
||||
};
|
||||
|
||||
testDegreesToRadians3 = {
|
||||
expr = self.math.round' (-5) (self.math.degreesToRadians 95);
|
||||
expected = 1.65806;
|
||||
};
|
||||
|
||||
testRadiansToDegrees = {
|
||||
expr = self.math.radiansToDegrees self.math.constants.pi;
|
||||
expected = 180;
|
||||
};
|
||||
|
||||
testRadiansToDegrees2 = {
|
||||
expr = self.math.round' (-3) (self.math.radiansToDegrees 180);
|
||||
expected = 10313.24;
|
||||
};
|
||||
|
||||
testRadiansToDegrees3 = {
|
||||
expr = self.math.round' (-3) (self.math.radiansToDegrees 4.5);
|
||||
expected = 257.831;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user