Inf&nan (excerpt from Baidu)

Source: Internet
Author: User

Excerpt from Baidu (Http://zhidao.baidu.com/link?url=Vv8vThjOgVIl1WV_WF_9yJcGVwt_2RkwdK3nyNuRZJa_ TKOF0HSDUPRATETYDNXNB6FSBAUBJF3XTCSVEFULGA)

Inf:infinity (Linux) is equivalent to #INF: Infinity
(Windows)

Nan:not A
Number is equal to
#IND: Indeterminate (Windows)

Note: 1, INF is generally due to the resulting value, exceeding the range of floating point number (overflow, that is, the order portion exceeds the maximum value it can represent), and Nan is generally because the floating-point numbers are undefined operations, such as the 1 root.

2, Nan==nan
The result is 0 or false, that is, you cannot compare with Nan, and the result that is compared to Nan is always false or 0. So you can use the function: int
Isnumber (double D) {return (d==d);} To determine if D is Nan and if D is Nan returns 0, otherwise a value other than 0 is returned.

3, 1.0/0.0 equals inf,-1.0/0.0 equals-inf,0.0+inf=inf;

4, the negative root sqrt (-1.0), the negative logarithm (log (-1.0)), 0.0/0.0, 0.0*inf, Inf/inf, inf-inf These operations will be Nan. (0/0 generates an operation exception; 0.0/0.0 does not produce an operation exception, but it gets Nan)

5, when the INF to see if there is overflow or divided by 0, to obtain a nan to see if there is an illegal operation.

6, C language header file <float.h>, there is a defined constant Dbl_max, this constant represents "the largest double-precision floating-point value can be represented". The <float.h> also has a constant dbl_min,dbl_min that represents the smallest positive floating-point number that can be normalized, but dbl_min is not the smallest positive floating-point number because it can be smaller with a non-normalized floating-point number. Functions can be used: int
Isfinitenumber (double D) {return
(D<=dbl_max&&d>=-dbl_max);} To determine if D is a finite number (neither INF nor Nan (with D as Nan, then D will get a value of False (0) if it participates in the comparison)).

7, 1.0/inf equals 0.0.

8, INF can be compared with other floating-point numbers, that is, you can participate in <=, >+, = =,! = and other operations.

  

The following macros (implemented as macros, using the same form as functions) are used to determine whether the result of an expression is INF, Nan, or other:

Header file:include<math.h>

Use of macros (similar to function prototypes): int fpclassify (x);

Int
Isfinite (x);

Int
Isnormal (x);

int isNaN (x);

int Isinf (x);

Specific usage:

1, int
Fpclassify (x)
To view the case of a floating-point number x, fpclassify can use any floating-point expression as an argument, and the return value of fpclassify has the following conditions.

Fp_nan:x is a "not a number".

Fp_infinite:x is positive and negative infinity.

FP_ZERO:X is 0.

The fp_subnormal:x is too small to be represented by the normalized form of a floating-point number.

Fp_normal:x is a normal floating-point number (not any of the above results).

2, int
Isfinite (x)
When (fpclassify (x)!=fp_nan&&fpclassify (x)!=fp_infinite), this macro gets a non-0 value.

3, int
Isnormal (x) when (fpclassify (x) ==fp_normal), this macro gets a non-0 value.

4, int
isNaN (x) when (fpclassify (x) ==fp_nan), this macro returns a value other than 0.

5, int
Isinf (x) when x is positive infinity is returned 1, when x is negative infinity returns-1. (Some older compiler versions, whether positive or negative, return a non-0 value, with no distinction between positive and negative infinity).

Inf&nan (excerpt from Baidu)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.