Forums Register Login

Floating point divide by zero

+Pie Number of slices to send: Send
Can anybody explain whether the following statement is true or not.
If true, please explain.

Floating point modulo (%) by zero produces NaN , but floating point divide by zero does not.
+Pie Number of slices to send: Send
Hi
Its true
Floating point divide by zero produces Infinity & Floating point modulo by zero produces NaN(not a number)
+Pie Number of slices to send: Send
does anyone know the reason behind this ?

Why arithmetic exception happens for int and not for float ?
[ March 28, 2007: Message edited by: JB Ramesh ]
+Pie Number of slices to send: Send
 

Originally posted by JB Ramesh:
does anyone know the reason behind this ?

Why arithmetic exception happens for int and not for float ?



The behavior of float is actually defined by the IEEE standard. Java follows the same standard used by most floating point processors in use today.

As for int, it throws an exception, because there is no representation for infinity or NaN.

Henry
+Pie Number of slices to send: Send
My actual doubt is that floating point module zero also does divide by zero internally. So why Nan is getting printed instead of Infinity?
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 893 times.
Similar Threads
floating point and integers..
Double
Rules roundup #113
What is Not-a-Number (NaN)?
java rule round up #113
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 01:55:57.