summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2001-09-10 22:37:07 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2001-09-10 22:37:07 +0000
commitf8a2c86989b396f318a87ce7f6c1d95b3c911d42 (patch)
treec27e504d9a498690ad7b4370e07a1c4fa4dc0e9d /lib
parent539d2fe1b065038867a3a79db8cb2c3267d79cd0 (diff)
Use the LBL frexp() on all platforms with ieee floating point.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/arch/alpha/gen/frexp.c80
-rw-r--r--lib/libc/arch/i386/gen/frexp.c43
-rw-r--r--lib/libc/arch/m68k/gen/frexp.c43
-rw-r--r--lib/libc/arch/m88k/gen/frexp.c7
-rw-r--r--lib/libc/arch/mips/gen/frexp.c49
-rw-r--r--lib/libc/arch/powerpc/gen/frexp.c43
-rw-r--r--lib/libc/arch/sparc/gen/frexp.c4
-rw-r--r--lib/libc/arch/sparc64/gen/frexp.c7
8 files changed, 172 insertions, 104 deletions
diff --git a/lib/libc/arch/alpha/gen/frexp.c b/lib/libc/arch/alpha/gen/frexp.c
index bf7eeace05b..16665ab5003 100644
--- a/lib/libc/arch/alpha/gen/frexp.c
+++ b/lib/libc/arch/alpha/gen/frexp.c
@@ -1,58 +1,78 @@
-/* $OpenBSD: frexp.c,v 1.4 1997/07/23 20:55:17 kstailey Exp $ */
-/* $NetBSD: frexp.c,v 1.1 1995/02/10 17:50:22 cgd Exp $ */
+/* $OpenBSD: frexp.c,v 1.5 2001/09/10 22:37:06 millert Exp $ */
/*
- * Copyright (c) 1994, 1995 Carnegie-Mellon University.
- * All rights reserved.
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
*
- * Author: Chris G. Demetriou
- *
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
*
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
*
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: frexp.c,v 1.4 1997/07/23 20:55:17 kstailey Exp $";
+static char rcsid[] = "$OpenBSD: frexp.c,v 1.5 2001/09/10 22:37:06 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <machine/ieee.h>
-#include <math.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;
int *eptr;
{
- union doub {
+ union {
double v;
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.dbl_exp - (DBL_EXP_BIAS - 1);
- u.s.dbl_exp = DBL_EXP_BIAS - 1;
- 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);
}
}
diff --git a/lib/libc/arch/i386/gen/frexp.c b/lib/libc/arch/i386/gen/frexp.c
index 4da4eac1f31..21b0cb426a5 100644
--- a/lib/libc/arch/i386/gen/frexp.c
+++ b/lib/libc/arch/i386/gen/frexp.c
@@ -1,6 +1,12 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
+/* $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
@@ -32,12 +38,17 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: frexp.c,v 1.3 1997/07/23 20:55:20 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 <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;
@@ -45,21 +56,23 @@ frexp(value, eptr)
{
union {
double v;
- struct {
- u_int u_mant2 : 32;
- u_int u_mant1 : 20;
- u_int u_exp : 11;
- u_int u_sign : 1;
- } 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);
}
}
diff --git a/lib/libc/arch/m68k/gen/frexp.c b/lib/libc/arch/m68k/gen/frexp.c
index 0fef1f5b73e..21b0cb426a5 100644
--- a/lib/libc/arch/m68k/gen/frexp.c
+++ b/lib/libc/arch/m68k/gen/frexp.c
@@ -1,6 +1,12 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
+/* $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
@@ -32,12 +38,17 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: frexp.c,v 1.3 1997/07/23 20:55:23 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 <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;
@@ -45,21 +56,23 @@ frexp(value, eptr)
{
union {
double v;
- struct {
- u_int u_sign : 1;
- u_int u_exp : 11;
- u_int u_mant1 : 20;
- u_int u_mant2 : 32;
- } 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);
}
}
diff --git a/lib/libc/arch/m88k/gen/frexp.c b/lib/libc/arch/m88k/gen/frexp.c
index e68405b442b..319f7262472 100644
--- a/lib/libc/arch/m88k/gen/frexp.c
+++ b/lib/libc/arch/m88k/gen/frexp.c
@@ -1,4 +1,5 @@
-/* * $OpenBSD: frexp.c,v 1.2 2000/03/01 17:31:20 todd Exp $*/
+/* $OpenBSD: frexp.c,v 1.3 2001/09/10 22:37:06 millert Exp $ */
+
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -34,12 +35,10 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * from: Header: frexp.c,v 1.1 91/07/07 04:45:01 torek Exp
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)frexp.c 8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$OpenBSD: frexp.c,v 1.3 2001/09/10 22:37:06 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
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);
}
}
diff --git a/lib/libc/arch/powerpc/gen/frexp.c b/lib/libc/arch/powerpc/gen/frexp.c
index 2297cf7dbb2..bfb3c684b7d 100644
--- a/lib/libc/arch/powerpc/gen/frexp.c
+++ b/lib/libc/arch/powerpc/gen/frexp.c
@@ -1,6 +1,12 @@
-/*-
- * Copyright (c) 1991 The Regents of the University of California.
- * All rights reserved.
+/* $OpenBSD: frexp.c,v 1.3 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
@@ -32,12 +38,17 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: frexp.c,v 1.2 1997/07/23 20:55:27 kstailey Exp $";
+static char rcsid[] = "$OpenBSD: frexp.c,v 1.3 2001/09/10 22:37:06 millert Exp $;
#endif /* LIBC_SCCS and not lint */
#include <sys/types.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;
@@ -45,21 +56,23 @@ frexp(value, eptr)
{
union {
double v;
- struct {
- u_int u_sign : 1;
- u_int u_exp : 11;
- u_int u_mant1 : 20;
- u_int u_mant2 : 32;
- } 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);
}
}
diff --git a/lib/libc/arch/sparc/gen/frexp.c b/lib/libc/arch/sparc/gen/frexp.c
index 2dcc0300fc9..21b0cb426a5 100644
--- a/lib/libc/arch/sparc/gen/frexp.c
+++ b/lib/libc/arch/sparc/gen/frexp.c
@@ -1,3 +1,5 @@
+/* $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.
@@ -36,7 +38,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: frexp.c,v 1.3 1997/07/23 20:55:30 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>
diff --git a/lib/libc/arch/sparc64/gen/frexp.c b/lib/libc/arch/sparc64/gen/frexp.c
index adf8aecd74e..f900a915536 100644
--- a/lib/libc/arch/sparc64/gen/frexp.c
+++ b/lib/libc/arch/sparc64/gen/frexp.c
@@ -1,4 +1,5 @@
-/* $OpenBSD: frexp.c,v 1.1 2001/08/29 01:41:29 art Exp $ */
+/* $OpenBSD: frexp.c,v 1.2 2001/09/10 22:37:06 millert Exp $ */
+
/*
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
@@ -36,7 +37,9 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+static char rcsid[] = "$OpenBSD: frexp.c,v 1.2 2001/09/10 22:37:06 millert Exp $";
+#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <machine/ieee.h>