*BSD News Article 32245


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!yarrina.connect.com.au!warrane.connect.com.au!kralizec.zeta.org.au!not-for-mail
From: bde@kralizec.zeta.org.au (Bruce Evans)
Newsgroups: comp.os.386bsd.questions
Subject: Re: FreeBSD-1.1 libm, sqrt(-1.00)
Date: 30 Jun 1994 16:26:23 +1000
Organization: Kralizec Dialup Unix Sydney - +61-2-837-1183, v.32bis v.42bis
Lines: 50
Message-ID: <2utoif$prn@kralizec.zeta.org.au>
References: <772914709.AA07837@f74.n700.z6.ftn.air.org>
NNTP-Posting-Host: kralizec.zeta.org.au

In article <772914709.AA07837@f74.n700.z6.ftn.air.org>,

>please comment on the issue of sqrt(-1.0) dump core case.

sqrt(-1.0) dumps core because the default npx control word says to trap
invalid floating point operands.  See <machine/npx.h>.

>on examining /usr/src/lib/libm, there seems to quite a number
>of problems related to the math library.  while the recent X11R6

Yes, there are.  The Sun libm in 1.1.5 (/usr/src/lib/msun) has less
problems but as configured it is broken in the same ways as libm.

>well, the case happens in linux, too.  the case there is even worse:
>source code of libm is not available!

linux dumps core on sqrt(-1.0) for the same reasons as FreeBSD-1.1.
Source code for all linux libraries is freely available.

Different types of brokenness are easy to achieve by changing the
defaults:

1. Change the default control word from 0x1272 to 0x127f.  This will
stop the core dumps and give IEEE 854 conformant arithmetic except
where the compiler does not fully support IEEE 854 (e.g., "auto double
x = 1e300 + 1e300;" probably ought to set the IEEE overflow flag but
doesn't because gcc evaluates the expression at compile time).

IEEE 854 does not specifiy the behaviour of the functions in libm, but
both libm and msun attempt to handle errors in the IEEE way by setting
IEEE exception flags.  The flags may not be set in some cases because
of the compiler problems.

The ANSI C standard specifies the behaviour of some of the functions
in libm.  libm does not support the ANSI method of reporting errors.
msun supports it but this support was not enabled in FreeBSD-current
a few weeks ago.  The ANSI method is probably no affected by the compiler
problems.

2. Additionally change the msun default to support ANSI error reporting.
This is probably best for now.  Be prepared for less obvious bugs from
all the programs that don't check for floating point errors.

3. Additionally change the default control word from 0x127f to 0x137f.
This will be necessary for gcc-2.5.8's support of long doubles to be
useful.  There are many problems with mixed precisions, and the FreeBSD
libraries don't support long doubles, so it is much too early for this
change.
-- 
Bruce Evans  bde@kralizec.zeta.org.au