• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

waht is -0.0?

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mock Exam:
What is displayed when the following is executed:
double d1 = -0.5;
System.out.println("Ceil d1 = " + Math.ceil(d1));
System.out.println("floor d1 = " + Math.floor(d1));
Answer: -0.0, -1.0.
I compiled and run, it is true.
So what is the difference between -0.0 and 0.0?
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my opinion, 0.0 is equals to -0.0. Sign only indicates how the zero was achieved, whether from positive or negative value.
B Arul
 
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ego...
0.0 & -0.0 :
1. they both are Floating Point Literals.
2. they considered equal when you use (0.0 == -0.0)
3. but produce different result when used in some calculation.
for example :
(1.0/0.0) produces positive invinity, and
(1.0/-0.0) produces negative invinity.
hope this help
stevie
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic