[Cfp-interest] implementing tgmath for constant rounding modes

Jim Thomas jaswthomas at sbcglobal.net
Sat Jun 2 08:22:55 PDT 2012


At our last teleconference, Fred asked about how <tgmath.h> could be written to work correctly with the pragma that switch between constant and dynamic rounding modes. 

<tgmath.h> aside, the math functions that can be affected by constant rounding modes must be sensitive to whether a constant rounding mode is in effect. Take the example of cbrt. <math.h> could have

#define cbrt(x) __roundwise_cbrt(x)

Then the translator would have to keep track of whether a constant rounding mode is in effect at each call site for __roundwise_cbrt and, if so, what the rounding direction is. Compilers already keep track of the state of other FP pragmas, which have the same sort of scoping as the constant rounding mode pragmas.

The <tgmath.h> situation isn't worse, say

>     #include <math.h>

>    #define cbrt(X) _Generic((X),                   \
>                                  long double: cbrtl(X),     \
>                                  default: __roundwise_cbrt(X),          \
>                                  float: cbrtf(X)


The float and long double cases will get the __roundwise_ prefix if the <math.h> macro replacement hasn't been disabled.

-JIm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20120602/920e77a0/attachment.html 


More information about the Cfp-interest mailing list