[PATCH] libm/math: Use __math_xflow in obsolete math code

Keith Packard keithp@keithp.com
Mon Aug 3 18:07:40 GMT 2020


Szabolcs Nagy <szabolcs.nagy@arm.com> writes:

> note1: i used c99 code when i wrote the
> new math code and currently the old math
> code can be compiled with older compilers,
> this change might prevent that.

Hrm. I just learned about "#pragma STDC FENV_ACCESS on" this morning and
am wondering if we shouldn't just patch the old math library to use that
instead of calling the __math_xflow functions. Would be a simpler patch
and provide precise compatibility with the previous version.

Here's an example of how that works:

        #include <fenv.h>
        #include <stdio.h>

        #pragma STDC FENV_ACCESS on

        int main(void)
        {
                double x;
                int e;
                feclearexcept(FE_ALL_EXCEPT);
                x = 0.0 / 0.0;
                e = fetestexcept(FE_ALL_EXCEPT);
                printf("x %g e %x\n", x, e);
                return 0;
        }

$ cc except.c -lm
$ ./a.out
x -nan e 1
$

As you can see, even using constants still raise the appropriate
exception.

-- 
-keith
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20200803/04e8c8c5/attachment.sig>


More information about the Newlib mailing list