parrotcode: Lua Mathematical Library | |
Contents | Language Implementations | Lua |
lib/luamath.pir - Lua Mathematical Library
This library is an interface to the standard C math library.
It provides all its functions inside the table math
.
The library provides the following functions:
math.abs math.acos math.asin math.atan math.atan2
math.ceil math.cos math.cosh math.deg math.exp
math.floor math.fmod math.frexp math.ldexp math.log
math.log10 math.max math.min math.modf math.pow
math.rad math.random math.randomseed math.sin
math.sinh math.sqrt math.tan math.tanh
plus a variable math.pi
and a variable math.huge
, with the value HUGE_VAL
. Most of these functions are only interfaces to the corresponding functions in the C library. All trigonometric functions work in radians. The functions math.deg
and math.rad
convert between radians and degrees.
The function math.max
returns the maximum value of its numeric arguments. Similarly, math.min
computes the minimum. Both can be used with 1, 2, or more arguments.
The function math.modf
corresponds to the modf
C function. It returns two values: The integral part and the fractional part of its argument. The function math.frexp
also returns 2 values: The normalized fraction and the exponent of its argument.
The functions math.random
and math.randomseed
are interfaces to the simple random generator functions rand
and srand
that are provided by ANSI C. (No guarantees can be given for their statistical properties.) When called without arguments, math.random
returns a pseudo-random real number in the range [0,1]. When called with a number n, math.random
returns a pseudo-random integer in the range [1,n]. When called with two arguments, l and u, math.random
returns a pseudo-random integer in the range [l,u]. The math.randomseed
function sets a "seed" for the pseudo-random generator: Equal seeds produce equal sequences of numbers.
See "Lua 5.1 Reference Manual", section 5.6 "Mathematical Functions".
Francois Perrad.
|