Path: utzoo!attcan!uunet!snorkelwacker!usc!srhqla!demott!kdq From: kdq@demott.COM (Kevin D. Quitt) Newsgroups: comp.lang.c Subject: Re: floating point multiplication BUG in C (cc compiler) Keywords: bug in C float multiplication Message-ID: <807@demott.COM> Date: 20 Oct 90 16:09:35 GMT References: <1348@banach.ACA.MCC.COM> Reply-To: kdq@demott.COM (Kevin D. Quitt) Organization: DeMott Electronics Co., Van Nuys CA Lines: 35 In article <1348@banach.ACA.MCC.COM> mishra@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@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.