How To Deal With Rounding Errors

2008-12-04 Thread Bridger Maxwell
Hey,
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.


Long explanation of my question:
In my project, I have users clicking and dragging to adjust values. I would
like to map values from the left-most of the view being zero, and the
right-most of the view to be one. This is fairly simple. However, it feels a
little unnatural if the value initially jumps to match where the mouse
clicks before dragging. For example, if the initial value is 0.3, and they
click in the middle of the view, the value jumps to 0.5. To take care of
this I construct a polynomial which maps 0 to 0, the right-most of the view
to 1, and the initial click location (middle) to the initial value (0.3).
This works very well, and feels natural. However, when any of the values
near the edges (the user clicks just off the left of the view), the values
go crazy. I believe this is because of a rounding error. The same question
still stands, would multiplying (and later dividing) everything by a scalar
help me get greater precision?

Thank You,
Bridger Maxwell
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: How To Deal With Rounding Errors

2008-12-04 Thread Nathan Day
The way floats work the round will always be to the same number of  
bits no matter what the order of magnitude (ignoring the extreme  
values  2^-1023 for doubles). Check that you haven't let any integers  
into you calculations.


On 04/12/2008, at 7:08 PM, Bridger Maxwell wrote:


Hey,
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.


Long explanation of my question:
In my project, I have users clicking and dragging to adjust values.  
I would

like to map values from the left-most of the view being zero, and the
right-most of the view to be one. This is fairly simple. However, it  
feels a
little unnatural if the value initially jumps to match where the  
mouse
clicks before dragging. For example, if the initial value is 0.3,  
and they
click in the middle of the view, the value jumps to 0.5. To take  
care of
this I construct a polynomial which maps 0 to 0, the right-most of  
the view
to 1, and the initial click location (middle) to the initial value  
(0.3).
This works very well, and feels natural. However, when any of the  
values
near the edges (the user clicks just off the left of the view), the  
values
go crazy. I believe this is because of a rounding error. The same  
question
still stands, would multiplying (and later dividing) everything by a  
scalar

help me get greater precision?

Thank You,
Bridger Maxwell
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/nathan_day%40mac.com

This email sent to [EMAIL PROTECTED]


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: How To Deal With Rounding Errors

2008-12-04 Thread Andrew Farmer

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
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: How To Deal With Rounding Errors

2008-12-04 Thread Ricky Sharp


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 PROTECTED]
Instant Interactive(tm)   http://www.instantinteractive.com



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]


Re: How To Deal With Rounding Errors

2008-12-04 Thread Scott Ribe
If the user clicks just off the left of the view, does that give you a
negative value? Or do you limit it to 0, then divide by 0? What happens if
you use a range of 1-2 instead of 0-1?

-- 
Scott Ribe
[EMAIL PROTECTED]
http://www.killerbytes.com/
(303) 722-0567 voice


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]