Skip to main content
GameDev.net gamedev.net
🔒 Locked

[C/C++] float == float

Started by jollyjeffers Apr 18, 2004 at 8:24 PM 1 replies 500+ views
Original Post
jollyjeffers
jollyjeffers
hi all, sure this aint a new thing, but the forum search tool is f**ked atm, and won''t help me out I''m well aware of both the practical and conceptual issues of limited precision floating point comparison/operators... so this isn''t directly a question regarding them. From a practical point of view, will the innacuracies caused by such operations be consistant . e.g. float a = 1000.456f; float b = 1000.0f; float c = a - b; now, if ''c == 0.45590001f'' (for example), as an "error", would that error be consistant across: a. The chipset (e.g. that model of pentium/athlon/etc..) b. The compiler (is such op''s affected by compiler?) c. The OS (unlikely, but suppose its an option). From my tests, any errors due to float/double precision have remained constant between runs (not necessarily constant between compilers??) - but I only have 3 compilers and 1 set of hardware can''t really call that conclusive research! any thoughts? cheers, Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
SiCrane
SiCrane
a. Mostly. (Remember the Pentium Bug?) If you go to radically different hardware, like a Cray super computer, the floating point format will be different, but most personal computers use IEEE single and double precision numbers and should give identical or near identical results.
b. Compilers can specify different accuracies by twiddling flags in the floating point coprocessor. For instance, if you have MSVC try looking up _controlfp(), in particular pay attention to the _PC_24, _PC_53, and _PC_64 flags. There are also compiler flags to specify floating point consistencies on most compilers, etc. However, code compiled with similar flags/modes across different compilers should have consistent results.
c. Should be.

Incidently, google indexes much of the forum, so you can do searches on google with site:gamedev.net and get pretty good results.
jollyjeffers
jollyjeffers
cheers SiCrane

I think it may have been that I was searching including "==" using the GDNet search engine. Don''t think it liked that ( a similiar search without said token worked, albeit with minimal useful results ).

>> a. Mostly. (Remember the Pentium Bug?)

yeah, I remember it but I suppose it''s not really much of an issue now. Haven''t heard about the fdiv thing since P1 / early P2''s...

>> b. Compilers can specify different accuracies

interesting. I''ll look up the commands you specify. I suppse this holds against a couple of the project compilation options exposed (something regarding FP consistancy iirc)

>> c. Should be.

thought as much


cheers for the reply,

Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.