#getting an NaN output

18 messages · Page 1 of 1 (latest)

serene orchid
#

im getting an NaN output trying to do a small calculation lab...can anyone tell me what im doing wrong here?

rich ridge
#

are you dividing 0.0/0.0?

serene orchid
#

no

#

let me check

#

this is the input file

#

is that whats wrong?

violet bay
#

You're probably dividing by zero

#

./run ```java
System.out.println(0.0/0.0);

torpid prairieBOT
#

Here is your java(15.0.2) output @violet bay

NaN
serene orchid
#

i see

#

so if theres one instance of that it just overrides the rest of the equations needed in the output?

violet bay
#

Yeah, NaN is a bit viral

#

But you can check for it with Double.isNaN(...)

#

./run ```java
System.out.println(Double.isNaN(1.0/0.0));
System.out.println(Double.isNaN(0.0/0.0));

torpid prairieBOT
#

Here is your java(15.0.2) output @violet bay

false
true
violet bay
#

./run ```java
double x = 0.0/0.0;
double y = x + 45.0;
double z = y * 3.0;
System.out.println(z);

torpid prairieBOT
#

Here is your java(15.0.2) output @violet bay

NaN
violet bay
#

./run ```java
double x = 0.0/0.0;
if (x == x) {
System.out.println("Equal");
}
else {
System.out.println("Not equal");
}