Tag Archives: float

Please Calculate This Circle’s Circumference

“Please write a C++ function that takes a circle’s diameter as a float and returns the circumference as a float.” It sounds like the sort of question you might get in the first week of a C++ programming class. And … Continue reading

Posted in Floating Point, Programming | Tagged , , , | 75 Comments

Float Precision Revisited: Nine Digit Float Portability

Last year I pointed out that float variables can be converted to text and then back to the same binary value using printf(“%1.8e”). You can also use %.9g for more compact results. I also supplied a test program that used … Continue reading

Posted in Floating Point | Tagged , , , , | 17 Comments

Doubles are not floats, so don’t compare them

I’ve seen a few online discussions linking to my Comparing Floating Point Numbers page for misguided reasons and I wanted to discuss those reasons to help people understand why throwing epsilons at the problem without understanding the situation is a … Continue reading

Posted in Floating Point, Programming | Tagged , , , , | 24 Comments

Exceptional Floating Point

Floating-point math has an answer for everything, but sometimes that’s not what you want. Sometimes instead of getting an answer to the question sqrt(-1.0) (it’s NaN) it’s better to know that your software is asking imaginary questions. The IEEE standard … Continue reading

Posted in AltDevBlogADay, Floating Point, Programming | Tagged , , , , | 24 Comments

Floating-point complexities

Binary floating-point math is complex and subtle. I’ve collected here a few of my favorite oddball facts about IEEE floating-point math, based on the articles so far in my floating-point series. The focus in this list is on float but … Continue reading

Posted in AltDevBlogADay, Floating Point, Programming | Tagged , , , , , , , , | 15 Comments

Intermediate Floating-Point Precision

Riddle me this Batman: how much precision are these calculations evaluated at? If you answered ‘double’ and ‘float’ then you score one point for youthful idealism, but zero points for correctness. The correct answer, for zero-idealism points and forty two … Continue reading

Posted in AltDevBlogADay, Floating Point, Programming, Visual Studio | Tagged , , , , , | 43 Comments

C++ 11 std::async for Fast Float Format Finding

After a recent post on float precision there was some debate about round-tripping of floats. My claim was that if you print a float with printf(“%1.8e”, f); and then scan it back in then you are guaranteed to get back … Continue reading

Posted in Floating Point, Programming, Visual Studio | Tagged , , , | 24 Comments

Float Precision–From Zero to 100+ Digits

How much precision does a float have? It depends on the float, and it depends on what you mean by precision. Typical reasonable answers range from 6-9 decimal digits, but it turns out that you can make a case for … Continue reading

Posted in AltDevBlogADay, Floating Point, Programming | Tagged , , , , , | 52 Comments

Comparing Floating Point Numbers, 2012 Edition

This post is a more carefully thought out and peer reviewed version of a floating-point comparison article I wrote many years ago. This one gives solid advice and some surprising observations about the tricky subject of comparing floating-point numbers. A … Continue reading

Posted in AltDevBlogADay, Floating Point, Programming | Tagged , , , , , , | 181 Comments

Don’t Store That in a Float

I promised in my last post to show an example of the importance of knowing how much precision a float has at a particular value. Here goes. As a general rule this type of data should never be stored in … Continue reading

Posted in AltDevBlogADay, Floating Point, Programming | Tagged , , , , , , | 27 Comments