Infinite and Not A Number
isInfinite( ) returns true if the value being tested is infinitely large or small in magnitude. isNaN( ) returns true if the value being tested is not a number.
Using the following methods you can find out if a float value is infinite value or it is not a number(NaN).
boolean isInfinite()
- Returns true if this Float value is infinitely large in magnitude, false otherwise.
static boolean isInfinite(float v)
- Returns true if the specified number is infinitely large in magnitude, false otherwise.
boolean isNaN()
- Returns true if this Float value is a Not-a-Number (NaN), false otherwise.
static boolean isNaN(float v)
- Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.
public class Main {
public static void main(String[] args) {
Float floatObject2 = Float.valueOf((float)0.0/(float)(0.0));
System.out.println(floatObject2);
System.out.println("isInfinite:"+floatObject2.isInfinite());
System.out.println("isNaN:"+floatObject2.isNaN());
}
}
The output:
NaN
isInfinite:false
isNaN:true
public class Main {
public static void main(String[] args) {
Float floatObject2 = Float.valueOf(1/(float)(0.0));
System.out.println(floatObject2);
System.out.println("isInfinite:"+floatObject2.isInfinite());
System.out.println("isNaN:"+floatObject2.isNaN());
}
}
The output:
Infinity
isInfinite:true
isNaN:false
Home
Java Book
Essential Classes
Java Book
Essential Classes
Float:
- Float class
- MAX/MIN_VALUE Find out the Maximum value and Minimum value a float type can have
- Create a Float object
- Convert Float to byte, double, float, int, long and short
- Compare two float objects
- Infinite and Not A Number
- Convert float value to Hex String value
- Convert float value to String value
- Convert string value to float value
- Bit oriented calculation for float