Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!columbia!rutgers!sri-spam!mordor!lll-tis!ptsfa!ihnp4!ihlpm!kmh From: kmh@ihlpm.ATT.COM (Kirk Hoyer) Newsgroups: comp.sys.ibm.pc Subject: Another TURBO C Bug?? Message-ID: <1236@ihlpm.ATT.COM> Date: Thu, 2-Jul-87 10:07:53 EDT Article-I.D.: ihlpm.1236 Posted: Thu Jul 2 10:07:53 1987 Date-Received: Sat, 4-Jul-87 07:54:12 EDT Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 68 Keywords: TURBO C floating point problems I have also encountered problems with floating point numbers, but mine seems to be different. I have applied the three compiler patches that Borland has posted on Compuserve, but the problem still persists. Given the following program: main() { float f1, f2, f3, ffunc(); f1 = 0.1234; f2 = 0.5678; printf("main: f1=%f f2=%f\n",f1,f2); f3 = ffunc( f1, f2 ); printf("main: f3=%f\n",f3); } float ffunc( f1, f2 ) float f1, f2; { float f3; printf("ffunc: f1=%f f2=%f\n",f1,f2); f3 = 0.9876; printf("ffunc: f3=%f\n",f3); return( f3 ); } When this program is compiled and executed (I used the tcc compiler), the values of f1 and f2 printed in the routine ffunc() are not the same as the values printed in the main program. The problem seems to go away if the declaration in the main program for ffunc() is changed as follows: float f1, f2, f3, ffunc( float, float ); Since Borland claims that both declaration styles are supported, it seems to me that both should work. If I could make floating point work by simply adopting this "modern" style, I could live with it. Unfortunately, I wrote a more meaningful program that ran fine on the large UNIX system at work, but failed miserably on my PC at home. After changing all my function declarations to the modern style, the program still bombed. I found the following problem: when a float function returned the value f1 like this: return( f1 ); the calling routine received the value of f1 as 0, even though f1 was printed as having a non-zero value just before returning. When I changed the return to look like this: f1 = 100. * f1; return( f1 ); the calling routine received the expected value. This indicates to me that the handling of floats as parameters and returned values in TURBO C has some serious flaws that have yet to be corrected. I will notify Borland of these problems, and hopefully they will have some answers soon.