> Hi,
>
> I want to know what is the semantic of the value NaN (when using float). Is
> this a special value only for errors ?
Yes, NaN is used when the result of an operation neither a finite number or
an infinity, due to restrictions in the operation performed.
> Or can there be cases where NaN is
> set by the JVM in valid operations ?
What do you regard as an (in)valid operation?
> My understanding of NaN is that it is used each time you divide by zero.
No, unless you divide zero by zero or you want the remainder of a division
by zero. Read paragraph 17 of chapter 15 of the Java Language
Specification. And the documentation on the java.lang.Math.sqrt method.
> Hi,
>
[quoted text clipped - 6 lines]
> Thanks in advance,
> Henry
Doesn't NaN stand for Not a Number ?
Chris Smith - 15 Jun 2004 15:07 GMT
> Doesn't NaN stand for Not a Number ?
Yes, it does.

Signature
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Andrew Thompson - 15 Jun 2004 15:16 GMT
..
>> My understanding of NaN is that it is used each time you divide by zero.
..
> Doesn't NaN stand for Not a Number ?
It does, try this..
System.out.println( Math.sqrt( -1 ) );
Attempts to divide by zero will also
result in a mathematical entity that
is not representable in the normal
numeric range. (..err I forget the
term for such a number)

Signature
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Mark Bottomley - 16 Jun 2004 01:19 GMT
> ..
> >> My understanding of NaN is that it is used each time you divide by zero.
[quoted text clipped - 10 lines]
> numeric range. (..err I forget the
> term for such a number)
One of the best sites for understanding floating point numbers
is http://babbage.cs.qc.edu/courses/cs341/IEEE-754references.html
It identifies Quiet and Signalling Nan's. There are also +/- infinities,
+/- zeroes, denormalized floating point numbers and signed underflows.
The links off the page go to on-line hex/float43/float64 conversions.
You can also find many of the rules for Nan's and infinities in the JVM
spec.
Mark...