From 1010f9a906d7db61eccbf782c2fbcd9c547acea9 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 2 Nov 2021 21:59:01 -0500 Subject: [PATCH] Add the FP comparison macros in (from C99). These rely on a new internal function that has been added to ORCALib. --- ORCACDefs/math.h | 8 ++++++++ cc.notes | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/ORCACDefs/math.h b/ORCACDefs/math.h index ea92fa8..faca23c 100644 --- a/ORCACDefs/math.h +++ b/ORCACDefs/math.h @@ -34,6 +34,7 @@ int __fpclassifyf(float); int __fpclassifyd(double); int __fpclassifyl(long double); int __signbit(long double); +int __fpcompare(long double, long double, short); #define fpclassify(x) _Generic((x), \ float: __fpclassifyf, \ @@ -46,6 +47,13 @@ int __signbit(long double); #define isnormal(x) (fpclassify(x) == FP_NORMAL) #define signbit(x) __signbit(x) +#define isgreater(x,y) __fpcompare((x),(y),0x40) +#define isgreaterequal(x,y) __fpcompare((x),(y),0x42) +#define isless(x,y) __fpcompare((x),(y),0x80) +#define islessequal(x,y) __fpcompare((x),(y),0x82) +#define islessgreater(x,y) __fpcompare((x),(y),0xC0) +#define isunordered(x,y) __fpcompare((x),(y),0x01) + #ifndef __KeepNamespacePure__ #define arctan(x) atan(x) #endif diff --git a/cc.notes b/cc.notes index 6836e08..9b6b605 100644 --- a/cc.notes +++ b/cc.notes @@ -845,6 +845,18 @@ void va_copy(va_list dest, va_list src); The va_copy macro makes a copy of the va_list src, which must have been initialized by a call to va_start in a function taking variable arguments (plus possibly some number of calls to va_arg). After a call to va_copy, dest can be used to access the variable arguments in the same way as src. A corresponding call to va_end(dest) must be made in the function that called va_copy. +18. (C99) Several new function-like macros for comparison of floating-point numbers have been added: + +#include +int isgreater(real-floating x, real-floating y); +int isgreaterequal(real-floating x, real-floating y); +int isless(real-floating x, real-floating y); +int islessequal(real-floating x, real-floating y); +int islessgreater(real-floating x, real-floating y); +int isunordered(real-floating x, real-floating y); + +These macros accept arguments of any real floating types, i.e. float, double, or long double. They return 1 if x and y have the indicated relationship, or 0 if they do not. These macros differ from the ordinary relational operators in that the macros will not raise the "invalid" floating-point exception if x and y are unordered because one or both is a quiet NaN. (In ORCA/C, they will raise the "invalid" exception for signaling NaNs.) + -- Compiler changes introduced in C 2.1.0 ----------------------------------- The Default .h File