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:
authorChristopher Faylor <me@cgf.cx>2000-02-17 22:39:52 +0300
committerChristopher Faylor <me@cgf.cx>2000-02-17 22:39:52 +0300
commit8a0efa53e44919bcf5ccb1d3353618a82afdf8bc (patch)
tree68c3dbf3f2c6fd5d49777def9914d77b5cd4589d /newlib/libm/mathfp/sf_ldexp.c
parent1fd5e000ace55b323124c7e556a7a864b972a5c4 (diff)
import newlib-2000-02-17 snapshot
Diffstat (limited to 'newlib/libm/mathfp/sf_ldexp.c')
-rw-r--r--newlib/libm/mathfp/sf_ldexp.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/newlib/libm/mathfp/sf_ldexp.c b/newlib/libm/mathfp/sf_ldexp.c
new file mode 100644
index 000000000..6b6c2c00b
--- /dev/null
+++ b/newlib/libm/mathfp/sf_ldexp.c
@@ -0,0 +1,81 @@
+
+/* @(#)z_ldexpf.c 1.0 98/08/13 */
+/******************************************************************
+ * ldexp
+ *
+ * Input:
+ * d - a floating point value
+ * e - an exponent value
+ *
+ * Output:
+ * A floating point value f such that f = d * 2 ^ e.
+ *
+ * Description:
+ * This function creates a floating point number f such that
+ * f = d * 2 ^ e.
+ *
+ *****************************************************************/
+
+#include <float.h>
+#include "fdlibm.h"
+#include "zmath.h"
+
+#define FLOAT_EXP_OFFS 127
+
+float
+_DEFUN (ldexpf, (float, int),
+ float d _AND
+ int e)
+{
+ int exp;
+ __int32_t wd;
+
+ GET_FLOAT_WORD (wd, d);
+
+ /* Check for special values and then scale d by e. */
+ switch (numtestf (wd))
+ {
+ case NAN:
+ errno = EDOM;
+ break;
+
+ case INF:
+ errno = ERANGE;
+ break;
+
+ case 0:
+ break;
+
+ default:
+ exp = (wd & 0x7f800000) >> 23;
+ exp += e;
+
+ if (exp > FLT_MAX_EXP + FLOAT_EXP_OFFS)
+ {
+ errno = ERANGE;
+ d = z_infinity_f.f;
+ }
+ else if (exp < FLT_MIN_EXP + FLOAT_EXP_OFFS)
+ {
+ errno = ERANGE;
+ d = -z_infinity_f.f;
+ }
+ else
+ {
+ wd &= 0x807fffff;
+ wd |= exp << 23;
+ SET_FLOAT_WORD (d, wd);
+ }
+ }
+
+ return (d);
+}
+
+#ifdef _DOUBLE_IS_32BITS
+
+double ldexp (double x, int e)
+{
+ return (double) ldexpf ((float) x, e);
+}
+
+#endif /* defined(_DOUBLE_IS_32BITS) */