• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error in Velmurugan's notes on floating point precision

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Velmurugan,
You have done a great work by collecting all the information required for the exam. I am taking the exam on Feb 9th.
I would like to point out an error in your notes:
-----------------------------------------------------
Floating point arithmetic always loses precision. The following code fragment returns false.
float f = 1.0 F / 3.0 F; if ( A * 3.0 F == 1.0 F ) return true; else return false;
-----------------------------------------------------
I assume A in the above expression is a typo. it is f.
If that is the case, then as such the above expression will return true, because even though u r making f to get a less precisioned value when u multiply by 3.0F u get back the same 1.0F u used to obtian f.
If it was just 3.0 then i agree with u that it is false (since LHS is a double and the RHS when promoted to double will not match it).
thanks
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for pointing it out. I agree with you, I noticed this sometime back, but forgot to change the notes.
Best wishes.

------------------
Velmurugan Periasamy
Sun Certified Java Programmer
----------------------
Study notes for Sun Java Certification
http://www.geocities.com/velmurugan_p/
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey
itz not only floating point arithmetic even integer airthmetic can lose precission. But is it that floating point arithmetic always loses precission.
Tell me what happens here
float f = 1.0F / 3.0F;
if ( A * 3.0F == 1.0F )
and here
float f = 1.0F / 3.0F;
if ( A * 3.0 == 1.0F )
Cherry
 
reply
    Bookmark Topic Watch Topic
  • New Topic