M_Real
— Agar-Math
real number operations
#include <agar/core.h>
#include <agar/gui.h>
#include <agar/math/m.h>
Real numbers in Agar-Math are most often described using the
M_Real
type. Depending on which precision mode the
library was compiled against (see the --with-<mode>-fp configure
option), M_Real
may expand to
float (32-bit,
SINGLE_PRECISION
is defined) or
double (64-bit,
DOUBLE_PRECISION
is defined).
Most Agar-Math structures use M_Real
to
represent floating-point numbers. The real and imaginary parts of
M_Complex(3),
and the elements of
M_Vector(3)
and
M_Matrix(3)
are all stored as M_Real
values. Note, however, that
fixed-size types such as M_Vector2,
M_Vector3, M_Vector4, and
M_Matrix44 may or may not use a different precision
(depending on the availability of SIMD instructions such as AltiVec and
SSE). The general M_Vector and
M_Matrix types are always guaranteed to use
M_Real
.
M_Real
M_ReadReal
(AG_DataSource
*ds);
void
M_CopyReal
(AG_DataSource
*ds, M_Real
*r);
void
M_WriteReal
(AG_DataSource
*ds, M_Real r);
The
M_ReadReal
()
function reads a complex number from an
AG_DataSource(3)
and returns it. The M_CopyReal
() variant returns the
number in r. M_WriteReal
()
writes a real number to a data source.
M_Real
M_Log
(M_Real
x);
M_Real
M_Exp
(M_Real
x);
M_Real
M_ExpM1
(M_Real
x);
M_Real
M_Sqrt
(M_Real
x);
M_Real
M_Cbrt
(M_Real
x);
M_Real
M_Sin
(M_Real
x);
M_Real
M_Cos
(M_Real
x);
M_Real
M_Tan
(M_Real
x);
M_Real
M_Sinh
(M_Real
x);
M_Real
M_Cosh
(M_Real
x);
M_Real
M_Tanh
(M_Real
x);
M_Real
M_Cot
(M_Real
x);
M_Real
M_Sec
(M_Real
x);
M_Real
M_Csc
(M_Real
x);
M_Real
M_Asin
(M_Real
x);
M_Real
M_Acos
(M_Real
x);
M_Real
M_Atan
(M_Real
x);
M_Real
M_Asinh
(M_Real
x);
M_Real
M_Acosh
(M_Real
x);
M_Real
M_Atanh
(M_Real
x);
M_Real
M_Atan2
(M_Real
y, M_Real x);
M_Real
M_Hypot2
(M_Real
x, M_Real y);
M_Real
M_Fabs
(M_Real
x);
M_Real
M_Sgn
(M_Real
x);
M_Real
M_Pow
(M_Real
x, M_Real y);
M_Real
M_Frexp
(M_Real
x, int *exp);
M_Real
M_Ldexp
(M_Real
x, int *exp);
M_Real
M_Ceil
(M_Real
x);
M_Real
M_Floor
(M_Real
x);
int
M_IsNaN
(M_Real
x);
int
M_IsInf
(M_Real
x);
M_Log
()
returns the natural logarithm of x.
M_Exp
()
returns the value of e, raised to the power of x.
The
M_ExpM1
()
routine returns the equivalent of M_Exp(x)-1. Numerical roundoff error is
prevented in the case of x being near zero.
M_Sqrt
()
returns the square root of x.
M_Cbrt
() returns the cube root of
x.
M_Sin
(),
M_Cos
() and M_Tan
() return
the sine, cosine and tangent of x (given in radians).
M_Sinh
(), M_Cosh
(),
M_Tanh
() return the hyperbolic sine, cosine and
tangent of x.
M_Cot
(),
M_Sec
() and M_Csc
() return
the cotangent, secant and cosecant of x.
M_Asin
(),
M_Acos
() and M_Atan
() return
the arc sine, arc cosine and arc tangent of x.
M_Asinh
(), M_Acosh
() and
M_Atanh
() return the hyperbolic arc sine, arc cosine
and arc tangent of x.
M_Atan2
()
returns the equivalent of Atan(y/x), except that the sign of the result is
determined from the signs of both arguments.
M_Hypot2
()
computes the length of the hypotenuse of a right-angle triangle with the
right-angle side lengths of x and
y.
M_Fabs
()
returns the absolute value of x.
The sign function
M_Sgn
()
returns +1.0 if the sign of x is positive or -1.0 if
the sign is negative.
M_Pow
()
returns x raised to the power of
y.
M_Frexp
()
returns the normalized fraction for x, and writes the
exponent to exp.
M_Ldexp
()
returns the result of multiplication of x by 2 to the
power exp.
M_Ceil
()
rounds x up to the nearest integer.
M_Floor
() rounds down to the nearest integer.
M_IsNan
()
evaluates to 1 if x is "not a number".
M_IsInf
()
evaluates to 1 if x represents infinity.
The M_Real
structure first appeared in
Agar 1.3.4.