C ++ float (NAN)

Source: Internet
Author: User

I often get Nan in as3, but I always think that C ++ is of a weak type. I only need the memory. In addition, I usually have a lot of dealings with uint32,

Today, we will step on the trap. A crash is generated when the value is-Nan (0x400000.

Google gains the following:

Http://stackoverflow.com/questions/570669/checking-if-a-double-or-float-is-nan-in-c

For a float F, F! = F will be true only if f is Nan.

For float type variables F, F! = F is valid only when F is Nan.

It seems that it is necessary to determine whether float is a valid value. f = f

ViewCode:

# Include <stdio. h>

Int main (){
Unsigned int I = 0x400000;
Float F = 0.0f;
Printf ("{f: % F, I: % u} \ n", F, I );

* (Unsigned int *) & F) = I;
Printf ("{f: % F, I: % u} \ n", F, I );

F = 0.0f/0.0f;
If (F! = F)
Printf ("F! = F, % F, % u \ n ", F, * (unsigned int *) & F ));
If (F> 0.0f | f = 0.0f | F <0.0f)
Printf ("F> 0.0f | f = 0.0f | F <0.0f) \ n ");
Else
Printf ("cool! \ N ");
Return 0;
}

It turns out that fish are not fish.

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.