0

The following piece of code outputs 0.1000000000001

float a=0.1;
printf("%lf",a);

But if I add a 10 times as

long float b=0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1;
printf("lf",b);

It outputs as 0.999999999999989
But if a=0.1 is stored as 0.1000000000001 then the answer should be greater than 10 due to the 1 in last column.Then why is the output less then 10

Edited by saurabh.mehta.33234

2
Contributors
3
Replies
5
Views
4 Years
Discussion Span
Last Post by deceptikon
0

Thankyou for your answer actually I read the link that you gave before I posted this article..But my doubt was that since the value of 0.1 shown above is slightly greater than 0.1 then why does the addition yield a value less than 1.

0

But my doubt was that since the value of 0.1 shown above is slightly greater than 0.1 then why does the addition yield a value less than 1.

You say you read the article, but then ask a question that belies your assertion. A combination of inaccuracy at higher precisions and arithmetic rounding is why you're getting unexpected results. Read the article again, and this time actually try to understand it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.