aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Divinding floating points by zero Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Divinding floating points by zero" Watch "Divinding floating points by zero" New topic
Author

Divinding floating points by zero

Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
Hi!
Little doubt.
Kathy's book says that when divided by zero, a floating point may become infinity or -infinity depending on the sign of the zero.
I checked it out and verified that, at least with sun's jvm, this result is actually due to the sign of the number beeing divided, the sign of the zero doesn't really matter.
Any comments?


Leandro Melo
SCJP 1.4, SCWCD 1.4
shandilya popuru
Ranch Hand

Joined: Dec 21, 2004
Posts: 95
hi leandro

thats right the sign of the numerator is taken into consideration rather than the sign of zero


sandy
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
yes , you are right ... I have also tried ...
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
The following example shows that the sign of the 0.0 certainly has an effect on the sign of the infinite quotent:


Output:


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
This code:


and its output:


might give you an idea what's happening in your tests.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830


output :
Infinite
Infinite
-Infinite
-Infinite
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Are you mean :
there is no difference b/w 0 & -0 .
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
I have checked :

1] there is no difference b/w 0 & -0 .
2] but this two 0.0 & -0.0 are different .
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

The actually is a difference between -0.0 and 0.0, try sorting it and see what order they come out in.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

"Sandy"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

You used to be in compliance. Why did you change your name?

Thanks! and welcome to the JavaRanch!

Mark
[ January 14, 2005: Message edited by: Mark Spritzler ]
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
Allright, you pointed the singalling diferences between 0.0 and 0 and -0.0 and 0. But, what is the reason behind it?
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Originally posted by rathi ji:
Are you mean :


I think he's actually quite nice


42
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608

Allright, you pointed the singalling diferences between 0.0 and 0 and -0.0 and 0. But, what is the reason behind it?


The definitive source that you appear to searching for is called "IEEE754".
This defines how floating-point data types are represented, and how they are operated on, etc.


Tony Morris
Java Q&A (FAQ, Trivia)
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Please download:
http://www.cs.berkeley.edu/~wkahan/ieee754status/IEEE754.PDF
 
 
subject: Divinding floating points by zero
 
Similar Threads
double question in srinivas majji's mock exam
In which occasion will a statement return a value of NaN ?
Floating Point Number and dividebyzero arithmatic exception
Division by zero floating point question
how come there is no error when dividing by 0/