Floating point problems

Started by
11 comments, last by Spanky 20 years, 5 months ago
quote:Original post by Spanky
Hey,

Thanks for the link. I''ll give that a quick read in a few minutes (haha, that thing is pretty long. I think it will take me a bit to get through it).

I guess I will have to find another solution to what I want to do.

All I wanted to do was increment 200 in increments of 0.1 each time... didn''t think this would be terribly hard to do. Damn these infernal contraptions.

Shawn


Well then why are you multiplying 0.1 by 1.0 first and then adding it to origValue?
If you just put delta + origValue that would solve half your problem.
I think even:
delta = 0.1f * 1 would be more accurate than 0.1f * 1.0f
Advertisement
Well, I wasn''t technically accurate in what I said. I do want to increment by 0.1 each time but I want to specify how many times (pixels the mouse has moved). I want to try using a loop instead and see if that would do anything to improve the accuracy.

Thanks
Shawn
quote:Original post by Spanky
Well, I wasn''t technically accurate in what I said. I do want to increment by 0.1 each time but I want to specify how many times (pixels the mouse has moved). I want to try using a loop instead and see if that would do anything to improve the accuracy.

Thanks
Shawn


Since all the variables in your problem are essentially measured as integer values (number of pixels travelled, mouse input value, milliseconds of time), then the most accurate thing to do for that case is simply move everything to integer.

That should only really require a few integer multiplies more to account for things such as converting "pixels moved per milisecond" to "pixels moved per second".

The point of the replies to this thread are more that floating point has its place when you need a much greater range than say 2^32. But can''t represent *everything*. If you need every value in a range, use fixed point or similar.

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

This topic is closed to new replies.

Advertisement