From 4ebdb4ad04c955296fa23a78232af93608e7b24e Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sat, 20 Nov 2021 19:45:07 -0600 Subject: [PATCH] Add the header containing type-generic math macros. So far this only has macros for the newly-added functions, since the existing math functions in SysFloat do not have f- and l-suffixed versions. --- ORCACDefs/tgmath.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++ cc.notes | 2 ++ 2 files changed, 59 insertions(+) create mode 100644 ORCACDefs/tgmath.h diff --git a/ORCACDefs/tgmath.h b/ORCACDefs/tgmath.h new file mode 100644 index 0000000..5862d69 --- /dev/null +++ b/ORCACDefs/tgmath.h @@ -0,0 +1,57 @@ +/**************************************************************** +* +* tgmath.h - type-generic math macros +* +* November 2021 +* Stephen Heumann +* +****************************************************************/ + +#ifndef __tgmath__ +#define __tgmath__ + +#include + +/* + * Note: This header currently contains only some of the macros specified + * in the C99 and later standards. Others are not present because the + * corresponding functions either are not available at all or have only + * an unsuffixed version available. + */ + +#define __tg_real_x(fn,x) _Generic((x), \ + float: fn##f, \ + long double: fn##l, \ + default: fn)(x) + +#define __tg_real_x_other(fn,x,other) _Generic((x), \ + float: fn##f, \ + long double: fn##l, \ + default: fn)((x),(other)) + +#define __tg_real_x_y(fn,x,y) _Generic((x), \ + float: _Generic((y), float: fn##f, long double: fn##l, default: fn), \ + long double: fn##l, \ + default: _Generic((y), long double: fn##l, default: fn))((x),(y)) + +#define __tg_real_x_y_other(fn,x,y,other) _Generic((x), \ + float: _Generic((y), float: fn##f, long double: fn##l, default: fn), \ + long double: fn##l, \ + default: _Generic((y), long double: fn##l, default: fn))((x),(y),(other)) + +#define cbrt(x) __tg_real_x(cbrt,(x)) +#define copysign(x,y) __tg_real_x_y(copysign,(x),(y)) +#define exp2(x) __tg_real_x(exp2,(x)) +#define expm1(x) __tg_real_x(expm1,(x)) +#define ilogb(x) __tg_real_x(ilogb,(x)) +#define log1p(x) __tg_real_x(log1p,(x)) +#define log2(x) __tg_real_x(log2,(x)) +#define logb(x) __tg_real_x(logb,(x)) +#define lrint(x) __tg_real_x(lrint,(x)) +#define remainder(x,y) __tg_real_x_y(remainder,(x),(y)) +#define remquo(x,y,quo) __tg_real_x_y_other(remquo,(x),(y),(quo)) +#define rint(x) __tg_real_x(rint,(x)) +#define scalbn(x,n) __tg_real_x_other(scalbn,(x),(n)) +#define trunc(x) __tg_real_x(trunc,(x)) + +#endif diff --git a/cc.notes b/cc.notes index 43feeca..57299ca 100644 --- a/cc.notes +++ b/cc.notes @@ -617,6 +617,8 @@ ORCA/C now includes several new headers specified by recent C standards. 9. (C11) The header defines the types char16_t and char32_t suitable for holding UTF-16 and UTF-32 code units, and provides functions for handling Unicode characters. +10. (C99) The header contains type-generic macros that can invoke the float, double, or long double versions of certain math functions, as determined based on the types of the arguments passed to them. + Library Updates ---------------