| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This chapter contains information about functions for doing basic arithmetic operations, such as splitting a float into its integer and fractional parts or retrieving the imaginary part of a complex value. These functions are declared in the header files `math.h' and `complex.h'.
| 20.1 Integers | Basic integer types and concepts | |
| 20.2 Integer Division | Integer division with guaranteed rounding. | |
| 20.3 Floating Point Numbers | Basic concepts. IEEE 754. | |
| 20.4 Floating-Point Number Classification Functions | The five kinds of floating-point number. | |
| 20.5 Errors in Floating-Point Calculations | When something goes wrong in a calculation. | |
| 20.6 Rounding Modes | Controlling how results are rounded. | |
| 20.7 Floating-Point Control Functions | Saving and restoring the FPU's state. | |
| 20.8 Arithmetic Functions | Fundamental operations provided by the library. | |
| 20.9 Complex Numbers | The types. Writing complex constants. | |
| 20.10 Projections, Conjugates, and Decomposing of Complex Numbers | Projection, conjugation, decomposition. | |
| 20.11 Parsing of Numbers | Converting strings to numbers. | |
| 20.12 Old-fashioned System V number-to-string functions | An archaic way to convert numbers to strings. |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The C language defines several integer data types: integer, short integer, long integer, and character, all in both signed and unsigned varieties. The GNU C compiler extends the language to contain long long integers as well.
The C integer types were intended to allow code to be portable among machines with different inherent data sizes (word sizes), so each type may have different ranges on different machines. The problem with this is that a program often needs to be written for a particular range of integers, and sometimes must be written for a particular size of storage, regardless of what machine the program runs on.
To address this problem, the GNU C library contains C type definitions you can use to declare integers that meet your exact needs. Because the GNU C library header files are customized to a specific machine, your program source code doesn't have to be.
These typedefs are in `stdint.h'.
If you require that an integer be represented in exactly N bits, use one of the following types, with the obvious mapping to bit size and signedness:
If your C compiler and target machine do not allow integers of a certain size, the corresponding above type does not exist.
If you don't need a specific storage size, but want the smallest data structure with at least N bits, use one of these:
If you don't need a specific storage size, but want the data structure that allows the fastest access while having at least N bits (and among data structures with the same access speed, the smallest one), use one of these:
If you want an integer with the widest range possible on the platform on which it is being used, use one of the following. If you use these, you should write code that takes into account the variable size and range of the integer.
The GNU C library also provides macros that tell you the maximum and
minimum possible values for each integer data type. The macro names
follow these examples: INT32_MAX, UINT8_MAX,
INT_FAST32_MIN, INT_LEAST64_MIN, UINTMAX_MAX,
INTMAX_MAX, INTMAX_MIN. Note that there are no macros for
unsigned integer minima. These are always zero.
There are similar macros for use with C's built in integer types which should come with your C compiler. These are described in A.5 Data Type Measurements.
Don't forget you can use the C sizeof function with any of these
data types to get the number of bytes of storage each uses.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section describes functions for performing integer division. These
functions are redundant when GNU CC is used, because in GNU C the
`/' operator always rounds towards zero. But in other C
implementations, `/' may round differently with negative arguments.
div and ldiv are useful because they specify how to round
the quotient: towards zero. The remainder has the same sign as the
numerator.
These functions are specified to return a result r such that the value
r.quot*denominator + r.rem equals
numerator.
To use these facilities, you should include the header file `stdlib.h' in your program.
div
function. It has the following members:
int quot
int rem
div computes the quotient and remainder from
the division of numerator by denominator, returning the
result in a structure of type div_t.
If the result cannot be represented (as in a division by zero), the behavior is undefined.
Here is an example, albeit not a very useful one.
div_t result; result = div (20, -6); |
Now result.quot is -3 and result.rem is 2.
ldiv
function. It has the following members:
long int quot
long int rem
(This is identical to div_t except that the components are of
type long int rather than int.)
ldiv function is similar to div, except that the
arguments are of type long int and the result is returned as a
structure of type ldiv_t.
lldiv
function. It has the following members:
long long int quot
long long int rem
(This is identical to div_t except that the components are of
type long long int rather than int.)
lldiv function is like the div function, but the
arguments are of type long long int and the result is returned as
a structure of type lldiv_t.
The lldiv function was added in ISO C99.
imaxdiv
function. It has the following members:
intmax_t quot
intmax_t rem
(This is identical to div_t except that the components are of
type intmax_t rather than int.)
See 20.1 Integers for a description of the intmax_t type.
imaxdiv function is like the div function, but the
arguments are of type intmax_t and the result is returned as
a structure of type imaxdiv_t.
See 20.1 Integers for a description of the intmax_t type.
The imaxdiv function was added in ISO C99.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Most computer hardware has support for two different kinds of numbers: integers () and floating-point numbers. Floating-point numbers have three parts: the mantissa, the exponent, and the sign bit. The real number represented by a floating-point value is given by where is the sign bit, the exponent, and the mantissa. See section A.5.3.1 Floating Point Representation Concepts, for details. (It is possible to have a different base for the exponent, but all modern hardware uses .)
Floating-point numbers can represent a finite subset of the real numbers. While this subset is large enough for most purposes, it is important to remember that the only reals that can be represented exactly are rational numbers that have a terminating binary expansion shorter than the width of the mantissa. Even simple fractions such as can only be approximated by floating point.
Mathematical operations and functions frequently need to produce values that are not representable. Often these values can be approximated closely enough for practical purposes, but sometimes they can't. Historically there was no way to tell when the results of a calculation were inaccurate. Modern computers implement the IEEE 754 standard for numerical computations, which defines a framework for indicating to the program when the results of calculation are not trustworthy. This framework consists of a set of exceptions that indicate why a result could not be represented, and the special values infinity and not a number (NaN).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
ISO C99 defines macros that let you determine what sort of floating-point number a variable holds.
int. The possible values are:
FP_NAN
FP_INFINITE
FP_ZERO
FP_SUBNORMAL
fpclassify returns this value
for values of x in this alternate format.
FP_NORMAL
fpclassify is most useful if more than one property of a number
must be tested. There are more specific macros which only test one
property at a time. Generally these macros execute faster than
fpclassify, since there is special hardware support for them.
You should therefore use the specific macros whenever possible.
(fpclassify (x) != FP_NAN && fpclassify (x) != FP_INFINITE) |
isfinite is implemented as a macro which accepts any
floating-point type.
(fpclassify (x) == FP_NORMAL) |
(fpclassify (x) == FP_NAN) |
Another set of floating-point classification functions was provided by BSD. The GNU C library also supports these functions; however, we recommend that you use the ISO C99 macros in new code. Those are standard and will be available more widely. Also, since they are macros, you do not have to worry about the type of their argument.
-1 if x represents negative infinity,
1 if x represents positive infinity, and 0 otherwise.
Note: The isnan macro defined by ISO C99 overrides
the BSD function. This is normally not a problem, because the two
routines behave identically. However, if you really need to get the BSD
function for some reason, you can write
(isnan) (x) |
Portability Note: The functions listed in this section are BSD extensions.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| 20.5.1 FP Exceptions | IEEE 754 math exceptions and how to detect them. | |
| 20.5.2 Infinity and NaN | Special values returned by calculations. | |
| 20.5.3 Examining the FPU status word | Checking for exceptions after the fact. | |
| 20.5.4 Error Reporting by Mathematical Functions | How the math functions report errors. |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The IEEE 754 standard defines five exceptions that can occur during a calculation. Each corresponds to a particular sort of error, such as overflow.
When exceptions occur (when exceptions are raised, in the language of the standard), one of two things can happen. By default the exception is simply noted in the floating-point status word, and the program continues as if nothing had happened. The operation produces a default value, which depends on the exception (see the table below). Your program can check the status word to find out which exceptions happened.
Alternatively, you can enable traps for exceptions. In that case,
when an exception is raised, your program will receive the SIGFPE
signal. The default action for this signal is to terminate the
program. See section 24. Signal Handling, for how you can change the effect of
the signal.
In the System V math library, the user-defined function matherr
is called when certain exceptions occur inside math library functions.
However, the Unix98 standard deprecates this interface. We support it
for historical compatibility, but recommend that you do not use it in
new programs.
The exceptions defined in IEEE 754 are:
If the exception does not trap, the result of the operation is NaN.
Whenever the overflow exception is raised, the inexact exception is also raised.
When no trap is installed for the underflow exception, underflow is signaled (via the underflow flag) only when both tininess and loss of accuracy have been detected. If no trap handler is installed the operation continues with an imprecise small value, or zero if the destination precision cannot hold the small exact result.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
IEEE 754 floating point numbers can represent positive or negative infinity, and NaN (not a number). These three values arise from calculations whose result is undefined or cannot be represented accurately. You can also deliberately set a floating-point variable to any of them, which is sometimes useful. Some examples of calculations that produce infinity or NaN:
When a calculation produces any of these values, an exception also occurs; see 20.5.1 FP Exceptions.
The basic operations and math functions all accept infinity and NaN and produce sensible output. Infinities propagate through calculations as one would expect: for example, , , atan . NaN, on the other hand, infects any calculation that involves it. Unless the calculation would produce the same result no matter what real value replaced NaN, the result is NaN.
In comparison operations, positive infinity is larger than all values
except itself and NaN, and negative infinity is smaller than all values
except itself and NaN. NaN is unordered: it is not equal to,
greater than, or less than anything, including itself. x ==
x is false if the value of x is NaN. You can use this to test
whether a value is NaN or not, but the recommended way to test for NaN
is with the isnan function (see section 20.4 Floating-Point Number Classification Functions). In
addition, <, >, <=, and >= will raise an
exception when applied to NaNs.
`math.h' defines macros that allow you to explicitly set a variable to infinity or NaN.
1.0 / 0.0.
-INFINITY represents negative infinity.
You can test whether a floating-point value is infinite by comparing it
to this macro. However, this is not recommended; you should use the
isfinite macro instead. See section 20.4 Floating-Point Number Classification Functions.
This macro was introduced in the ISO C99 standard.
You can steaibc_20.html#SEC410">20.5.2 Infinity and NaN)
FP_ZERO
FP_SUBNORMAL
fpclassify returns this value
for values of x in this alternate format.
FP_NORMAL
fpclassify is most useful if more than one property of a number
must be tested. There are more specific macros which only test one
property at a time. Generally these macros execute faster than
fpclassify, since there is special hardware support for them.
You should therefore use the specific macros whenever possible.
(fpclassify (x) != FP_NAN && fpclassify (x) != FP_INFINITE) |
isfinite is implemented as a macro which accepts any
floating-point type.
(fpclassify (x) == FP_NORMAL) |
(fpclassify (x) == FP_NAN) |
Another set of floating-point classification functions was provided by BSD. The GNU C library also supports these functions; however, we recommend that you use the ISO C99 macros in new code. Those are standard and will be available more widely. Also, since they are macros, you do not have to worry about the type of their argument.
-1 if x represents negative infinity,
1 if x represents positive infinity, and 0 otherwise.
Note: The isnan macro defined by ISO C99 overrides
the BSD function. This is normally not a problem, because the two
routines behave identically. However, if you really need to get the BSD
function for some reason, you can write
(isnan) (x) |
Portability Note: The functions listed in this section are BSD extensions.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| 20.5.1 FP Exceptions | IEEE 754 math exceptions and how to detect them. | |
| 20.5.2 Infinity and NaN | Special values returned by calculations. | |
| 20.5.3 Examining the FPU status word | Checking for exceptions after the fact. | |
| 20.5.4 Error Reporting by Mathematical Functions | How the math functions report errors. |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The IEEE 754 standard defines five exceptions that can occur during a calculation. Each corresponds to a particular sort of error, such as overflow.
When exceptions occur (when exceptions are raised, in the language of the standard), one of two things can happen. By default the exception is simply noted in the floating-point status word, and the program continues as if nothing had happened. The operation produces a default value, which depends on the exception (see the table below). Your program can check the status word to find out which exceptions happened.
Alternatively, you can enable traps for exceptions. In that case,
when an exception is raised, your program will receive the SIGFPE
signal. The default action for this signal is to terminate the
program. See section 24. Signal Handling, for how you can change the effect of
the signal.
In the System V math library, the user-defined function matherr
is called when certain exceptions occur inside math library functions.
However, the Unix98 standard deprecates this interface. We support it
for historical compatibility, but recommend that you do not use it in
new programs.
The exceptions defined in IEEE 754 are:
If the exception does not trap, the result of the operation is NaN.
Whenever the overflow exception is raised, the inexact exception is also raised.
When no trap is installed for the underflow exception, underflow is signaled (via the underflow flag) only when both tininess and loss of accuracy have been detected. If no trap handler is installed the operation continues with an imprecise small value, or zero if the destination precision cannot hold the small exact result.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
IEEE 754 floating point numbers can represent positive or negative infinity, and NaN (not a number). These three values arise from calculations whose result is undefined or cannot be represented accurately. You can also deliberately set a floating-point variable to any of them, which is sometimes useful. Some examples of calculations that produce infinity or NaN:
When a calculation produces any of these values, an exception also occurs; see 20.5.1 FP Exceptions.
The basic operations and math functions all accept infinity and NaN and produce sensible output. Infinities propagate through calculations as one would expect: for example, , , atan . NaN, on the other hand, infects any calculation that involves it. Unless the calculation would produce the same result no matter what real value replaced NaN, the result is NaN.
In comparison operations, positive infinity is larger than all values
except itself and NaN, and negative infinity is smaller than all values
except itself and NaN. NaN is unordered: it is not equal to,
greater than, or less than anything, including itself. x ==
x is false if the value of x is NaN. You can use this to test
whether a value is NaN or not, but the recommended way to test for NaN
is with the isnan function (see section 20.4 Floating-Point Number Classification Functions). In
addition, <, >, <=, and >= will raise an
exception when applied to NaNs.
`math.h' defines macros that allow you to explicitly set a variable to infinity or NaN.
1.0 / 0.0.
-INFINITY represents negative infinity.
You can test whether a floating-point value is infinite by comparing it
to this macro. However, this is not recommended; you should use the
isfinite macro instead. See section 20.4 Floating-Point Number Classification Functions.
This macro was introduced in the ISO C99 standard.
You can steaibc_20.html#SEC410">20.5.2 Infinity and NaN)
FP_ZERO
FP_SUBNORMAL
fpclassify returns this value
for values of x in this alternate format.
FP_NORMAL
fpclassify is most useful if more than one property of a number
must be tested. There are more specific macros which only test one
property at a time. Generally these macros execute faster than
fpclassify, since there is special hardware support for them.
You should therefore use the specific macros whenever possible.
(fpclassify (x) != FP_NAN && fpclassify (x) != FP_INFINITE) |
isfinite is implemented as a macro which accepts any
floating-point type.
(fpclassify (x) == FP_NORMAL) |
(fpclassify (x) == FP_NAN) |
Another set of floating-point classification functions was provided by BSD. The GNU C library also supports these functions; however, we recommend that you use the ISO C99 macros in new code. Those are standard and will be available more widely. Also, since they are macros, you do not have to worry about the type of their argument.
-1 if x represents negative infinity,
1 if x represents positive infinity, and 0 otherwise.
Note: The isnan macro defined by ISO C99 overrides
the BSD function. This is normally not a problem, because the two
routines behave identically. However, if you really need to get the BSD
function for some reason, you can write
(isnan) (x) |
Portability Note: The functions listed in this section are BSD extensions.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| 20.5.1 FP Exceptions | IEEE 754 math exceptions and how to detect them. | |
| 20.5.2 Infinity and NaN | Special values returned by calculations. | |
| 20.5.3 Examining the FPU status word | Checking for exceptions after the fact. | |
| 20.5.4 Error Reporting by Mathematical Functions | How the math functions report errors. |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The IEEE 754 standard defines five exceptions that can occur during a calculation. Each corresponds to a particular sort of error, such as overflow.
When exceptions occur (when exceptions are raised, in the language of the standard), one of two things can happen. By default the exception is simply noted in the floating-point status word, and the program continues as if nothing had happened. The operation produces a default value, which depends on the exception (see the table below). Your program can check the status word to find out which exceptions happened.
Alternatively, you can enable traps for exceptions. In that case,
when an exception is raised, your program will receive the SIGFPE
signal. The default action for this signal is to terminate the
program. See section 24. Signal Handling, for how you can change the effect of
the signal.
In the System V math library, the user-defined function matherr
is called when certain exceptions occur inside math library functions.
However, the Unix98 standard deprecates this interface. We support it
for historical compatibility, but recommend that you do not use it in
new programs.
The exceptions defined in IEEE 754 are:
If the exception does not trap, the result of the operation is NaN.
Whenever the overflow exception is raised, the inexact exception is also raised.
When no trap is installed for the underflow exception, underflow is signaled (via the underflow flag) only when both tininess and loss of accuracy have been detected. If no trap handler is installed the operation continues with an imprecise small value, or zero if the destination precision cannot hold the small exact result.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
IEEE 754 floating point numbers can represent positive or negative infinity, and NaN (not a number). These three values arise from calculations whose result is undefined or cannot be represented accurately. You can also deliberately set a floating-point variable to any of them, which is sometimes useful. Some examples of calculations that produce infinity or NaN:
When a calculation produces any of these values, an exception also occurs; see 20.5.1 FP Exceptions.
The basic operations and math functions all accept infinity and NaN and produce sensible output. Infinities propagate through calculations as one would expect: for example, , , atan . NaN, on the other hand, infects any calculation that involves it. Unless the calculation would produce the same result no matter what real value replaced NaN, the result is NaN.
In comparison operations, positive infinity is larger than all values
except itself and NaN, and negative infinity is smaller than all values
except itself and NaN. NaN is unordered: it is not equal to,
greater than, or less than anything, including itself. x ==
x is false if the value of x is NaN. You can use this to test
whether a value is NaN or not, but the recommended way to test for NaN
is with the isnan function (see section 20.4 Floating-Point Number Classification Functions). In
addition, <, >, <=, and >= will raise an
exception when applied to NaNs.
`math.h' defines macros that allow you to explicitly set a variable to infinity or NaN.
1.0 / 0.0.
-INFINITY represents negative infinity.
You can test whether a floating-point value is infinite by comparing it
to this macro. However, this is not recommended; you should use the
isfinite macro instead. See section 20.4 Floating-Point Number Classification Functions.
This macro was introduced in the ISO C99 standard.
You can steaibc_20.html#SEC410">20.5.2 Infinity and NaN)
FP_ZERO
FP_SUBNORMAL
fpclassify returns this value
for values of x in this alternate format.
FP_NORMAL
fpclassify is most useful if more than one property of a number
must be tested. There are more specific macros which only test one
property at a time. Generally these macros execute faster than
fpclassify, since there is special hardware support for them.
You should therefore use the specific macros whenever possible.
(fpclassify (x) != FP_NAN && fpclassify (x) != FP_INFINITE) |
isfinite is implemented as a macro which accepts any
floating-point type.
(fpclassify (x) == FP_NORMAL) |
(fpclassify (x) == FP_NAN) |
Another set of floating-point classification functions was provided by BSD. The GNU C library also supports these functions; however, we recommend that you use the ISO C99 macros in new code. Those are standard and will be available more widely. Also, since they are macros, you do not have to worry about the type of their argument.
-1 if x represents negative infinity,
1 if x represents positive infinity, and 0 otherwise.
Note: The isnan macro defined by ISO C99 overrides
the BSD function. This is normally not a problem, because the two
routines behave identically. However, if you really need to get the BSD
function for some reason, you can write
(isnan) (x) |
Portability Note: The functions listed in this section are BSD extensions.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| 20.5.1 FP Exceptions | IEEE 754 math exceptions and how to detect them. | |
| 20.5.2 Infinity and NaN | Special values returned by calculations. | |
| 20.5.3 Examining the FPU status word | Checking for exceptions after the fact. | |
| 20.5.4 Error Reporting by Mathematical Functions | How the math functions report errors. |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The IEEE 754 standard defines five exceptions that can occur during a calculation. Each corresponds to a particular sort of error, such as overflow.
When exceptions occur (when exceptions are raised, in the language of the standard), one of two things can happen. By default the exception is simply noted in the floating-point status word, and the program continues as if nothing had happened. The operation produces a default value, which depends on the exception (see the table below). Your program can check the status word to find out which exceptions happened.
Alternatively, you can enable traps for exceptions. In that case,
when an exception is raised, your program will receive the SIGFPE
signal. The default action for this signal is to terminate the
program. See section 24. Signal Handling, for how you can change the effect of
the signal.
In the System V math library, the user-defined function matherr
is called when certain exceptions occur inside math library functions.
However, the Unix98 standard deprecates this interface. We support it
for historical compatibility, but recommend that you do not use it in
new programs.
The exceptions defined in IEEE 754 are:
If the exception does not trap, the result of the operation is NaN.
Whenever the overflow exception is raised, the inexact exception is also raised.
When no trap is installed for the underflow exception, underflow is signaled (via the underflow flag) only when both tininess and loss of accuracy have been detected. If no trap handler is installed the operation continues with an imprecise small value, or zero if the destination precision cannot hold the small exact result.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
IEEE 754 floating point numbers can represent positive or negative infinity, and NaN (not a number). These three values arise from calculations whose result is undefined or cannot be represented accurately. You can also deliberately set a floating-point variable to any of them, which is sometimes useful. Some examples of calculations that produce infinity or NaN:
When a calculation produces any of these values, an exception also occurs; see 20.5.1 FP Exceptions.
The basic operations and math functions all accept infinity and NaN and produce sensible output. Infinities propagate through calculations as one would expect: for example, , , atan . NaN, on the other hand, infects any calculation that involves it. Unless the calculation would produce the same result no matter what real value replaced NaN, the result is NaN.
In comparison operations, positive infinity is larger than all values
except itself and NaN, and negative infinity is smaller than all values
except itself and NaN. NaN is unordered: it is not equal to,
greater than, or less than anything, including itself. x ==
x is false if the value of x is NaN. You can use this to test
whether a value is NaN or not, but the recommended way to test for NaN
is with the isnan function (see section 20.4 Floating-Point Number Classification Functions). In
addition, <, >, <=, and >= will raise an
exception when applied to NaNs.
`math.h' defines macros that allow you to explicitly set a variable to infinity or NaN.
1.0 / 0.0.
-INFINITY represents negative infinity.
You can test whether a floating-point value is infinite by comparing it
to this macro. However, this is not recommended; you should use the
isfinite macro instead. See section 20.4 Floating-Point Number Classification Functions.
This macro was introduced in the ISO C99 standard.
You can steaibc_20.html#SEC410">20.5.2 Infinity and NaN)
FP_ZERO
FP_SUBNORMAL
fpclassify returns this value
for values of x in this alternate format.
FP_NORMAL
fpclassify is most useful if more than one property of a number
must be tested. There are more specific macros which only test one
property at a time. Generally these macros execute faster than
fpclassify, since there is special hardware support for them.
You should therefore use the specific macros whenever possible.
(fpclassify (x) != FP_NAN && fpclassify (x) != FP_INFINITE) |
isfinite is implemented as a macro which accepts any
floating-point type.
(fpclassify (x) == FP_NORMAL) |
(fpclassify (x) == FP_NAN) |
Another set of floating-point classification functions was provided by BSD. The GNU C library also supports these functions; however, we recommend that you use the ISO C99 macros in new code. Those are standard and will be available more widely. Also, since they are macros, you do not have to worry about the type of their argument.
-1 if x represents negative infinity,
1 if x represents positive infinity, and 0 otherwise.
Note: The isnan macro defined by ISO C99 overrides
the BSD function. This is normally not a problem, because the two
routines behave identically. However, if you really need to get the BSD
function for some reason, you can write
(isnan) (x) |
Portability Note: The functions listed in this section are BSD extensions.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| 20.5.1 FP Exceptions | IEEE 754 math exceptions and how to detect them. | |
| 20.5.2 Infinity and NaN | Special values returned by calculations. | |
| 20.5.3 Examining the FPU status word | Checking for exceptions after the fact. | |
| 20.5.4 Error Reporting by Mathematical Functions | How the math functions report errors. |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The IEEE 754 standard defines five exceptions that can occur during a calculation. Each corresponds to a particular sort of error, such as overflow.
When exceptions occur (when exceptions are raised, in the language of the standard), one of two things can happen. By default the exception is simply noted in the floating-point status word, and the program continues as if nothing had happened. The operation produces a default value, which depends on the exception (see the table below). Your program can check the status word to find out which exceptions happened.
Alternatively, you can enable traps for exceptions. In that case,
when an exception is raised, your program will receive the SIGFPE
signal. The default action for this signal is to terminate the
program. See section 24. Signal Handling, for how you can change the effect of
the signal.
In the System V math library, the user-defined function matherr
is called when certain exceptions occur inside math library functions.
However, the Unix98 standard deprecates this interface. We support it
for historical compatibility, but recommend that you do not use it in
new programs.
The exceptions defined in IEEE 754 are:
If the exception does not trap, the result of the operation is NaN.
Whenever the overflow exception is raised, the inexact exception is also raised.
When no trap is installed for the underflow exception, underflow is signaled (via the underflow flag) only when both tininess and loss of accuracy have been detected. If no trap handler is installed the operation continues with an imprecise small value, or zero if the destination precision cannot hold the small exact result.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
IEEE 754 floating point numbers can represent positive or negative infinity, and NaN (not a number). These three values arise from calculations whose result is undefined or cannot be represented accurately. You can also deliberately set a floating-point variable to any of them, which is sometimes useful. Some examples of calculations that produce infinity or NaN:
When a calculation produces any of these values, an exception also occurs; see 20.5.1 FP Exceptions.
The basic operations and math functions all accept infinity and NaN and produce sensible output. Infinities propagate through calculations as one would expect: for example, , , atan . NaN, on the other hand, infects any calculation that involves it. Unless the calculation would produce the same result no matter what real value replaced NaN, the result is NaN.
In comparison operations, positive infinity is larger than all values
except itself and NaN, and negative infinity is smaller than all values
except itself and NaN. NaN is unordered: it is not equal to,
greater than, or less than anything, including itself. x ==
x is false if the value of x is NaN. You can use this to test
whether a value is NaN or not, but the recommended way to test for NaN
is with the isnan function (see section 20.4 Floating-Point Number Classification Functions). In
addition, <, >, <=, and >= will raise an
exception when applied to NaNs.
`math.h' defines macros that allow you to explicitly set a variable to infinity or NaN.
1.0 / 0.0.
-INFINITY represents negative infinity.
You can test whether a floating-point value is infinite by comparing it
to this macro. However, this is not recommended; you should use the
isfinite macro instead. See section 20.4 Floating-Point Number Classification Functions.
This macro was introduced in the ISO C99 standard.
You can steaibc_20.html#SEC410">20.5.2 Infinity and NaN)
FP_ZERO
FP_SUBNORMAL
fpclassify returns this value
for values of x in this alternate format.
FP_NORMAL
fpclassify is most useful if more than one property of a number
must be tested. There are more specific macros which only test one
property at a time. Generally these macros execute faster than
fpclassify, since there is special hardware support for them.
You should therefore use the specific macros whenever possible.
(fpclassify (x) != FP_NAN && fpclassify (x) != FP_INFINITE) |
isfinite is implemented as a macro which accepts any
floating-point type.
(fpclassify (x) == FP_NORMAL) |
(fpclassify (x) == FP_NAN) |
Another set of floating-point classification functions was provided by BSD. The GNU C library also supports these functions; however, we recommend that you use the ISO C99 macros in new code. Those are standard and will be available more widely. Also, since they are macros, you do not have to worry about the type of their argument.
-1 if x represents negative infinity,
1 if x represents positive infinity, and 0 otherwise.
Note: The isnan macro defined by ISO C99 overrides
the BSD function. This is normally not a problem, because the two
routines behave identically. However, if you really need to get the BSD
function for some reason, you can write
(isnan) (x) |
Portability Note: The functions listed in this section are BSD extensions.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| 20.5.1 FP Exceptions | IEEE 754 math exceptions and how to detect them. | |
| 20.5.2 Infinity and NaN | Special values returned by calculations. | |
| 20.5.3 Examining the FPU status word | Checking for exceptions after the fact. | |
| 20.5.4 Error Reporting by Mathematical Functions | How the math functions report errors. |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The IEEE 754 standard defines five exceptions that can occur during a calculation. Each corresponds to a particular sort of error, such as overflow.
When exceptions occur (when exceptions are raised, in the language of the standard), one of two things can happen. By default the exception is simply noted in the floating-point status word, and the program continues as if nothing had happened. The operation produces a default value, which depends on the exception (see the table below). Your program can check the status word to find out which exceptions happened.
Alternatively, you can enable traps for exceptions. In that case,
when an exception is raised, your program will receive the SIGFPE
signal. The default action for this signal is to terminate the
program. See section 24. Signal Handling, for how you can change the effect of
the signal.
In the System V math library, the user-defined function matherr
is called when certain exceptions occur inside math library functions.
However, the Unix98 standard deprecates this interface. We support it
for historical compatibility, but recommend that you do not use it in
new programs.
The exceptions defined in IEEE 754 are:
If the exception does not trap, the result of the operation is NaN.
Whenever the overflow exception is raised, the inexact exception is also raised.
When no trap is installed for the underflow exception, underflow is signaled (via the underflow flag) only when both tininess and loss of accuracy have been detected. If no trap handler is installed the operation continues with an imprecise small value, or zero if the destination precision cannot hold the small exact result.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
IEEE 754 floating point numbers can represent positive or negative infinity, and NaN (not a number). These three values arise from calculations whose result is undefined or cannot be represented accurately. You can also deliberately set a floating-point variable to any of them, which is sometimes useful. Some examples of calculations that produce infinity or NaN:
When a calculation produces any of these values, an exception also occurs; see 20.5.1 FP Exceptions.
The basic operations and math functions all accept infinity and NaN and produce sensible output. Infinities propagate through calculations as one would expect: for example, , , atan . NaN, on the other hand, infects any calculation that involves it. Unless the calculation would produce the same result no matter what real value replaced NaN, the result is NaN.
In comparison operations, positive infinity is larger than all values
except itself and NaN, and negative infinity is smaller than all values
except itself and NaN. NaN is unordered: it is not equal to,
greater than, or less than anything, including itself. x ==
x is false if the value of x is NaN. You can use this to test
whether a value is NaN or not, but the recommended way to test for NaN
is with the isnan function (see section 20.4 Floating-Point Number Classification Functions). In
addition, <, >, <=, and >= will raise an
exception when applied to NaNs.
`math.h' defines macros that allow you to explicitly set a variable to infinity or NaN.
1.0 / 0.0.
-INFINITY represents negative infinity.
You can test whether a floating-point value is infinite by comparing it
to this macro. However, this is not recommended; you should use the
isfinite macro instead. See section 20.4 Floating-Point Number Classification Functions.
This macro was introduced in the ISO C99 standard.
You can steaibc_20.html#SEC410">20.5.2 Infinity and NaN)
FP_ZERO
FP_SUBNORMAL
fpclassify returns this value
for values of x in this alternate format.
FP_NORMAL
fpclassify is most useful if more than one property of a number
must be tested. There are more specific macros which only test one
property at a time. Generally these macros execute faster than
fpclassify, since there is special hardware support for them.
You should therefore use the specific macros whenever possible.
(fpclassify (x) != FP_NAN && fpclassify (x) != FP_INFINITE) |
isfinite is implemented as a macro which accepts any
floating-point type.
(fpclassify (x) == FP_NORMAL) |
(fpclassify (x) == FP_NAN) |
Another set of floating-point classification functions was provided by BSD. The GNU C library also supports these functions; however, we recommend that you use the ISO C99 macros in new code. Those are standard and will be available more widely. Also, since they are macros, you do not have to worry about the type of their argument.
-1 if x represents negative infinity,
1 if x represents positive infinity, and 0 otherwise.
Note: The isnan macro defined by ISO C99 overrides
the BSD function. This is normally not a problem, because the two
routines behave identically. However, if you really need to get the BSD
function for some reason, you can write
(isnan) (x) |
Portability Note: The functions listed in this section are BSD extensions.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| 20.5.1 FP Exceptions | IEEE 754 math exceptions and how to detect them. | |
| 20.5.2 Infinity and NaN | Special values returned by calculations. | |
| 20.5.3 Examining the FPU status word | Checking for exceptions after the fact. | |
| 20.5.4 Error Reporting by Mathematical Functions | How the math functions report errors. |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The IEEE 754 standard defines five exceptions that can occur during a calculation. Each corresponds to a particular sort of error, such as overflow.
When exceptions occur (when exceptions are raised, in the language of the standard), one of two things can happen. By default the exception is simply noted in the floating-point status word, and the program continues as if nothing had happened. The operation produces a default value, which depends on the exception (see the table below). Your program can check the status word to find out which exceptions happened.
Alternatively, you can enable traps for exceptions. In that case,
when an exception is raised, your program will receive the SIGFPE
signal. The default action for this signal is to terminate the
program. See section 24. Signal Handling, for how you can change the effect of
the signal.
In the System V math library, the user-defined function matherr
is called when certain exceptions occur inside math library functions.
However, the Unix98 standard deprecates this interface. We support it
for historical compatibility, but recommend that you do not use it in
new programs.
The exceptions defined in IEEE 754 are:
If the exception does not trap, the result of the operation is NaN.
Whenever the overflow exception is raised, the inexact exception is also raised.
When no trap is installed for the underflow exception, underflow is signaled (via the underflow flag) only when both tininess and loss of accuracy have been detected. If no trap handler is installed the operation continues with an imprecise small value, or zero if the destination precision cannot hold the small exact result.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
IEEE 754 floating point numbers can represent positive or negative infinity, and NaN (not a number). These three values arise from calculations whose result is undefined or cannot be represented accurately. You can also deliberately set a floating-point variable to any of them, which is sometimes useful. Some examples of calculations that produce infinity or NaN:
When a calculation produces any of these values, an exception also occurs; see 20.5.1 FP Exceptions.
The basic operations and math functions all accept infinity and NaN and produce sensible output. Infinities propagate through calculations as one would expect: for example, , , atan . NaN, on the other hand, infects any calculation that involves it. Unless the calculation would produce the same result no matter what real value replaced NaN, the result is NaN.
In comparison operations, positive infinity is larger than all values
except itself and NaN, and negative infinity is smaller than all values
except itself and NaN. NaN is unordered: it is not equal to,
greater than, or less than anything, including itself. x ==
x is false if the value of x is NaN. You can use this to test
whether a value is NaN or not, but the recommended way to test for NaN
is with the isnan function (see section 20.4 Floating-Point Number Classification Functions). In
addition, <, >, <=, and >= will raise an
exception when applied to NaNs.
`math.h' defines macros that allow you to explicitly set a variable to infinity or NaN.
1.0 / 0.0.
-INFINITY represents negative infinity.
You can test whether a floating-point value is infinite by comparing it
to this macro. However, this is not recommended; you should use the
isfinite macro instead. See section 20.4 Floating-Point Number Classification Functions.
This macro was introduced in the ISO C99 standard.
You can steaibc_20.html#SEC410">20.5.2 Infinity and NaN)
FP_ZERO
FP_SUBNORMAL
fpclassify returns this value
for values of x in this alternate format.
FP_NORMAL
fpclassify is most useful if more than one property of a number
must be tested. There are more specific macros which only test one
property at a time. Generally these macros execute faster than
fpclassify, since there is special hardware support for them.
You should therefore use the specific macros whenever possible.
(fpclassify (x) != FP_NAN && fpclassify (x) != FP_INFINITE) |
isfinite is implemented as a macro which accepts any
floating-point type.
(fpclassify (x) == FP_NORMAL) |
(fpclassify (x) == FP_NAN) |
Another set of floating-point classification functions was provided by BSD. The GNU C library also supports these functions; however, we recommend that you use the ISO C99 macros in new code. Those are standard and will be available more widely. Also, since they are macros, you do not have to worry about the type of their argument.
-1 if x represents negative infinity,
1 if x represents positive infinity, and 0 otherwise.
Note: The isnan macro defined by ISO C99 overrides
the BSD function. This is normally not a problem, because the two
routines behave identically. However, if you really need to get the BSD
function for some reason, you can write
(isnan) (x) |
Portability Note: The functions listed in this section are BSD extensions.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |