summaryrefslogtreecommitdiff
path: root/src/math/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/log.c')
-rw-r--r--src/math/log.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/math/log.c b/src/math/log.c
index ee809cf5..abc29e4e 100644
--- a/src/math/log.c
+++ b/src/math/log.c
@@ -2,11 +2,24 @@
#include <math.h>
#include "_tgmath.h"
#include "errno.h"
+#include "fenv.h"
/** natural logarithm **/
TYPE TGFN(log)(TYPE x)
{
+ switch (fpclassify(x)) {
+ case FP_ZERO: feraiseexcept(FE_DIVBYZERO); return - INFINITY;
+ case FP_INFINITE: if (!signbit(x)) { return x; }
+ default: break;
+ }
+
+ if (x == 1.0) {
+ return 0.0;
+ }
+
if (x < 0) {
+ feraiseexcept(FE_INVALID);
+ return NAN;
errno = EDOM; /* ARGUMENT(x) is negative */
return TGHUGE;
}