Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Virtual Machine / June 2004

Tip: Looking for answers? Try searching our database.

NaN in the JVM

Thread view: 
Henry - 20 May 2004 15:13 GMT
Hi,

I want to know what is the semantic of the value NaN (when using float). Is
this a special value only for errors ? Or can there be cases where NaN is
set by the JVM in valid operations ?

My understanding of NaN is that it is used each time you divide by zero.

Thanks in advance,
Henry
Boudewijn Dijkstra - 22 May 2004 14:38 GMT
> 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.
Jonas Geiregat - 15 Jun 2004 14:55 GMT
> 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...


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.