Umm... Hi.
Whenever...
33.3 + 33.3 + 33.3 = 99.89999
or
33.3 * 3 = 99.8999
Why doesn't it equal 99.9?
-Berserker
Umm... Hi.
Whenever...
33.3 + 33.3 + 33.3 = 99.89999
or
33.3 * 3 = 99.8999
Why doesn't it equal 99.9?
-Berserker
umm..
whenever question bad....
answer = ?
and
cannot help
Why not post code?
i seem to have GCC 3.3.4
But how do i start it?
I dont have a menu for it or anything.
Because floating point numbers can not respresent every number accurately. However 99.9 does = 99.89999999999999999999999999999999999999999999999 9999999999(to infinity)
Sorry Calculating a triangle's perimeter.
void perimeter(void)
{
float perimeter, a, b, c;
printf("Please input side A > ");
scanf("%f", &a);
printf("Please input side B > ");
scanf("%f", &b);
printf("Please input side C > ");
scanf("%f", &c);
perimeter = a + b + c;
printf("\nThe final solution is... > %.5f\n\n", perimeter);
}
Is there any way I can accurately depcit all numbers?Originally Posted by Thantos
Nope. Due to memory limitations and per fact that some numbers just never end it's impossible to accurately store all numbers. What you have to do is decide how close is close enough.
Edit: you can also try using double instead of float but I don't know how much difference it'll make in this case.
Perhaps that is what I don't understand.Originally Posted by Thantos
To me, 3.33 + 3.33 + 3.33 should equal 99.9. Not 99.8999...
I know it can't store all numbers, but it should accurately depict the numbers displayed.
It screws up Pi too, but that is more understandable.
Oh well, I guess I'll never understand it.
Thanks anyway.
PS: Double did the same as float.
Here is an explanation of fixed-point math, which may also help explain what flaoting point numbers are doing to confuse you.
http://www.wwnet.net/~stevelim/fixed.html
You could also have a look at arbitrary-precision math libraries, like http://www.tc.umn.edu/~ringx004/mapm-main.html
For those who don't already have a copy:
What Every Computer Scientist Should Know About Floating-Point Arithmetic
and
comp.lang.c Frequently Asked Questions (Section 14)
gg