Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NaN Literal in C?

How do you write an NaN floating-point literal in C?

like image 363
user541686 Avatar asked Apr 19 '11 09:04

user541686


People also ask

What is NaN in C?

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 Floating-Point Number Classification Functions).

What is NaN in double C?

Returns a quiet NaN (Not-A-Number) value of type double . The NaN values are used to identify undefined or non-representable values for floating-point elements, such as the square root of negative numbers or the result of 0/0.

What makes a float a NaN?

NaN stands for Not A Number and is one of the common ways to represent the missing value in the data. It is a special floating-point value and cannot be converted to any other type than float. NaN value is one of the major problems in Data Analysis.

Why does NaN occur?

NaN, an acronym for Not a Number is an exception that usually occurs in the cases when an expression results in a number that is undefined or can't be represented. It is used for floating-point operations. For example: The square root of negative numbers.


1 Answers

In C99's <math.h>

  7.12  Mathematics <math.h>
   [#5] The macro

           NAN

   is defined if and only if the implementation supports  quiet
   NaNs   for  the  float  type.   It  expands  to  a  constant
   expression of type float representing a quiet NaN.           |
like image 87
pmg Avatar answered Oct 21 '22 20:10

pmg