summaryrefslogtreecommitdiff
path: root/lib/libc/arch
diff options
context:
space:
mode:
authorDale Rahn <drahn@cvs.openbsd.org>2004-02-03 16:45:36 +0000
committerDale Rahn <drahn@cvs.openbsd.org>2004-02-03 16:45:36 +0000
commit7ea697ce3364ef6afcfe5a7105a7e03ec134bd96 (patch)
treeefe26ffb28786b86df24b4b9185f3d752c3b0bfa /lib/libc/arch
parent934740f57ecef9b4b44eefbb42b120e94225eaa6 (diff)
Correct modf (from alpha) instead of one which doesnt compile from NetBSD
Diffstat (limited to 'lib/libc/arch')
-rw-r--r--lib/libc/arch/arm/gen/Makefile.inc4
-rw-r--r--lib/libc/arch/arm/gen/modf.c (renamed from lib/libc/arch/arm/gen/modf_ieee754.c)62
2 files changed, 37 insertions, 29 deletions
diff --git a/lib/libc/arch/arm/gen/Makefile.inc b/lib/libc/arch/arm/gen/Makefile.inc
index 6928132b5b1..562aed7bd86 100644
--- a/lib/libc/arch/arm/gen/Makefile.inc
+++ b/lib/libc/arch/arm/gen/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.5 2004/02/02 16:09:45 drahn Exp $
+# $OpenBSD: Makefile.inc,v 1.6 2004/02/03 16:45:35 drahn Exp $
# $NetBSD: Makefile.inc,v 1.6 2003/08/01 17:03:47 lukem Exp $
SRCS+= alloca.S byte_swap_2.S byte_swap_4.S divsi3.S \
@@ -11,6 +11,6 @@ SRCS+= sigsetjmp.S
SRCS+= isinf.c isnan.c
-SRCS+= modf_ieee754.c
+SRCS+= modf.c
SRCS+= ldexp.c
SRCS+= frexp.c
diff --git a/lib/libc/arch/arm/gen/modf_ieee754.c b/lib/libc/arch/arm/gen/modf.c
index deafdb4875e..3666d927841 100644
--- a/lib/libc/arch/arm/gen/modf_ieee754.c
+++ b/lib/libc/arch/arm/gen/modf.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: modf_ieee754.c,v 1.2 2004/02/01 05:40:52 drahn Exp $ */
-/* $NetBSD: modf_ieee754.c,v 1.1 2003/05/12 15:15:16 kleink Exp $ */
+/* $OpenBSD: modf.c,v 1.1 2004/02/03 16:45:35 drahn Exp $ */
+/* $NetBSD: modf.c,v 1.1 1995/02/10 17:50:25 cgd Exp $ */
/*
* Copyright (c) 1994, 1995 Carnegie-Mellon University.
@@ -28,6 +28,10 @@
* rights to redistribute these changes.
*/
+#if defined(LIBC_SCCS) && !defined(lint)
+static char *rcsid = "$OpenBSD: modf.c,v 1.1 2004/02/03 16:45:35 drahn Exp $";
+#endif /* LIBC_SCCS and not lint */
+
#include <sys/types.h>
#include <machine/ieee.h>
#include <errno.h>
@@ -41,38 +45,42 @@
* Beware signedness when doing subtraction, and also operand size!
*/
double
-modf(double val, double *iptr)
+modf(val, iptr)
+ double val, *iptr;
{
- union ieee_double_u u, v;
+ union doub {
+ double v;
+ struct ieee_double s;
+ } u, v;
u_int64_t frac;
/*
* If input is Inf or NaN, return it and leave i alone.
*/
- u.dblu_d = val;
- if (u.dblu_dbl.dbl_exp == DBL_EXP_INFNAN)
- return (u.dblu_d);
+ u.v = val;
+ if (u.s.dbl_exp == DBL_EXP_INFNAN)
+ return (u.v);
/*
* If input can't have a fractional part, return
* (appropriately signed) zero, and make i be the input.
*/
- if ((int)u.dblu_dbl.dbl_exp - DBL_EXP_BIAS > DBL_FRACBITS - 1) {
- *iptr = u.dblu_d;
- v.dblu_d = 0.0;
- v.dblu_dbl.dbl_sign = u.dblu_dbl.dbl_sign;
- return (v.dblu_d);
+ if ((int)u.s.dbl_exp - DBL_EXP_BIAS > DBL_FRACBITS - 1) {
+ *iptr = u.v;
+ v.v = 0.0;
+ v.s.dbl_sign = u.s.dbl_sign;
+ return (v.v);
}
/*
* If |input| < 1.0, return it, and set i to the appropriately
* signed zero.
*/
- if (u.dblu_dbl.dbl_exp < DBL_EXP_BIAS) {
- v.dblu_d = 0.0;
- v.dblu_dbl.dbl_sign = u.dblu_dbl.dbl_sign;
- *iptr = v.dblu_d;
- return (u.dblu_d);
+ if (u.s.dbl_exp < DBL_EXP_BIAS) {
+ v.v = 0.0;
+ v.s.dbl_sign = u.s.dbl_sign;
+ *iptr = v.v;
+ return (u.v);
}
/*
@@ -86,16 +94,16 @@ modf(double val, double *iptr)
* normalization. Therefore, we take the easy way out, and
* just use subtraction to get the fractional part.
*/
- v.dblu_d = u.dblu_d;
+ v.v = u.v;
/* Zero the low bits of the fraction, the sleazy way. */
- frac = ((u_int64_t)v.dblu_dbl.dbl_frach << 32) + v.dblu_dbl.dbl_fracl;
- frac >>= DBL_FRACBITS - (u.dblu_dbl.dbl_exp - DBL_EXP_BIAS);
- frac <<= DBL_FRACBITS - (u.dblu_dbl.dbl_exp - DBL_EXP_BIAS);
- v.dblu_dbl.dbl_fracl = frac & 0xffffffff;
- v.dblu_dbl.dbl_frach = frac >> 32;
- *iptr = v.dblu_d;
+ frac = ((u_int64_t)v.s.dbl_frach << 32) + v.s.dbl_fracl;
+ frac >>= DBL_FRACBITS - (u.s.dbl_exp - DBL_EXP_BIAS);
+ frac <<= DBL_FRACBITS - (u.s.dbl_exp - DBL_EXP_BIAS);
+ v.s.dbl_fracl = frac & 0xffffffff;
+ v.s.dbl_frach = frac >> 32;
+ *iptr = v.v;
- u.dblu_d -= v.dblu_d;
- u.dblu_dbl.dbl_sign = v.dblu_dbl.dbl_sign;
- return (u.dblu_d);
+ u.v -= v.v;
+ u.s.dbl_sign = v.s.dbl_sign;
+ return (u.v);
}