Sidef::Math::Math
This object is the Math department. It handles various math functions, like cos, sin, gcd and others.
Special Numbers
var pi = Math.pi; var inf = Math.inf;
Calculation precision
Math.precision(-32); # precision to 32 decimal digits Math.accuracy(64); # accuracy to 64 digits
Math functions
var sqrt = Math.sqrt(5); var gcd = Math.gcd(81, 21, 63);
Inherits methods from:
* Sidef
Math.abs() -> Obj
Return the
Math.accuracy() -> Num
Set the calculation accuracy at an arbitrary number of digits.
Math.accuracy(128); # sets the accurracy to 128 digits
Returns an object of type: Sidef::Types::Number::Number
Sidef::Types::Number::Number
Math.acos() -> Obj
Math.acosec() -> Obj
Math.acosech() -> Obj
Math.acosh() -> Obj
Math.acot() -> Obj
Math.acotan() -> Obj
Math.acotanh() -> Obj
Math.acoth() -> Obj
Math.acsc() -> Obj
Math.acsch() -> Obj
Math.asec() -> Obj
Math.asech() -> Obj
Math.asin() -> Obj
Math.asinh() -> Obj
Math.atan(Num) -> Num
This functions takes one arguments and calculcates the arctangent of it in the range -PI to PI.
Math.atan(1/180);
Math.atan2(Num, Num) -> Num
This function works in the same way as the atan function, except that it takes two arguments.
atan
Math.atan2(0, -Math.inf); # returns PI
Math.atanh() -> Obj
Math.avg() -> Obj
Math.ceil() -> Obj
Math.cos(Num) -> Num
Returns the cosine of Num (expressed in radians).
Math.cos(45);
Math.cosec() -> Obj
Math.cosech() -> Obj
Math.cosh() -> Obj
Math.cot() -> Obj
Math.cotan() -> Obj
Math.cotanh() -> Obj
Math.coth() -> Obj
Math.csc() -> Obj
Math.csch() -> Obj
Math.deg2deg() -> Obj
Math.deg2grad() -> Obj
Math.deg2rad() -> Obj
Math.e() -> Obj
Math.exp() -> Obj
Math.floor() -> Obj
Math.gcd(Num, Num, ...) -> Num
Returns the greatest common divisor for a list of numbers.
Math.gcd(64, 40); # returns 8
Math.get_constant() -> Obj
Math.grad2deg() -> Obj
Math.grad2grad() -> Obj
Math.grad2rad() -> Obj
Math.inf() -> Num
Returns the logical infinite number.
Math.inf; # positive infinity (+1/0) -Math.inf; # negative infinity (-1/0)
Math.lcm(Num, Num, ...) -> Num
Returns the least common multiple for a list of numbers.
Math.lcm(3, 6, 8); # returns 24
Math.log() -> Obj
Math.log10() -> Obj
Math.log2() -> Obj
Math.map(amount, from, to) -> Array
This function returns an amount of numbers mapped between from and to, each number having the same distance between each other.
Math.map(8, 1, 3); # returns: [1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75]
Returns an object of type: Sidef::Types::Array::Array
Sidef::Types::Array::Array
Math.max() -> Obj
Math.min() -> Obj
Math.npow() -> Obj
Math.npow2() -> Obj
Math.num2percent() -> Obj
Aliases: number_to_percentage
Math.PI(Num) -> Num
Returns the PI number. The function can take an optional argument, which must be a positive integer, and returns the PI with the Num number of digits.
Math.pi; # returns PI (default: 40 places) Math.pi(320) # returns PI at 320 places accuracy
Aliases: pi().
Math.pow() -> Obj
Math.precision(Num) -> Num
Set the calculation precision. A negative number indicates decimal precision. Basically, this functions just rounds all the numbers to the Numth digit.
Math.precision(1); # int mode: 10/3 == 3 Math.precision(-3); # mini mode: 10/3 == 3.333
Math.rad2deg() -> Obj
Math.rad2grad() -> Obj
Math.rad2rad() -> Obj
Math.rand() -> Obj
Math.rangeSum(from, to, step) -> Num
Returns the sum for a given range of numbers and an optional step.
Math.rangeSum(1, 9); # returns: 45 (1+2+3+...+9) Math.rangeSum(1, 9, 2); # returns: 25 (1+3+5+...+9)
Aliases: range_sum().
Math.sec() -> Obj
Math.sech() -> Obj
Math.sin(Num) -> Num
Returns the sine of Num (expressed in radians).
Math.sin(90);
Math.sinh() -> Obj
Math.sqrt(Num) -> Num
Returns the positive square root of Num.
Math.sqrt(25); # returns: 5
Math.sum() -> Obj
Math.tan() -> Obj
Math.tanh() -> Obj
To install Sidef, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sidef
CPAN shell
perl -MCPAN -e shell install Sidef
For more information on module installation, please visit the detailed CPAN module installation guide.