Previous: Rest arguments, Up: Functions
Asymptote
has built-in versions of the standard libm
mathematical
real(real) functions sin
, cos
, tan
, asin
,
acos
, atan
, exp
, log
, pow10
,
log10
, sinh
, cosh
, tanh
, asinh
,
acosh
, atanh
, sqrt
, cbrt
, fabs
,
as well as the identity function identity
.
Asymptote
also defines the order n
Bessel functions of
the first kind J(int n, real)
and second kind
Y(int n, real)
, as well as the gamma function gamma
,
the error function erf
, and the complementary error function
erfc
. The standard real(real, real) functions atan2
,
hypot
, fmod
, remainder
are also included.
For convenience, the module math.asy
defines variants
Sin
, Cos
, Tan
, aSin
, aCos
, and
aTan
of the standard trigonometric functions using degrees
rather than radians.
The functions floor
, ceil
, and round
differ from
their usual definitions in that they all return an int value rather than
a real (since that is normally what one wants).
The functions Floor
, Ceil
, and Round
are
respectively similar, except that if the result cannot be converted
to a valid int, they return intMax
for positive arguments and -intMax
for negative arguments,
rather than generating an integer overflow.
We also define a function sgn
, which returns the sign of its
real argument as an integer (-1, 0, or 1).
There is an abs(int)
function, as well as an abs(real)
function
(equivalent to fabs(real)
) and an abs(pair)
function
(equivalent to length(pair)
).
Random numbers can be seeded with srand(int)
and generated with
the int rand()
function, which returns a random integer between 0
and the integer randMax
. A Gaussian random number generator
Gaussrand
and a collection of statistics routines, including
histogram
, are provided in the base file stats.asy
.