tur/math
stdlib/math.tur
thin wrappers around libm functions (sin, cos, sqrt, ...).
Since: Phase B1
defn
sqrt
(sqrt [x :float] :float)
square root of a float (double precision).
Parameters
| x | non-negative float value |
Returns
The square root of x.
Example
(sqrt 2.0) ; => 1.41421
Since: Phase B1
defn
fabs
(fabs [x :float] :float)
absolute value of a float.
Parameters
| x | float value |
Returns
The absolute value of x.
Example
(fabs -3.5) ; => 3.5
Since: Phase B1
defn
floor
(floor [x :float] :float)
largest integer not greater than x.
Parameters
| x | float value |
Returns
Floor of x as a float.
Example
(floor 3.7) ; => 3
Since: Phase B1
defn
ceil
(ceil [x :float] :float)
smallest integer not less than x.
Parameters
| x | float value |
Returns
Ceiling of x as a float.
Example
(ceil 3.2) ; => 4
Since: Phase B1
defn
pow
(pow [x :float y :float] :float)
x raised to the power y.
Parameters
| x | base value | |
| y | exponent |
Returns
x^y as a float.
Example
(pow 2.0 10.0) ; => 1024
Since: Phase B1
defn
int->float
(int->float [n :int] :float)
convert an integer to a float via numeric cast.
Parameters
| n | integer value |
Returns
The integer converted to a double-precision float.
Example
(int->float 42) ; => 42
Since: Phase B1
defn
float->int
(float->int [x :float] :int)
truncate a float to an integer.
Parameters
| x | float value |
Returns
The float truncated toward zero as an int.
Example
(float->int 3.9) ; => 3
Since: Phase B1
defn
printf-float6
(printf-float6 [x :float] :nil)
print a float to stdout with 6 decimal places followed by a
Parameters
| x | float value to print |
Since: Phase B1