I’m working through C++ Primer Plus, using Xcode as my IDE and one of the exercises calls for assigning the value 0.0254 to a symbolic constant (converting inches to meters). The problem is, when I declare the constant I’m getting a value of 0.0253999997. I’m declaring the constant as seen below.
#include <iostream>
const float METERS_PER_INCH = .0254;
Don’t worry your mac is OK.
Problem is that computers can’t accurately represent floats and doubles so this is what you are seeing there.
Why comparing double and float leads to unexpected result?
http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
strange output in comparison of float with float literal
Google is your friend!