If I directly (not getting it as a result of a calculation), explicitly assign 0.0001 to a variable of a Double type, is it guaranteed to be exactly equal to 0.0001 wherever it goes?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No… because it’s simply impossible to represent 0.0001 as a (finite) binary fraction – you’ll get a rounding error when the literal is compiled or interpreted.
However, integer numbers can be stored without rounding – up to the limit of precision, which is of course lower than for an integer type of the same size. And when the limit is reached, instead of an overflow, you start to lose precision, so at some point
d == d+1