NAME
Sidef::Math::Math
DESCRIPTION
This object is the Math department. It handles various math functions, like cos, sin, gcd and others.
SYNOPSIS
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
Inherits methods from:
* Sidef
METHODS
abs
Math.abs() -> Obj
Return the
accuracy
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
acos
Math.acos() -> Obj
Return the
acosec
Math.acosec() -> Obj
Return the
acosech
Math.acosech() -> Obj
Return the
acosh
Math.acosh() -> Obj
Return the
acot
Math.acot() -> Obj
Return the
acotan
Math.acotan() -> Obj
Return the
acotanh
Math.acotanh() -> Obj
Return the
acoth
Math.acoth() -> Obj
Return the
acsc
Math.acsc() -> Obj
Return the
acsch
Math.acsch() -> Obj
Return the
asec
Math.asec() -> Obj
Return the
asech
Math.asech() -> Obj
Return the
asin
Math.asin() -> Obj
Return the
asinh
Math.asinh() -> Obj
Return the
atan
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);
Returns an object of type: Sidef::Types::Number::Number
atan2
Math.atan2(Num, Num) -> Num
This function works in the same way as the atan
function, except that it takes two arguments.
Math.atan2(0, -Math.inf); # returns PI
Returns an object of type: Sidef::Types::Number::Number
atanh
Math.atanh() -> Obj
Return the
avg
Math.avg() -> Obj
Return the
ceil
Math.ceil() -> Obj
Return the
cos
Math.cos(Num) -> Num
Returns the cosine of Num (expressed in radians).
Math.cos(45);
Returns an object of type: Sidef::Types::Number::Number
cosec
Math.cosec() -> Obj
Return the
cosech
Math.cosech() -> Obj
Return the
cosh
Math.cosh() -> Obj
Return the
cot
Math.cot() -> Obj
Return the
cotan
Math.cotan() -> Obj
Return the
cotanh
Math.cotanh() -> Obj
Return the
coth
Math.coth() -> Obj
Return the
csc
Math.csc() -> Obj
Return the
csch
Math.csch() -> Obj
Return the
deg2deg
Math.deg2deg() -> Obj
Return the
deg2grad
Math.deg2grad() -> Obj
Return the
deg2rad
Math.deg2rad() -> Obj
Return the
e
Math.e() -> Obj
Return the
exp
Math.exp() -> Obj
Return the
floor
Math.floor() -> Obj
Return the
gcd
Math.gcd(Num, Num, ...) -> Num
Returns the greatest common divisor for a list of numbers.
Math.gcd(64, 40); # returns 8
Returns an object of type: Sidef::Types::Number::Number
get_constant
Math.get_constant() -> Obj
Return the
grad2deg
Math.grad2deg() -> Obj
Return the
grad2grad
Math.grad2grad() -> Obj
Return the
grad2rad
Math.grad2rad() -> Obj
Return the
inf
Math.inf() -> Num
Returns the logical infinite number.
Math.inf; # positive infinity (+1/0)
-Math.inf; # negative infinity (-1/0)
Returns an object of type: Sidef::Types::Number::Number
lcm
Math.lcm(Num, Num, ...) -> Num
Returns the least common multiple for a list of numbers.
Math.lcm(3, 6, 8); # returns 24
Returns an object of type: Sidef::Types::Number::Number
log
Math.log() -> Obj
Return the
log10
Math.log10() -> Obj
Return the
log2
Math.log2() -> Obj
Return the
map
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
max
Math.max() -> Obj
Return the
min
Math.min() -> Obj
Return the
npow
Math.npow() -> Obj
Return the
npow2
Math.npow2() -> Obj
Return the
num2percent
Math.num2percent() -> Obj
Return the
Aliases: number_to_percentage
PI
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().
Returns an object of type: Sidef::Types::Number::Number
pow
Math.pow() -> Obj
Return the
precision
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
Returns an object of type: Sidef::Types::Number::Number
rad2deg
Math.rad2deg() -> Obj
Return the
rad2grad
Math.rad2grad() -> Obj
Return the
rad2rad
Math.rad2rad() -> Obj
Return the
rand
Math.rand() -> Obj
Return the
rangeSum
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().
Returns an object of type: Sidef::Types::Number::Number
sec
Math.sec() -> Obj
Return the
sech
Math.sech() -> Obj
Return the
sin
Math.sin(Num) -> Num
Returns the sine of Num (expressed in radians).
Math.sin(90);
Returns an object of type: Sidef::Types::Number::Number
sinh
Math.sinh() -> Obj
Return the
sqrt
Math.sqrt(Num) -> Num
Returns the positive square root of Num.
Math.sqrt(25); # returns: 5
Returns an object of type: Sidef::Types::Number::Number
sum
Math.sum() -> Obj
Return the
tan
Math.tan() -> Obj
Return the
tanh
Math.tanh() -> Obj
Return the