• 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

Difference between StrictMaths ans Maths

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
What is difference between StrictMaths ans Maths class.?
Thanks.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, neither one is a Java class, so it seems the only difference is that they are spelled differently.
If you're actually talking about Math and StrictMath, the difference is basically that StrictMath is strictly defined so that its methods will always produce exactly the same answer, on any platform. The Math class is a little more flexible; its methods may produce slightly different results for different implementations. Results will be very close, but the roundoff errors may differ. E.g. when you expect 2.1 you may instead get 2.0999999997 or 2.1000000005. (You get roundoff errors like this for StrictMath as well, but the're consistent (reproducible on any platform)). The advantage to Math is that as technology changes, it can take advantage of new algorithms which may be faster or slightly more accurate than those in StrictMath. For most appliations, Math is the one you want to use - but if you're studying roundoff errors you may need the consistency that StrictMath provides.
The keyword strictfp has an effect similar to using StrictMath - it forces calculations to conform to strictly-defined algorithms.
Note that I don't think StrictMath or strictfp are actually covered in the SCJP exam - though I suppose they could be.
[ January 22, 2003: Message edited by: Jim Yingst ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic