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 / General / October 2007

Tip: Looking for answers? Try searching our database.

What is "-0.0"

Thread view: 
Morgan Cheng - 13 Oct 2007 13:06 GMT
In java 6.0, I have below code.
double x = 0.0;
double y = -10.0;
double z = x / y;
System.out.println("z = " +z);

The result is "-0.0". This is wired, why it is negative zero?
Richard Reynolds - 13 Oct 2007 15:18 GMT
> In java 6.0, I have below code.
> double x = 0.0;
[quoted text clipped - 3 lines]
>
> The result is "-0.0". This is wired, why it is negative zero?

http://en.wikipedia.org/wiki/%E2%88%920_(number)
Patricia Shanahan - 13 Oct 2007 15:49 GMT
> In java 6.0, I have below code.
> double x = 0.0;
[quoted text clipped - 3 lines]
>
> The result is "-0.0". This is wired, why it is negative zero?

I agree that it is weird, but there are reasons why IEEE 754 floating
point arithmetic distinguishes positive and negative zero.

A zero may be a stand-in for a number of very small absolute magnitude.
There are some algorithms where intermediate results overflow and
underflow, but the final answer is representable.

Preserving the sign on underflow, and through arithmetic using a zero,
also preserves the sign on division by the result of the underflow,
leading to the correct choice between positive and negative infinity.

Patricia
Stefan Ram - 13 Oct 2007 17:29 GMT
>The result is "-0.0". This is wired, why it is negative zero?

 The first result for

http://google.to/search?q=negative+zero

 currently is

http://en.wikipedia.org/wiki/%E2%88%920_(number)

 .
Roedy Green - 14 Oct 2007 10:20 GMT
On Sat, 13 Oct 2007 05:06:35 -0700, Morgan Cheng
<morgan.chengmo@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>The result is "-0.0". This is wired, why it is negative zero?

Because floating point has both a positive and negative 0, signed
magnitude, unlike ints.  see http://mindprod.com/jgloss/ieee754.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



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



©2009 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.