<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><font class="Apple-style-span" size="4"><font face="sans-serif">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. </font></font><div><font class="Apple-style-span" size="4"><font face="sans-serif"><br></font></font></div><div><font class="Apple-style-span" size="4"><font face="sans-serif"><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</font></font><div><font class="Apple-style-span" face="sans-serif" size="4"><br></font></div><div><font class="Apple-style-span" face="sans-serif" size="4">#define cbrt(x) __roundwise_cbrt(x)</font></div><div><font class="Apple-style-span" face="sans-serif" size="4"><br></font></div><div><font class="Apple-style-span" face="sans-serif" size="4">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.</font></div><div><font class="Apple-style-span" face="sans-serif" size="4"><br></font></div><div><font class="Apple-style-span" face="sans-serif" size="4">The <tgmath.h> situation isn't worse, say</font></div><div><font class="Apple-style-span" face="sans-serif" size="4"><br></font></div><div><font class="Apple-style-span" face="sans-serif" size="4"><blockquote type="cite" style="font-family: Helvetica; font-size: medium; "> #include <math.h></blockquote><br><blockquote type="cite" style="font-family: Helvetica; font-size: medium; "> #define cbrt(X) _Generic((X), \<br></blockquote><blockquote type="cite" style="font-family: Helvetica; font-size: medium; "> long double: cbrtl(X), \<br></blockquote><blockquote type="cite" style="font-family: Helvetica; font-size: medium; "> default: __roundwise_cbrt(X), \<br></blockquote><blockquote type="cite" style="font-family: Helvetica; font-size: medium; "> float: cbrtf(X)<br></blockquote><div><br></div></font><div><font class="Apple-style-span" size="4"><font face="sans-serif"><br></font></font></div><div><font class="Apple-style-span" face="sans-serif" size="4">The float and long double cases will get the __roundwise_ prefix if the <math.h> macro replacement hasn't been disabled.</font></div></div></div><div><font class="Apple-style-span" face="sans-serif" size="4"><br></font></div><div><font class="Apple-style-span" face="sans-serif" size="4">-JIm</font></div></body></html>