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

Printable View

- 01-11-2005BerserkerMath Issues
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 - 01-11-2005misplaced
umm..

whenever question bad....

answer = ?

and

cannot help

Why not post code? - 01-11-2005Thantos
Because floating point numbers can not respresent every number accurately. However 99.9 does = 99.89999999999999999999999999999999999999999999999 9999999999(to infinity)

- 01-11-2005Berserker
Sorry :p 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);

} - 01-11-2005BerserkerQuote:

Originally Posted by**Thantos**

*can*accurately depcit all numbers? - 01-11-2005Thantos
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. - 01-11-2005BerserkerQuote:

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. - 01-11-2005jim mcnamara
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 - 01-11-2005DonFiasco
You could also have a look at arbitrary-precision math libraries, like http://www.tc.umn.edu/~ringx004/mapm-main.html

- 01-11-2005Codeplug
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