File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes float and double concepts Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "float and double concepts" Watch "float and double concepts" New topic
Author

float and double concepts

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 3901
I'm reading the JLS and dont unerstand some of the concepts related to floating point numbers. What is normalized and denormalized? What is FP-strict? What is value set conversion?
If anyone can help explain this stuff in english I would appreciate it.


I never took notes in college. That's how I got a 4.0 the first 2 years, and a 3.5 the second two years.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Randall,
I had trouble with this as well, from what I understand (and I'm not great at math); there is a standard, IEEE 754, which defines the rules for handling floating point numbers particularly how infinities are to be treated and how high-precision numbers are rounded during calculations.
Java basically guarantees that

The rules for operations on infinities match normal mathematical expectations.
The Java Programming Language: Second Edition
Ken Arnold and James Gosling

The same book gives the rules for inifinities as:
<pre>





































x y x/y x%y
finite 0.0 infinity NaN
finite infinity 0.0 x
0.0 0.0 NaN NaN
infinity finite infinity NaN
infinity infinity NaN NaN

</pre>
Where NaN is Not a number and infinity can be POSITIVE_INFINITY or NEGATIVE_INFINITY.
What this boils down to is: floating point arithmetic will never throw an <code>ArithmeticException</code>. So a divide by zero will not cause a Runtime error and underflow/overflow conditions (results that won't fit within 32-bit or 64-bit memory) don't cause runtime errors.
The value set is the range a number can fall within. When a number with many decimals is divided by another number large decimals values which exceed what can be held by 32-bit or 64-bit memory storage result. How the runtime rounds the result to fit within the available memory is also defined in the standard. For the most part, Java rounds toward zero or chops off the portion that won't fit into storage. There are other extended value sets that allow for different rounding mechanisms.
When strictfp is used, Java guarantees that any arithmetic operation will strictly conform to the standard; producing the same result any other system conforming to the standard would produce. If strictfp is not used there are cases when an extended or different value set is allowed whose results may or may not match the result arrived at by strictly following the standard.
Bottom line, unless your doing really intensive and precise mathematical calculations you don't really need to be concerned with infinitesimal differences in calculations.
As for normalized and denormalized from what I can make out a number is normalized if it fits within the standard value set; otherwise it's denormalized (although I'm really iffy on this).
Whew! Hope that makes sense and if I've got anything wrong someone with a better understanding will jump in.
------------------
Jane
The cure for boredom is curiosity.
There is no cure for curiousity.
-- Dorothy Parker
[This message has been edited by Jane Griscti (edited November 01, 2000).]


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 3901
thanks that helped a lot. also i love the quote!
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Your welcome I swiped the quote from "The Java Programming Language" ... they've got some really good ones.
------------------
Jane
The cure for boredom is curiosity.
There is no cure for curiousity.
-- Dorothy Parker
 
 
subject: float and double concepts
 
Threads others viewed
tool to measure how many domain concepts
java And J2EE
jdk1.4 and jdk1.5
security design pattern
Passed SCEA Part I with 87%
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com