summaryrefslogtreecommitdiff
path: root/lib/libc/arch/mips
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/arch/mips')
-rw-r--r--lib/libc/arch/mips/gen/frexp.c49
1 files changed, 27 insertions, 22 deletions
diff --git a/lib/libc/arch/mips/gen/frexp.c b/lib/libc/arch/mips/gen/frexp.c
index 181e1dc735d..21b0cb426a5 100644
--- a/lib/libc/arch/mips/gen/frexp.c
+++ b/lib/libc/arch/mips/gen/frexp.c
@@ -1,7 +1,13 @@
-/*-
- * Copyright (c) 1991, 1993
+/* $OpenBSD: frexp.c,v 1.4 2001/09/10 22:37:06 millert Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -32,13 +38,17 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: frexp.c,v 1.3 1997/07/23 20:55:24 kstailey Exp $";
+static char rcsid[] = "$OpenBSD: frexp.c,v 1.4 2001/09/10 22:37:06 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
-#include <machine/endian.h>
-#include <math.h>
+#include <machine/ieee.h>
+/*
+ * Split the given value into a fraction in the range [0.5, 1.0) and
+ * an exponent, such that frac * (2^exp) == value. If value is 0,
+ * return 0.
+ */
double
frexp(value, eptr)
double value;
@@ -46,28 +56,23 @@ frexp(value, eptr)
{
union {
double v;
- struct {
-#if BYTE_ORDER == LITTLE_ENDIAN
- u_int u_mant2 : 32;
- u_int u_mant1 : 20;
- u_int u_exp : 11;
- u_int u_sign : 1;
-#else
- u_int u_sign : 1;
- u_int u_exp : 11;
- u_int u_mant1 : 20;
- u_int u_mant2 : 32;
-#endif
- } s;
+ struct ieee_double s;
} u;
if (value) {
+ /*
+ * Fractions in [0.5..1.0) have an exponent of 2^-1.
+ * Leave Inf and NaN alone, however.
+ * WHAT ABOUT DENORMS?
+ */
u.v = value;
- *eptr = u.s.u_exp - 1022;
- u.s.u_exp = 1022;
- return(u.v);
+ if (u.s.dbl_exp != DBL_EXP_INFNAN) {
+ *eptr = u.s.dbl_exp - (DBL_EXP_BIAS - 1);
+ u.s.dbl_exp = DBL_EXP_BIAS - 1;
+ }
+ return (u.v);
} else {
*eptr = 0;
- return((double)0);
+ return ((double)0);
}
}