Friday, 15 March 2013

java - System.out.println(0.0%0.0!=0.0/0.0); what will be the out put ? Can you Please Explain the Answers any one? -



java - System.out.println(0.0%0.0!=0.0/0.0); what will be the out put ? Can you Please Explain the Answers any one? -

this question has reply here:

why double.nan==double.nan homecoming false? 8 answers

i studying ocjp questions , found unusual code:

public class abc { public static void main(string[] args) { system.out.println(0.0%0.0!=0.0/0.0);// homecoming true system.out.println(0.0%0.0==0.0/0.0);// homecoming false } }

when ran code, got:

true false

how output false when we're comparing 2 things same each other? nan mean?

both 0.0 / 0.0 , 0.0 % 0.0 homecoming double.nan.

if compare double.nan == double.nan receive false , why system.out.println(0.0%0.0==0.0/0.0); prints false.

the question goes why double.nan == double.nan homecoming false?

according jls:

floating-point operators produce no exceptions (§11). operation overflows produces signed infinity, operation underflows produces denormalized value or signed zero, , operation has no mathematically definite result produces nan. numeric operations nan operand produce nan result. has been described, nan unordered, numeric comparing operation involving 1 or 2 nans returns false , != comparing involving nan returns true, including x!=x when x nan.

more info:

why double.nan==double.nan homecoming false?

java

No comments:

Post a Comment