Saturday, January 21, 2006

Floating Point Anamoly

Source:YPK "Test Your C Skills" Ch-4 "Floating Point Issues" 1st question

main()
{
float a=0.7;
if(a <0.7) a="="b" href="http://docs.sun.com/source/806-3568/ncg_goldberg.html">IEEE
and
Why this anamoly

One good practice is

use something like
#include <math.h>

if(fabs(a - b) <= epsilon * fabs(a))

for some suitably-chosen degree of closeness epsilon (as long as a is nonzero!).


1 comment:

Shantanu said...

Error in the main code(typo error regretted)
main()
{
float a=0.7;
if(a <0.7)
printf("C");
else
printf("C++");
}
Output: C
Reference:http://docs.sun.com/source/806-3568/ncg_goldberg.html