numpy  2.0.0
src/npymath/npy_math.c.src File Reference
#include "npy_math_private.h"

Defines

#define NPY_DBL_EPSILON   1.2246467991473531772E-16
#define LOGE2   NPY_LOGE2@c@
#define LOG2E   NPY_LOG2E@c@
#define RAD2DEG   (180.0@c@/NPY_PI@c@)
#define DEG2RAD   (NPY_PI@c@/180.0@c@)

Functions

double npy_expm1 (double x)
double npy_log1p (double x)
double npy_atan2 (double y, double x)
double npy_hypot (double x, double y)
double npy_acosh (double x)
double npy_asinh (double xx)
double npy_atanh (double x)
double npy_rint (double x)
double npy_trunc (double x)
double npy_exp2 (double x)
double npy_log2 (double x)
type npy_ kind c (@type @x)
type npy_ kind c (@type @x,@type @y)
type npy_modf c (@type @x,@type @*iptr)
type npy_ldexp c (@type @x, int exp)
type npy_frexp c (@type @x, int *exp)
type npy_divmod c (@type @a,@type @b,@type @*modulus)

Define Documentation

#define DEG2RAD   (NPY_PI@c@/180.0@c@)
#define LOG2E   NPY_LOG2E@c@
#define LOGE2   NPY_LOGE2@c@
end repeat*
Non standard functions
begin repeat
#type = npy_float, npy_double, npy_longdouble# c = f, ,l# C = F, ,L#
#define NPY_DBL_EPSILON   1.2246467991473531772E-16
Taken from FreeBSD mlib, adapted for numpy
XXX: we could be a bit faster by reusing high/low words for inf/nan classification instead of calling npy_isinf/npy_isnan: we should have some macros for this, though, instead of doing it manually
XXX: we should have this in npy_math.h
#define RAD2DEG   (180.0@c@/NPY_PI@c@)

Referenced by c().


Function Documentation

type npy_exp2_m1 c ( @type @  x)
if C99 extensions not available then define dummy functions that use the double versions for
sin, cos, tan sinh, cosh, tanh, fabs, floor, ceil, rint, trunc sqrt, log10, log, exp, expm1 asin, acos, atan, asinh, acosh, atanh
hypot, atan2, pow, fmod, modf ldexp, frexp
We assume the above are always available in their double versions.
NOTE: some facilities may be available as macro only instead of functions. For simplicity, we define our own functions and undef the macros. We could instead test for the macro, but I am lazy to do that for now.
begin repeat
#type = npy_longdouble, npy_float# TYPE = NPY_LONGDOUBLE, FLOAT# c = l,f# C = L,F#
begin repeat1
kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10,
log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2,log2#
#KIND = SIN,COS,TAN,SINH,COSH,TANH,FABS,FLOOR,CEIL,RINT,TRUNC,SQRT,LOG10,
LOG,EXP,EXPM1,ASIN,ACOS,ATAN,ASINH,ACOSH,ATANH,LOG1P,EXP2,LOG2#
end repeat*
Decorate all the math functions which are available on the current platform
begin repeat
#type = npy_longdouble, npy_double, npy_float# c = l,,f# C = L,,F#
begin repeat1
kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10,
log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2,log2#
#KIND = SIN,COS,TAN,SINH,COSH,TANH,FABS,FLOOR,CEIL,RINT,TRUNC,SQRT,LOG10,
LOG,EXP,EXPM1,ASIN,ACOS,ATAN,ASINH,ACOSH,ATANH,LOG1P,EXP2,LOG2#
end repeat1*
begin repeat1
kind = atan2,hypot,pow,fmod,copysign# #KIND = ATAN2,HYPOT,POW,FMOD,COPYSIGN#
end repeat1*
C99 but not mandatory
don't set invalid flag
type npy_logaddexp2 c ( @type @  x,
@type @  y 
)
end repeat1*
begin repeat1
kind = atan2,hypot,pow,fmod,copysign# #KIND = ATAN2,HYPOT,POW,FMOD,COPYSIGN#
Handles infinities of the same sign without warnings
NaNs
Handles infinities of the same sign without warnings
NaNs

References NPY_NAN.

type npy_modf c ( @type @  x,
@type @*  iptr 
)
end repeat1*
type npy_ldexp c ( @type @  x,
int  exp 
)
type npy_frexp c ( @type @  x,
int *  exp 
)

References RAD2DEG.

type npy_divmod c ( @type @  a,
@type @  b,
@type @*  modulus 
)
Python version of divmod.
The implementation is mostly copied from cpython 3.5.
If b == 0, return result of fmod. For IEEE is nan
a - mod should be very nearly an integer multiple of b
adjust fmod result to conform to Python convention of remainder
if mod is zero ensure correct sign
snap quotient to nearest integral value
if div is zero ensure correct sign
double npy_acosh ( double  x)

References npy_ceil(), and npy_floor().

double npy_asinh ( double  xx)
double npy_atan2 ( double  y,
double  x 
)
if x or y is nan, return nan

<

atan(+-0,+anything)=+-0

<

atan(+0,-anything) = pi

<

atan(-0,-anything) =-pi

<

atan(+INF,+INF)

<

atan(-INF,+INF)

<

atan(+INF,-INF)

<

atan(-INF,-INF)

<

atan(+...,+INF)

<

atan(-...,+INF)

<

atan(+...,-INF)

<

atan(-...,-INF)
compute y/x

<

|y/x| > 2**60

Docutils System Messages

System Message: ERROR/3 (<string>, line 1); backlink Undefined substitution referenced: "y/x".

<

0 > |y|/x > -2**-60

Docutils System Messages

System Message: ERROR/3 (<string>, line 1); backlink Undefined substitution referenced: "y".

<

safe to do y/x

<

atan(+,+)

<

atan(-,+)

<

atan(+,-)

<

case 3

<

atan(-,-)
double npy_atanh ( double  x)
double npy_exp2 ( double  x)

References kind().

double npy_expm1 ( double  x)

* BASIC MATH FUNCTIONS **

Original code by Konrad Hinsen.
double npy_hypot ( double  x,
double  y 
)

References npy_floor().

Referenced by HALF_sign().

double npy_log1p ( double  x)
double npy_log2 ( double  x)
does not provide int(log(2**i)) == i
double npy_rint ( double  x)
Round to nearest even
double npy_trunc ( double  x)

References kind().