Previous: Floating-Point Comparison Functions, Up: Arithmetic Functions [Contents][Index]
The functions in this section perform miscellaneous but common operations that are awkward to express with C operators. On some processors these functions can use special machine instructions to perform these operations faster than the equivalent C code.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
The fmin
function returns the lesser of the two values x
and y. It is similar to the expression
((x) < (y) ? (x) : (y))
except that x and y are only evaluated once.
If an argument is a quiet NaN, the other argument is returned. If both arguments are NaN, or either is a signaling NaN, NaN is returned.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
The fmax
function returns the greater of the two values x
and y.
If an argument is a quiet NaN, the other argument is returned. If both arguments are NaN, or either is a signaling NaN, NaN is returned.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
The fminimum
function returns the lesser of the two values x
and y. Unlike fmin
, if either argument is a NaN, NaN is returned.
Positive zero is treated as greater than negative zero.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
The fmaximum
function returns the greater of the two values x
and y. Unlike fmax
, if either argument is a NaN, NaN is returned.
Positive zero is treated as greater than negative zero.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
The fminimum_num
function returns the lesser of the two values
x and y. If one argument is a number and the other is a
NaN, even a signaling NaN, the number is returned. Positive zero is
treated as greater than negative zero.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
The fmaximum_num
function returns the greater of the two values
x and y. If one argument is a number and the other is a
NaN, even a signaling NaN, the number is returned. Positive zero is
treated as greater than negative zero.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
These functions, from TS 18661-1:2014 and TS 18661-3:2015, return
whichever of the two values x and y has the smaller absolute
value. If both have the same absolute value, or either is NaN, they
behave the same as the fmin
functions.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
These functions, from TS 18661-1:2014, return whichever of the two
values x and y has the greater absolute value. If both
have the same absolute value, or either is NaN, they behave the same
as the fmax
functions.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
These functions return whichever of the two values x and y
has the smaller absolute value. If both have the same absolute value,
or either is NaN, they behave the same as the fminimum
functions.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
These functions return whichever of the two values x and y
has the greater absolute value. If both have the same absolute value,
or either is NaN, they behave the same as the fmaximum
functions.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
These functions return whichever of the two values x and y
has the smaller absolute value. If both have the same absolute value,
or either is NaN, they behave the same as the fminimum_num
functions.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
These functions return whichever of the two values x and y
has the greater absolute value. If both have the same absolute value,
or either is NaN, they behave the same as the fmaximum_num
functions.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
The fdim
function returns the positive difference between
x and y. The positive difference is x -
y if x is greater than y, and 0 otherwise.
If x, y, or both are NaN, NaN is returned.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
The fma
function performs floating-point multiply-add. This is
the operation (x · y) + z, but the
intermediate result is not rounded to the destination type. This can
sometimes improve the precision of a calculation.
This function was introduced because some processors have a special
instruction to perform multiply-add. The C compiler cannot use it
directly, because the expression ‘x*y + z’ is defined to round the
intermediate result. fma
lets you choose when you want to round
only once.
On processors which do not implement multiply-add in hardware,
fma
can be very slow since it must avoid intermediate rounding.
math.h defines the symbols FP_FAST_FMA
,
FP_FAST_FMAF
, and FP_FAST_FMAL
when the corresponding
version of fma
is no slower than the expression ‘x*y + z’.
In the GNU C Library, this always means the operation is implemented in
hardware.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
These functions, from TS 18661-1:2014 and TS 18661-3:2015, return x + y, rounded once to the return type of the function without any intermediate rounding to the type of the arguments.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
These functions, from TS 18661-1:2014 and TS 18661-3:2015, return x - y, rounded once to the return type of the function without any intermediate rounding to the type of the arguments.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
These functions, from TS 18661-1:2014 and TS 18661-3:2015, return x * y, rounded once to the return type of the function without any intermediate rounding to the type of the arguments.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
These functions, from TS 18661-1:2014 and TS 18661-3:2015, return x / y, rounded once to the return type of the function without any intermediate rounding to the type of the arguments.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
These functions, from TS 18661-1:2014 and TS 18661-3:2015, return the square root of x, rounded once to the return type of the function without any intermediate rounding to the type of the arguments.
Preliminary: | MT-Safe | AS-Safe | AC-Safe | See POSIX Safety Concepts.
These functions, from TS 18661-1:2014 and TS 18661-3:2015, return (x · y) + z, rounded once to the return type of the function without any intermediate rounding to the type of the arguments and without any intermediate rounding of result of the multiplication.
Previous: Floating-Point Comparison Functions, Up: Arithmetic Functions [Contents][Index]