Floating point numbers

From: Hoelz, Thomas (Thomas.Hoelz_at_gedas.de)
Date: Wed Mar 07 2001 - 09:02:28 GMT

Hello Bob,

in my opinion your experience results from the limited precision a computer
uses to represent floating point numbers. In contrast to integers, floating
point numbers on a computer are never exact representations of their
mathematical counterparts!

It's a well known problem in using floats that a comparison of two floats
might yield differing results, even if the computation should result in
equality in a mathematical sense.

	float a, b;
	a = 20;
	b = 5;
	if ( a / b == 4 ) printf("Equality");    // may fail

	float c = a / b;
	if ( c < 0.0000001 ) printf("Equality");    
		// uses a so called "epsilon" to decide on equality of two



This archive was generated by hypermail 2.1.4 : Wed Feb 13 2002 - 21:51:33 GMT