Fwd: Floating point exception in strtod()

Ken Brown kbrown@cornell.edu
Sun Apr 8 18:40:00 GMT 2018


On 4/7/2018 8:05 PM, Brian Inglis wrote:
> (gdb) p aadj
> $1 = 2529648000
> (gdb) p L
> $2 = -1765319296

[...]

> Seems to be happening at strtod.c line 1189 conversion to Long in:
> https://sourceware.org/git/?p=newlib-cygwin.git;a=blame;f=newlib/libc/stdlib/strtod.c;h=402510cdf24ee332a9fc09c6f73df06b1975a6e2;hb=4c73ad6b20378e4b74355fcdb2005f2aac489c9f#l1189
> 1187			if (y == z) {
> 1188				/* Can we stop now? */
> 1189				L = (Long)aadj;		!!!
> 1190				aadj -= L;

Note that aadj == 2529648000 == 0x96C75D80, which is too big to be 
represented by a Long (which is typedef'd to __int32_t in 
newlib/libc/stdlib/mprec.h).  I think this explains the SIGFPE.

Presumably the authors of the code knew that aadj could be this big, 
because there's a test for aadj <= 0x7fffffff in line 1123.  So would 
the solution be to catch SIGFPE here and ignore it?

[I haven't tried to understand what aadj is being used for, so this 
suggestion might be complete nonsense.]

Ken



More information about the Newlib mailing list