std/math¶
module math
Numbers, in the prelude. abs, pow and sign take an Int or a
Float, and abs and sign a Decimal too; round takes a Float or
a Decimal, and the rest take a Float. float, int and decimal
convert between the three, since no number widens on its own except an
Int beside a Decimal.
abs—selfwithout its sign, at its own type:abs(-3)is3, andabs(-1.50)is1.50.pow—selfraised toexponent, both of one type:pow(2, 10)is1024.sign—-1,0or1by the sign ofself, as anInt:sign(-0.5)is-1.float—selfas aFloat, theFloatnearest it:float(1.10)is1.1.int— The integer part ofself, as anInt, the fraction dropped toward zero:int(-2.9f)is-2.decimal—selfas aDecimal: anIntexactly, and aFloatby the shortest digits that read back as it:decimal(0.1f)is0.1.gcd— The greatest common divisor ofselfandother, at least 0:gcd(12, 18)is6, andgcd(0, 0)is0.sqrt— The square root ofself:sqrt(2.0f)is1.4142135623730951.floor— The greatest whole number not aboveself, as aFloat:floor(-1.5f)is-2.0.ceil— The least whole number not belowself, as aFloat:ceil(-1.5f)is-1.0.round— The whole number nearestself, as aFloat; a value halfway between two rounds away from zero:2.5f | roundis3.0.exp— e raised toself:exp(1.0f)is2.718281828459045.ln— The natural logarithm ofself:ln(1.0f)is0.0.log10— The base-10 logarithm ofself:log10(1000.0f)is3.0.sin— The sine ofself, an angle in radians:sin(0.0f)is0.0.cos— The cosine ofself, an angle in radians:cos(0.0f)is1.0.tan— The tangent ofself, an angle in radians:tan(0.0f)is0.0.