Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libm/ld/s_logbl.c')
-rw-r--r--newlib/libm/ld/s_logbl.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/newlib/libm/ld/s_logbl.c b/newlib/libm/ld/s_logbl.c
new file mode 100644
index 000000000..ee1a91fd8
--- /dev/null
+++ b/newlib/libm/ld/s_logbl.c
@@ -0,0 +1,54 @@
+/*
+ * From: @(#)s_ilogb.c 5.1 93/09/24
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <float.h>
+#include <limits.h>
+#include <math.h>
+
+#include "fpmath.h"
+
+long double
+logbl(long double x)
+{
+ union IEEEl2bits u;
+ unsigned long m;
+ int b;
+
+ u.e = x;
+ if (u.bits.exp == 0) {
+ if ((u.bits.manl | u.bits.manh) == 0) { /* x == 0 */
+ u.bits.sign = 1;
+ return (1.0L / u.e);
+ }
+ /* denormalized */
+ if (u.bits.manh == 0) {
+ m = 1lu << (LDBL_MANL_SIZE - 1);
+ for (b = LDBL_MANH_SIZE; !(u.bits.manl & m); m >>= 1)
+ b++;
+ } else {
+ m = 1lu << (LDBL_MANH_SIZE - 1);
+ for (b = 0; !(u.bits.manh & m); m >>= 1)
+ b++;
+ }
+#ifdef LDBL_IMPLICIT_NBIT
+ b++;
+#endif
+ return ((long double)(LDBL_MIN_EXP - b - 1));
+ }
+ if (u.bits.exp < (LDBL_MAX_EXP << 1) - 1) /* normal */
+ return ((long double)(u.bits.exp - LDBL_MAX_EXP + 1));
+ else /* +/- inf or nan */
+ return (x * x);
+}