• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How To Deal With Rounding Errors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How To Deal With Rounding Errors


  • Subject: Re: How To Deal With Rounding Errors
  • From: Ricky Sharp <email@hidden>
  • Date: Thu, 4 Dec 2008 06:56:19 -0600


On Dec 4, 2008, at 6:37 AM, Andrew Farmer wrote:

On 04 Dec 08, at 00:08, Bridger Maxwell wrote:
Short version of my question: I believe I am having rounding errors because
I am working with really, really small values. Would it help if I multiplied
these values by a scalar (say, 1,000), did math with them, and then divided
them by the scalar? I remember learning how IEEE floating point numbers are
stored, but I can't remember enough about it to know if this would have any
effect on precision. If not, what is a good way to get better precision? I
am already using doubles instead of floats.

No; if anything, multiplying by a constant will reduce your precision slightly.


If you're having precision issues with doubles, you are probably manipulating your intermediate values in such a way as to destroy precision ("loss of significance"). A common culprit is subtracting two values of nearly equal value. Without knowing what your math looks like, it's hard to guess what might be at fault, but rearranging your float math to avoid this sort of thing may improve your results.

Goldberg's "What Every Computer Scientist Should Know About Floating Point" is a worthwhile read, and covers this issue (as well as many other pitfalls) in great detail:

http://www.engr.pitt.edu/hunsaker/3097/floatingpoint.pdf

One common thing to do when working with very small values (i.e. values close to zero), is to order your operations. For example, if you have a set of values that you want to compute a sum, adding them in smallest to largest order will often be different than largest to smallest.


___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >How To Deal With Rounding Errors (From: "Bridger Maxwell" <email@hidden>)
 >Re: How To Deal With Rounding Errors (From: Andrew Farmer <email@hidden>)

  • Prev by Date: Re: How To Deal With Rounding Errors
  • Next by Date: Re: Asynchronous timers (without a run loop)
  • Previous by thread: Re: How To Deal With Rounding Errors
  • Next by thread: Re: How To Deal With Rounding Errors
  • Index(es):
    • Date
    • Thread