diff options
Diffstat (limited to 'src/math/log2.c')
| -rw-r--r-- | src/math/log2.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/math/log2.c b/src/math/log2.c index c438d7ce..55569065 100644 --- a/src/math/log2.c +++ b/src/math/log2.c @@ -1,9 +1,25 @@ #define TGSOURCE "log2.c" #include "_tgmath.h" #include <math.h> +#include "fenv.h" TYPE TGFN(log2)(TYPE x) { + switch (fpclassify(x)) { + case FP_ZERO: feraiseexcept(FE_DIVBYZERO); return - INFINITY; + case FP_INFINITE: if (!signbit(x)) { return x; } break; + default: break; + } + + if (x == 1.0) { + return 0.0; + } + + if (x < 0.0) { + feraiseexcept(FE_INVALID); + return NAN; + } + return x; } |
