[Cfp-interest] updated draft

Joel C. Salomon joelcsalomon at gmail.com
Thu Mar 15 10:51:10 PDT 2012


Joel C. Salomon wrote:
> I'd suggest something like (using the hidden
>    double (*__sin_arr[])(double) = {
>        [FE_DYNAMIC] = sin,
>        [FE_DOWNWARD] = __sin_down, …};
>    #define __sin __sin_arr[fegetround()]
>    #define sin __sin
> This can be wrapped in <tgmath.h>.

Correction, per phone conference:

For systems where 754's "static" modes are implemented via the
hardware's dynamic modes.  For real static modes, fegetround() should
be replaced with some magic that works at compile time.

// math.h
double (*__sin_arr[])(double) = {
    [FE_DYNAMIC] = sin,
    [FE_DOWNWARD] = __sin_down,
    …};
#define __sin __sin_arr[fegetround()]
#define sin(x) __sin(x)

float (*__sinf_arr[])(float) = {
    [FE_DYNAMIC] = sinf,
    [FE_DOWNWARD] = __sinf_down,
    …};
#define __sinf __sinf_arr[fegetround()]
#define sinf(x) __sinf(x)

// tgmath.h
#undef sin
// keep def'n of sinf

#define sin(x) _Generic((x), float: __sinf, default: __sin)(x)

This allows for macro suppression.

—Joel



More information about the Cfp-interest mailing list