floating point multiplication BUG in C (cc compiler)

Kevin D. Quitt kdq at demott.COM
Sun Oct 21 02:09:35 AEST 1990


In article <1348 at banach.ACA.MCC.COM> mishra at banach.ACA.MCC.COM (Aditya Mishra) writes:
>BUG !!!   BUG !!!   BUG !!!
>
>THIS PROGRAM DEMONSTRATES WHAT I BELIEVE IS A BUG IN FLOATING POINT
>MULTIPLICATION IN 'C' !! 

    Calm down, take a deep breath.  There. Feel better?

    This has nothing to do with C.  It has to do with your individual
compiler (which, by the way you didn't identify) on your particular
machine (which you also didn't identify), the libraries used, and quite
possibly the floating-point notation itself. 

    cc on this machine also gets 3199 instead of 3200, but gnu's gcc gets
this one right.  They both miss the second one by one, so it's possible
that this is due to the inherent inaccuracy of floating point numbers.  If
your need to be exactly on, use integers, not floating point, or round the
data in the process of conversion to integer - remember: conversion from
floating point to integer in C is defined as truncation, not rounding.

    If the floating point value is off by one LSB (as it's allowed to be in
the IEEE spec), you will not get the correct integer.  Please note the
following warning generated by the Microsoft C compiler:

foo.c(13) : warning C4051: type conversion - possible loss of data

    See what it's trying to tell you?  So again, relaxen und vatchen das
blinkenlites.
-- 
 _
Kevin D. Quitt         demott!kdq   kdq at demott.com
DeMott Electronics Co. 14707 Keswick St.   Van Nuys, CA 91405-1266
VOICE (818) 988-4975   FAX (818) 997-1190  MODEM (818) 997-4496 PEP last

                96.37% of all statistics are made up.



More information about the Comp.lang.c mailing list