*BSD News Article 20744


Return to BSD News archive

Newsgroups: comp.os.386bsd.bugs
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!agate!doc.ic.ac.uk!uknet!mcsun!chsun!bernina!torda
From: torda@igc.ethz.ch (Andrew Torda)
Subject: Re: Serious bug in NetBSD 0.9 floating-point emulator
Message-ID: <CD5Mt9.AoJ@bernina.ethz.ch>
Sender: news@bernina.ethz.ch (USENET News System)
Nntp-Posting-Host: hermitage
Organization: Computational Chemistry, ETH, Zuerich
References: <26jrb8$89i@mudos.pc.cc.cmu.edu>
Date: Fri, 10 Sep 1993 20:12:44 GMT
Lines: 39

mju@mudos.pc.cc.cmu.edu (Marc Unangst) wrote
[.. headers and stuff deleted ..]
>	printf("sqrt(2) = %lf\n", sqrt(2));
>}
>
>On NetBSD 0.9 with the MATH_EMULATE option, it prints "sqrt(2) = 2".

I have the same problem, also with MATH_EMULATE, but here are some
more details which can be reproduced by the script below:
 - running the example program reproduces the bug
 - recompiling the source for sqrt() with no optimising gives me the
correct answer
 - recompiling the source for sqrt() with -O2 reproduces the bug
Have a look at the script output below.
-Andrew
Script started on Sat Sep 11 00:56:18 1993
z$ cat z.c
#include <math.h>
#include <stdio.h>
int main ()
{
    double a;
    a = sqrt (2.0);
    printf ("%f\n", a);
    exit (0);
}
z$ cp /usr/src/lib/libm/common_source/mathimpl.h .
z$ cp /usr/src/lib/libm/ieee/support.c .
z$ gcc -g -Dnational z.c support.c
z$ gcc -g z.c -lm ; a.out
2.000000                                     <--- broken
z$ a.out
1.414214                                     <--- OK
z$ gcc -O -Dnational z.c support.c; a.out
2.000000                                     <--- broken
z$ exit
Script done on Sat Sep 11 00:58:10 1993
-- 
Andrew Torda, Computational Chemistry, ETH, Zurich, torda@igc.ethz.ch