Mathematical Operations¶
In the following, the data types T
refer to arithmetic data types on which the operation is defined mathematically.
This includes the active XAD types as well as the standard passive types.
The functions listed here are defined in the xad
namespace,
and C++ ADL rules (argument-dependent lookup) typically find these functions
automatically if they are applied to XAD types.
However, for this the calls must be unqualified, i.e. without a namespace specifier.
Alternatively, fully qualified names work as usual (e.g. xad::sin(x)
),
also for float
and double
.
For convenience, if the header XAD/StdCompatibility.hpp
is included,
the XAD variables are imported into the std
namespace,
so that existing calls to std::sin
and similar functions are working as expected.
Absolute Values, Max, Min, and Rounding¶
- T abs(T x)¶
Computes the absolute value of
x
.Note that for defined second-order derivatives, this computes
(x>0)-(x<0)
- T max(T x, T y)¶
Returns the maximum of
x
andy
.Note that for well-defined second order derivative, this is implemented as
(x + y + abs(x-y)) / 2
- T min(T x, T y)¶
Returns the minimum of
x
andy
.Note that for well-defined second order derivative, this is implemented as
(x + y - abs(x-y)) / 2
- T fmod(T x, T y)¶
The floating-point remainder of the division operation
x/y
, i.e. exactly the valuex - n*y
, wheren
isx/y
with its fractional part truncated.
- T remainder(T x, T y)¶
The IEEE floating-point remainder of the division operation
x/y
, i.e. exactly the valuex - n*y
, where the valuen
is the integral value nearest the exact valuex/y
. Whenabs(n-x/y) = 0.5
, the value n is chosen to be even.In contrast to
fmod()
, the returned value is not guaranteed to have the same sign asx
.
- T modf(T x, T *iptr)¶
Decomposes
x
into integral and fractional parts, each with the same type and sign asx
. The integral part is stored iniptr
.
- T nextafter(T from, T to)¶
Returns the next representable value of
from
in the direction ofto
.Mathmatically, the difference of
from
to the return value is very small. For derivatives, we therefore consider them both the same and calculate derivative accordingly.
Trigonometric Functions¶
Powers, Exponentials, and Logarithms¶
- T frexp(T arg, int *exp)¶
Decomposes the given floating point value arg into a normalised fraction and an integral power of two.
- int ilogb(T arg)¶
Returns the integral part of the logarithm of
abs(x)
, usingFLT_RADIX
as base for the log.
Error Functions¶
- T erfc(T x)¶
Computes the complementary error function of
x
, if provided by the compiler’s math library.
Floating Point Classification¶
- bool signbit(T x)¶
Returns true if
x
is negative and false otherwise. Also detects sign bit of zeros.
- bool isnormal(T x)¶
Checks if the value is a normal floating point number, i.e. not zero, subnormal, infinite, or NaN.