Author | Topic: Math min,max |
Mani ranch hand |
posted April 29, 2000 06:29 AM
1: public void check() 2: { 3: System.out.println(Math.min(-0.0,+0.0)); 4: System.out.println(Math.max(-0.0,+0.0)); 5: System.out.println(Math.min(-0.0,+0.0) ==Math.max0.0,+0.0)); 6: } A) prints -0.0, +0.0 and false. Ans given is B. What is happening here?? Math.min(-0.0,+0.0) gives -0.0 If I'm not wrong -0.0 is differnt from +0.0 [This message has been edited by Mani (edited April 30, 2000).]
|
maha anna bartender |
posted April 30, 2000 11:58 AM
Mani, Please edit your message. The last part. Math.min(-0.0,+0.0) gives +0.0 as Math.max(...) In Java primitive float type, other than NaN all other float values are ordered. float primitive type has special +inf , -inf ,+0.0 ,-0.0 . In these -0.0 is considered to be less than +0.0 and +0.0 is considered to be greater than -0.0. But (0.0 == -0.0) IS TRUE. I have my notes which I written down from JLS and It is said in JLS like that. But min(+0.0,-0.0) is I will get the exact page from JLS for you as soon as I get it. regds [This message has been edited by maha anna (edited April 30, 2000).]
|
Mani ranch hand |
posted April 30, 2000 11:02 PM
Maha , I have edited the message.
|
| | |