# fp64lib Library reference

### float64_t fp64_abs(float64_t x);

Return absolute value of x, removing sign. This works even if is NaN, Inf or zero.

### float64_t fp64_acos(float64_t x );

Returns the arcus cosine of x, the inverse function to fp64_cos(). The following special cases apply:

`acos(NaN) = NaNacos(x) = NaN for any x > +1, including +Infacos(x) = NaN for any x < -1, including -Inf`

### float64_t fp64_add( float64_t A, float64_t B );

Adds two 64 bit floating point numbers and rounds result to a 64bit floating point number. The following special cases apply:

### float64_t fp64_asin(float64_4 x );

Returns the arcus sine of x, the inverse function to fp64_sin(). The following special cases apply:

`asin(NaN) = NaNasin(x) = NaN for any x > +1, including +Infasin(x) = NaN for any x < -1, including -Inf`

### float64_t fp64_atan( float64_t x);

Returns the arcus tangent of x, the inverse function to fp64_tan(). The following special cases apply:

`atan(NaN) = NaNatan(+Inf) = +PI/2atan(-Inf) = -PI/2`

### float64_t fp64_atan2 (float64_t A, float64_t B);

The fp64_atan2() function calculates the arc tangent of the two variables A and B, where A can be interpreted as the y coordinate and B as the x coordinate. It is similar to calculating the arc tangent of A/B, except that the signs of both arguments are used to determine the quadrant of the result. The fp64_atan2() function returns the result in radians, which is between -PI and PI (inclusive):

`Sector|   x  |   y  | |y|<=|x| | result range------+------+------+----------+-----------------I     | >= 0 | >= 0 |    yes   | 0..PI/4II    | >= 0 | >= 0 |     no   | PI/4..PI/2III   | < 0  | >= 0 |     no   | PI/2..3*PI/4IV    | < 0  | >= 0 |    yes   | 3*PI/4..PIV     | < 0  | < 0  |    yes   | -PI..-3*PI/4VI    | < 0  | < 0  |     no   | -3*PI/4..-PI/2VII   | >= 0 | < 0  |     no   | -PI/2..-PI/4VIII  | >= 0 | < 0  |     yes  | -PI/4..0Note:Unlike the 32bit floating library, this implementation respects all fourcases of 0/0, like x86 (GCC/Glibc): +0/+0, +0/-0, -0/+0 and -0/-0.`

The following special cases apply:

### float64_t fp64_atof( char *str);

converts a string to a number, handles also NaN, +INF, -INF.
A valid number (non NaN or INF) can be expressed by the
following regex: [+-]?[0-9]+\.?[0-9]*([eE][+-]?[0-9]+)?

### float64_t fp64_cbrt(float64_t x);

The fp64_cbrt() returns the cubic root of x. Works for positive and
negative values of x.

### float64_t fp64_ceil( float64_t A );

Rounds A upwards to the nearest integer greater or equal A.
For A < 0 this is identical to trunc(A). The following rules apply:

### int fp64_classify( float64_t x );

Categorizes floating point value x into the following categories:
zero, subnormal, normal, infinite, and NAN.
The following cases apply:

### float64_t fp64_compare (float64_t A, float64_t B);

Compares the two values A and B and returns -1/0/1, based on the following rules:

### float64_t fp64_copysign (float64_t x, float64_t y);

The fp64_copysign() function returns x but with the sign of y. This works even if x or y are NaN, Inf or zero.

### float64_t fp64_cos( float64_t phi );

Returns the cosine of phi. The following special cases apply:

`cos(NaN) = NaNcos(+Inf) = NaNcos(-Inf) = NaN`

### float64_t fp64_cosh( float64_t x );

The fp64_cosh() function returns the hyperbolic cosine of x, which is
defined mathematically as (exp(x) + exp(-x)) / 2.

### float64_t fp64_cotan( float64_t x );

The fp64_cotan() function returns the cotangent of x, which is
defined mathematically as cos(x) / sin(x) or 1/tan(x).

### float64_t fp64_cut_noninteger_fraction( float64_t x );

Alias to fp64_trunc, see there.

### float64_t fp64_div( float64_t A, float64_t B );

Divides two 64 bit floating point numbers and rounds result of A/B to a 64bit floating point number. The following special cases apply:

### float fp64_ds( float64_t A );

Converts a float64 to the float32 representing the same number. Significand is rounded up, if bit 25 of significand of A is set.
As the range of float is significandly smaller than float64_t,
the following rules apply:

### float64_t fp64_exp (float64_t x);

The fp64_exp() function returns the value of e (the base of natural
logarithms) raised to the power of x (e^x). The following rules apply:

### float64_t fp64_exp10 (float64_t x);

The fp64_exp10() function returns the value of 10 raised to the power of x, i.e. 10^x.

### float_64t fp64_fdim (float_64t A, float_64t B);

The fp64_fdim() function returns max(A-B,0). If x or y or both are NaN, NaN is returned.

### long fp64_float64_to_long( float64_t A );

Alias to fp64_to_int32, see there.

### float64_t fp64_floor( float64_t A );

Rounds A downwards to the nearest integer less or equal A. For A > 0 this is identical to trunc(A).

`Examples:fp64_floor(1.9) --> 1.0fp64_floor(-1.9) --> -2.0`

The following rules apply:

### float64_t fp64_fma (float64_t A, float64_t B, float64_t C);

The `fp64_fma’ function performs floating-point multiply-add. This is the operation (A * B) + C. Current implementation is space optimized, so no effort is taken to work on internal intermediate result. Only advantage for the caller is to save space for the call sequence.

### float64_t fp64_fmax (float64_t A, float64_t B);

The fp64_fmax() function returns the greater of the two values A and B.
The following rules apply:

### float64_t fp64_fmin(float64_t A, float64_t B);

The fp64_fmin() function returns the lesser of the two values A and B.
The following rules apply:

### float64_t fp64_fmod (float64_t x, float64_t y);

The fp64_fmod() function computes the remainder of dividing x by y. The
return value is x – n*y, where n is the quotient of x/y, rounded
towards zero to an integer. The following rules apply:

### float64_t fp64_fmodn( float64_t x, float64_t y, unsigned long *np );

Like fp64_fmod, fp64_fmodn() function computes the remainder of dividing x by y. The return value is x – n*y, where n is the quotient of x/y, rounded towards zero to an integer. If pointer a pointer np != NULL is passed, the value of n will be stored in *np. See fp64_fmod for further rules.

Available with release 1.08 onwards.

### float64_t fp64_fmodx_pi2( float64_t x, unsigned long *np );

Computes the remainder of dividing x by Π/2 with extended 96-bit internal precision to avoid loss of significand digits for x >> Π. The return value is Π/2 – n*y, where n is the quotient of x/(Π/2), rounded towards zero to an integer. If pointer a pointer np != NULL is passed, the value of n will be stored in *np. See fp64_fmod for further rules.

Available with release 1.08 onwards.

### float64_t fp64_frexp (float64_t A, int *pexp);

The fp64_frexp() function is used to split the number A into a normalized
fraction and an exponent which is stored by pexp.

Return:
If A is a normal float point number, the fp64_frexp() function returns the
value v, such that v has a magnitude in the interval [1/2, 1) or zero,
and A equals v times 2 raised to the power *pexp. If A is zero, both
parts of the result are zero. If A is not a finite number, the fp64_frexp()
returns A as is and stores 0 by pexp.

Note:
This implementation permits a zero pointer as a directive to skip
a storing the exponent.

### float64_t fp64_hypot(float64_t x, float64_t y);

The float64_t() function returns `sqrt (x*x + y*y)’. This is the length
of the hypotenuse of a right triangle with sides of length x and y,
or the distance of the point (x, y) from the origin.

### float64_t fp64_int32_to_float64 ( long x );

Convert a signed 32-bit integer (long) to float64_t.
No overflow will occur, as 32bit long will always fit into the 53-bit significand.

### float64_t int64_to_float64( long long x );

Convert a signed 64-bit integer (long long) to float64_t.
Overflow cannot occur, but loss of precision, if abs(x) > 2^53

### float64_t inverse (float64_t A);

The inverse() function returns 1/A value.

### int fp64_isfinite (float64_t x);

The isfinite() function returns a nonzero value if x is finite: not
plus or minus infinity, and not NaN.

### int fp64_isinf (float64_t);

The fp64_isinf () function returns -1 if value represents negative
infinity, 1 if value represents positive infinity, and 0 otherwise.

### int fp64_isnan( float64_t x );

The fp64_isnan() function returns a non-zero value if value is
“not-a-number” (NaN), and 0 otherwise.

### float64_t fp64_ldexp (float64_t x, int exp);

The fp64_ldexp() function returns the result of multiplying the
floating-point number x by 2 raised to the power exp.
The following rules apply:

### float64_t fp64_log( float64_t x );

returns the natural logarithm ln of x. The following rules apply:

### float64_t fp64_log10( float64_t A );

The fp64_log10() function returns the base 10 logarithm of A.
log10(A) = log(A) / log(10).

### float64_t fp64_log2( float64_t A );

The fp64_log2() function returns the base 2 logarithm of A.
log2(A) = log(A) / log(2).

### float64_t fp64_long_to_float64( float64_t A );

Alias to fp64_int32_to_float64, see there.

### long fp64_lrint (float64_t A);

The fp64_lrint() function rounds A to the nearest integer, rounding the
halfway cases to the even integer direction. (That is both 1.5 and
2.5 values are rounded to 2). This function is similar to rint()
function, but it differs in type of return value and in that an
overflow is possible.
Return:
The rounded long integer value. If A is infinite, NaN or an overflow
was, this realization returns the LONG_MIN value (0x80000000).

`Examples:fp64_lrint(1.25) --> 1Lfp64_lrint(1.5)  --> 2Lfp64_lrint(2.5)  --> 2Lfp64_lrint(2.75) --> 3Lfp64_lrint(3.5)  --> 4Lfp64_lrint(-1.25) --> -1Lfp64_lrint(-1.5)  --> -2Lfp64_lrint(-2.5)  --> -2Lfp64_lrint(-2.75) --> -3Lfp64_lrint(-3.5)  --> -4L`

The following rules apply:

 case A fp64_lrint(A) 1 NaN LONG_MIN (0x80000000) 2 +/- Inf LONG_MIN (0x80000000) 3 +/- 0 0L 4 |A|>=2^31 LONG_MIN (0x80000000) 5 0 < |A|<= 0.5 0L 6 0.5 < |A|< 1.0 +/- 1L 7 1.0 <=|A|< 2^31 trunc(x) if (|x|-trunc(|x|)) < 0.5trunc(x+sign(x)) if (|x|-trunc(|x|)) >= 0.5

### long fp64_lround (float64_t x);

The fp64_lround() function rounds x to the nearest integer, but rounds
halfway cases away from zero (instead of to the nearest even integer).
This function is similar to round() function, but it differs in
type of return value and in that an overflow is possible.
Return:
The rounded long integer value. If x is infinite, NaN or an overflow
was, this realization returns the LONG_MIN value (0x80000000).

`Examples:fp64_lround(1.1) --> 1Lfp64_lround(1.5) --> 2Lfp64_lround(-1.1) --> -1Lfp64_lround(-1.5) --> -2L`

The following rules apply:

 case x fp64_lround(A) 1 NaN LONG_MIN (0x80000000) 2 +/- Inf LONG_MIN (0x80000000) 3 +/- 0 0L 4 |x|>=2^31 LONG_MIN (0x80000000) 5 0 < |x| < 0.5 0L 6 0.5 <= |x| < 1.0 +/- 1L 7 1.0 <= |x| < 2^31 trunc(x) if (|x|-trunc(|x|)) < 0.5trunc(x+sign(x)) if (|x|-trunc(|x|)) >= 0.5

### float64_t fp64_modf (float64_t x, float64_t *iptr);

The fp64_modf() function breaks the argument x into an integral part and a fractional part, each of which has the same sign as x. The integral part
is stored in iptr. This implementation skips writing by zero pointer.

`Examples:modf(123.45) makes 0.45 (return value) + 123.0 (stored in *iptr)`

The following rules apply:

### fp64 fp64_mul( fp64 A, fp64 B );

Multiplies two 64 bit floating point numbers and rounds result to a 64bit floating point number.

`Examples:modf(123.45) makes 0.45 (return value) + 123.0 (stored in *iptr)`

The following rules apply:

### float64_t fp64_neg (float64_t A);

Returns -A. Also works for special cases (NaN, +Inf, -Inf), subnormal numbers and +0 and -0.

### float64_t fp64_pow(float64_t x, float64_t y);

The fp64_pow() function returns the value of x raised to the power of y. The following rules apply:

### float64_t fp64_pow10 (float64_t x);

The fp64_exp10() function returns the value of 10 raised to the power of x, i.e. 10^x. It is an alias to fp64_exp10(x).

### float64_t fp64_round( float64_t x );

Rounds x upwards to the nearest integer, but rounds halfway cases away from 0.

`Examples: fp64_round(1.1) --> 1.0fp64_round(1.5) --> 2.0fp64_round(-1.1) --> -1.0fp64_round(-1.5) --> -2.0`

The following rules apply:

### float64_t fp64_sd (float A);

Converts a float32 to the float64 representing the same number. As float64_t fully includes all values of float, no error or truncation occurs.

### int fp64_signbit (float64_t x);

The fp64_signbit() function returns a nonzero value if the value of x has
its sign bit set. This is not the same as `x < 0.0′, because IEEE 754
floating point allows zero to be signed. The comparison `-0.0 < 0.0′
is false, but `fp64_signbit (-0.0)’ will return a nonzero value.

This implementation returns 1 if sign bit is set. This corresponds
to builtin GCC realization for float.

### float64_t fp64_sin( float64_t phi );

Returns the sine of phi. The following special cases apply:

`sin(NaN) = NaNsin(+Inf) = NaNsin(-Inf) = NaN`

### float64_t fp64_sinh( float64_t x);

The fp64_sinh() function returns the hyperbolic sine of x, which is
defined mathematically as (exp(x) – exp(-x)) / 2.

### float64_t fp64_sqrt (float64_t);

Square root function. The following special cases apply:

`sqrt(NaN) = NaNsqrt(+Inf) = +Infsqrt(-Inf) = NaNsqrt(+-0) = +-0`

Be especially aware of the last special case: fp64_sqrt(-0) = -0. This is fully compliant to IEEE 754 standard, see Wikipedia, but might cause trouble in your code if you are relying on the result always beeing positive.

### float64_t fp64_square (float64_t A);

The fp64_square() function returns square of A.

### float64_t fp64_strtod( char *str, char **endptr );

converts a string to a number, handles also NaN, +INF, -INF
a valid number (non NaN or INF) can be expressed by the
following regex: [+-]?[0-9]+\.?[0-9]*([eE][+-]?[0-9]+)?

Returns the identified number as result, and *endptr contains pointer to last parsed position in string str.

### float64_t fp64_sub( float64_t A, float64_t B );

Subtracts two 64 bit floating point numbers and rounds result to a 64bit floating point number. The following special cases apply:

### float64_t fp64_tan( float64_4 phi );

Returns the tangent of phi. The following special cases apply:

`tan(NaN) = NaNtan(+Inf) = NaNtan(-Inf) = NaN`

### float64_t fp64_tanh (float64_t x);

The fp64_tanh() function returns the hyperbolic tangent of x, which is
defined mathematically as sinh(x) / cosh(x).

### char *fp64_to_decimalExp( float64_t x, uint8_t maxDigits, uint8_t expSep, int16_t *exp10 )

converts a number to a string with maxDigits of significand.

parameters:
x                    number x to convert in float64_t format
maxDigits  maximum number of digits in significand
expSep         flag to store significand and exponent seperately
exp10            if != NULL, store exponent base 10 here

NOTE: this function supports conversion of up to 17 digits. However, accuracy of IEEE754 is only 52 bit which is 15-16 decimal digits!

WARNING: function returns a pointer to a static temporary scratch area which might be used also for other functions. The returned string might become invalid/scrambled if one of the other fp64_ functions will be called. So copy the result to some other allocated memory that you have under control before calling further fp64lib-routines.

### int fp64_to_int16( float64_t A );

The fp64_to_int16() function converts A to the signed integer value,
rounding towards 0, the fractional part is lost. No saturation.
Only when called in assembly language: Besides a normal 16-bits value, the carry is returned as extra error flag.

The following rules apply:

### long fp64_to_int32( float64_t A );

The fp64_to_int32() function converts A to the signed integer value,
rounding towards 0, the fractional part is lost. No saturation.
Only when called in assembly language: Besides a normal 32-bits value, the carry is returned as extra error flag.

The following rules apply:

### long long fp64_to_int64( float64_t A );

The fp64_to_int64() function converts A to the signed integer value,
rounding towards 0, the fractional part is lost. No saturation.
Only when called in assembly language: Besides a normal 64-bits value, the carry is returned as extra error flag.

The following rules apply:

### char fp64_to_int8( float64_t A );

The fp64_to_int8() function converts A to the signed integer value,
rounding towards 0, the fractional part is lost. No saturation.
Only when called in assembly language: Besides a normal 8-bits value, the carry is returned as extra error flag.

The following rules apply:

### char *fp64_to_string(float64_t x, uint8_t max_chars, uint8_t max_zeroes);

converts the float64 to the decimal representation of the number x. fp64_to_string adjusts the number of decimal digits so that the result
will fit into a string with max_chars characters. However, a longer string
will be returned if the minimum representation will not fit into max_chars.
Minimum representation is “mESn[nn]” for X > 0 else “-mESn[nn]”, so at least 4 to 7 characters are needed.

parameters:
x:                        number to convert in float64_t format
max_chars:   maximum space for result
max_zeroes: use “s0.mmmmmm” when result has less than this # of 0s

WARNING: function returns a pointer to a static temporary scratch area which might be used also for other functions. The returned string might become invalid/scrambled if one of the other fp64_ functions will be called. So copy the result to some other allocated memory that you have under control before calling further fp64__ routines.

The following rules apply:

 case x fp64_to_string(x) 1 NaN “NaN” 2 +Inf “+INF” 3 -Inf “-INF” 4 |x|<1 “s0.mmmmmm” representation without exponent if x can be displayed with less than max_zeroes “0” after “0.”leading sign s only for x < 0else exponential form is used “sm.mmmmmESnnn” 5 log10(|x|)

NOTE: this function supports conversion of up to 17 digits. However, accuracy of IEEE754 is only 52 bit which is 15-16 decimal digits! Therefore, in no case more than 17 digits of precision are generated.

### unsigned int fp64_to_uint16( float64_t A );

The fp64_to_uint16() function converts A to the unsigned integer value,
rounding towards 0, the fractional part is lost. No saturation.
Negative input is permissable (like GCC/x86).
Only when called in assembly language: Besides a normal 16-bits value, the carry is returned as extra error flag.

The following rules apply:

### unsigned long fp64_to_uint32( float64_t A );

The fp64_to_uint32() function converts A to the unsigned integer value,
rounding towards 0, the fractional part is lost. No saturation.
Negative input is permissable (like GCC/x86).
Only when called in assembly language: Besides a normal 32-bits value, the carry is returned as extra error flag.

The following rules apply:

### unsigned long long fp64_to_uint64( float64_t A );

The fp64_to_uint64() function converts A to the unsigned integer value,
rounding towards 0, the fractional part is lost. No saturation.
Negative input is permissable (like GCC/x86).
Only when called in assembly language: Besides a normal 64-bits value, the carry is returned as extra error flag.

The following rules apply:

### unsigned char fp64_to_uint8( float64_t A );

The fp64_to_uint8() function converts A to the unsigned integer value,
rounding towards 0, the fractional part is lost. No saturation.
Negative input is permissable (like GCC/x86).
Only when called in assembly language: Besides a normal 64-bits value, the carry is returned as extra error flag.

The following rules apply:

### float64_t fp64_trunc( float64_t A );

Rounds A to the nearest integer not larger in absolute value,
by cutting the noninteger part ( = setting the fractional part to 0).
This is effectively the same as rounding A towards 0.

`Examples: fp64_trunc(1.9) --> 1.0fp64_trunc(-1.9) --> -1.0`

The following rules apply:

### float64_t fp64_uint16_to_float64( uint16_t x );

Convert an unsigned 16-bit integer to float64_t. Overflow cannot occur.

Available with release 1.08 onwards.

### float64_t fp64_uint64_to_float64( unsigned long long x );

Convert an unsigned 64-bit integer (unsigned long long) to float64_t.
Overflow cannot occur, but loss of precision, if abs(x) > 2^53