Trouble rounding floats

Discuss Programming
Post Reply
User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Trouble rounding floats

Post by Void Main » Mon Aug 14, 2006 8:36 am

Has anyone ever run into problems with floating point approximation? I know I have. Here's a nice little article on it:

http://www.regdeveloper.co.uk/2006/08/1 ... oximation/

Deeper information:

http://docs.sun.com/source/806-3568/ncg_goldberg.html

worker201
guru
guru
Posts: 668
Joined: Sun Jun 13, 2004 6:38 pm
Location: Hawaii

Post by worker201 » Mon Aug 14, 2006 1:18 pm

Sounds like a potentially serious issue. An issue that would/should have occured to the great programmers of old who invented digital floating point calculations. And if they knew about it, why didn't they come up with a solution?

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Mon Aug 14, 2006 2:12 pm

Maybe you didn't read the article? :) This problem is as old as computers and it's taught in computer programming 101 (and if it's not it should be). As long as you are aware of it and understand the implications you can code around the issue in many cases, in many other cases it isn't even an issue. There are certain cases where it can definitely bite you though.

worker201
guru
guru
Posts: 668
Joined: Sun Jun 13, 2004 6:38 pm
Location: Hawaii

Post by worker201 » Mon Aug 14, 2006 2:57 pm

What I meant was that the first guy who stored a binary floating point number must have seen the issue. I don't know, I guess I would have scrapped that method then and tried to figure out something that works.

If that hadn't been done, then the methods to get around it ought to have been coded into the OS, or the language headers. It just seems like the sort of thing a modern programmer wouldn't have to deal with, just because somebody would have found a way to deal with it already. A simple floating point calculation should be an abstraction of whatever arithmetic method this guy suggests for minimizing float errors.

I admit to not reading the solutions page (or the deep tech page), but I did understand why certain numbers are difficult/impossible to accurately represent with current binary floating point procedures.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Mon Aug 14, 2006 3:20 pm

If you find that simple solution I can assure you, you will become very wealthy.

Post Reply