[Cfp-interest] type-generic cbrt for decimal

Jim Thomas jaswthomas at sbcglobal.net
Tue Dec 11 10:58:34 PST 2012


Regarding 

ISSUE 7: We intend to add an example showing how generic selection can be used to define cbrt for tgmath to handle decimal as well as generic FP types.

in Part 2, I'm wondering if providing the example is really desirable. 

An implementation that supports Parts 1 and 2 might implement the cbrt type-generic macro as:
#ifdef __STDC_WANT_IEC_00000_EXT2
					#define cbrt(X)  _Generic((X),                                               \
                                         _Decimal128: cbrtd128(X),              \
                                         _Decimal64: cbrtd64(X),              \
                                         _Decimal32: cbrtd32(X),              \
                                         long double: cbrtl(X),              \
                                         default: _Roundwise_cbrt(X),  \
                                         float: cbrtf(X)                           \
                                         )
#else
					#define cbrt(X)  _Generic((X),                                               \
                                         long double: cbrtl(X),              \
                                         default: _Roundwise_cbrt(X),  \
                                         float: cbrtf(X)                           \
                                         )
#endif
 
where _Roundwise_cbrt() is equivalent to cbrt() invoked without macro-replacement suppression.

However, implementing a 2 or 3 argument function using _Generic, which is already prohibitively cumbersome with just C11, would become even worse with decimal types. It's difficult to imagine an implementation would do it, even without decimal types.

If the example is just for programmers writing type-generic macros for their own 1-argument functions, then this straightforward example isn't really needed.

Your thoughts?

-Jim


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20121211/9302d659/attachment-0001.html 


More information about the Cfp-interest mailing list