Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can float (or double) be set to NaN?

Tags:

Note: Similar to Can an integer be NaN in C++?

I understand this has little practical purpose, but can a float or double be set to NaN?

like image 466
ahodder Avatar asked Sep 14 '11 15:09

ahodder


People also ask

What makes a float NaN?

In data science, Nan is used to represent the missing values in a dataset. So Nan is basically a placeholder to represent undefined or missing values. You can create the Nan value using float type. Since it is not a defined keyword in Python, you have to pass it to float in a string format (within quotes).

What is float NaN Java?

The Float. isNaN() method in Float Class is a built in method in Java returns true if this Float value or the specified float value is Not-a-Number (NaN), or false otherwise. Syntax: public boolean isNaN() or public static boolean isNaN(float val)

Is float NaN Python?

In Python, the float type has nan . nan stands for "not a number" and is defined by the IEEE 754 floating-point standard.


2 Answers

The Float object contains a static value, which is a float type, called NaN.

So

float myFloat = Float.NaN; 

gives you what you are asking.

http://download.oracle.com/javase/6/docs/api/java/lang/Float.html#NaN

like image 191
Codemwnci Avatar answered Sep 20 '22 14:09

Codemwnci


Sure! NaN is a static constant in the Float and Double classes.

double x = Double.NaN; 
like image 23
japreiss Avatar answered Sep 19 '22 14:09

japreiss