delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/09/30/05:04:13

Message-ID: <324F87BF.1AA4@pobox.oleane.com>
Date: Mon, 30 Sep 1996 10:41:35 +0200
From: Francois Charton <deef AT pobox DOT oleane DOT com>
Organization: CCMSA
MIME-Version: 1.0
To: Ian Viemeister <ian AT viemeister DOT com>
CC: djgpp AT delorie DOT com
Subject: Re: ldexp problems (was Re: HELP: What's wrong ?)
References: <01bbae54$12da4180$LocalHost AT 10 DOT 0 DOT 1 DOT 1 DOT inf> <324F415E DOT 5123 AT viemeister DOT com>

Ian Viemeister wrote:
> 
> This is odd.  I checked, and found exactly the same problem (fifth call
> to ldexp always causes SIGFPE).  HOWEVER, if you leave off the "-lm",
> and use the non-math library ldexp, no floating-point error occurs.
> As the obivous quick-fix, Guillermo, just don't link with libm.a
> 
> ***Note to whoever is currently maintaining the math libs:
> Is this a general bug, or is it possibly related to a particular setup?
> 

I am not maintaining the library, but here is an answer : 

This is a "general" bug : it seems to happen because some function 
(*_scalb.s) forgets to pop from the stack some data after pushing it on.
Hence, the stack gets corrupted after a few calls of exponential 
functions (not only ldexp), and your program bombs with a FPE signal, 
sometimes on some seemingly harmless calculation (eg, an addition...).

This bug has been corrected (dig the newsgroup archives at delorie.com 
for information on this), but as you say, you can workaround by not 
linking -lm (you then are using the default math functions of the C 
library). This worked for me, but you should be aware that:

1/ not linking -lm results in faster calculation (on my 486DX at least)
2/ a few functions are missing in libc.a : namely Bessel functions, and 
the Gamma function (not much used heh?)
3/ I am told libm.a functions do a better handling of errors and 
exceptions... 

I have also been told that libm.a functions are more precise, but I do 
not think so (or at least not by a sensible margin).
Anyway, if you need extremely precise math functions, you should never 
rely on library functions...

Hope this helps
Francois

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019