Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Initial version of fmodl from FreeBSD.
details: https://anonhg.NetBSD.org/src/rev/f1062c5a5f01
branches: trunk
changeset: 791305:f1062c5a5f01
user: joerg <joerg%NetBSD.org@localhost>
date: Tue Nov 12 16:48:39 2013 +0000
description:
Initial version of fmodl from FreeBSD.
Basic test case for the fmod family.
diffstat:
distrib/sets/lists/comp/mi | 5 +-
distrib/sets/lists/debug/mi | 3 +-
distrib/sets/lists/tests/mi | 3 +-
lib/libm/Makefile | 13 ++-
lib/libm/man/fmod.3 | 14 ++-
lib/libm/src/e_fmodl.c | 157 ++++++++++++++++++++++++++++++++++++++++++++
lib/libm/src/math_private.h | 5 +-
lib/libm/src/namespace.h | 3 +-
lib/libm/src/w_fmod.c | 6 +-
lib/libm/src/w_fmodl.c | 42 +++++++++++
tests/lib/libm/Makefile | 3 +-
tests/lib/libm/t_fmod.c | 63 +++++++++++++++++
12 files changed, 300 insertions(+), 17 deletions(-)
diffs (truncated from 502 to 300 lines):
diff -r 04c498ebfe6f -r f1062c5a5f01 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi Tue Nov 12 16:39:39 2013 +0000
+++ b/distrib/sets/lists/comp/mi Tue Nov 12 16:48:39 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1856 2013/11/12 16:39:39 joerg Exp $
+# $NetBSD: mi,v 1.1857 2013/11/12 16:48:39 joerg Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -6282,6 +6282,7 @@
./usr/share/man/cat3/fminl.0 comp-c-catman .cat
./usr/share/man/cat3/fmod.0 comp-c-catman .cat
./usr/share/man/cat3/fmodf.0 comp-c-catman .cat
+./usr/share/man/cat3/fmodl.0 comp-c-catman .cat
./usr/share/man/cat3/fmtcheck.0 comp-c-catman .cat
./usr/share/man/cat3/fmtmsg.0 comp-c-catman .cat
./usr/share/man/cat3/fnmatch.0 comp-c-catman .cat
@@ -12838,6 +12839,7 @@
./usr/share/man/html3/fminl.html comp-c-htmlman html
./usr/share/man/html3/fmod.html comp-c-htmlman html
./usr/share/man/html3/fmodf.html comp-c-htmlman html
+./usr/share/man/html3/fmodl.html comp-c-htmlman html
./usr/share/man/html3/fmtcheck.html comp-c-htmlman html
./usr/share/man/html3/fmtmsg.html comp-c-htmlman html
./usr/share/man/html3/fnmatch.html comp-c-htmlman html
@@ -19308,6 +19310,7 @@
./usr/share/man/man3/fminl.3 comp-c-man .man
./usr/share/man/man3/fmod.3 comp-c-man .man
./usr/share/man/man3/fmodf.3 comp-c-man .man
+./usr/share/man/man3/fmodl.3 comp-c-man .man
./usr/share/man/man3/fmtcheck.3 comp-c-man .man
./usr/share/man/man3/fmtmsg.3 comp-c-man .man
./usr/share/man/man3/fnmatch.3 comp-c-man .man
diff -r 04c498ebfe6f -r f1062c5a5f01 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi Tue Nov 12 16:39:39 2013 +0000
+++ b/distrib/sets/lists/debug/mi Tue Nov 12 16:48:39 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.39 2013/11/11 11:10:45 joerg Exp $
+# $NetBSD: mi,v 1.40 2013/11/12 16:48:39 joerg Exp $
./etc/mtree/set.debug comp-sys-root
./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib
@@ -1975,6 +1975,7 @@
./usr/libdata/debug/usr/tests/lib/libm/t_erf.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libm/t_exp.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libm/t_floor.debug tests-obsolete obsolete
+./usr/libdata/debug/usr/tests/lib/libm/t_fmod.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libm/t_infinity.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libm/t_ldexp.debug tests-lib-debug debug,atf
./usr/libdata/debug/usr/tests/lib/libm/t_libm.debug tests-obsolete obsolete
diff -r 04c498ebfe6f -r f1062c5a5f01 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Tue Nov 12 16:39:39 2013 +0000
+++ b/distrib/sets/lists/tests/mi Tue Nov 12 16:48:39 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.549 2013/11/12 12:22:33 kefren Exp $
+# $NetBSD: mi,v 1.550 2013/11/12 16:48:39 joerg Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -2353,6 +2353,7 @@
./usr/tests/lib/libm/t_erf tests-lib-tests atf
./usr/tests/lib/libm/t_exp tests-lib-tests atf
./usr/tests/lib/libm/t_floor tests-obsolete obsolete
+./usr/tests/lib/libm/t_fmod tests-lib-tests atf
./usr/tests/lib/libm/t_infinity tests-lib-tests atf
./usr/tests/lib/libm/t_ldexp tests-lib-tests atf
./usr/tests/lib/libm/t_libm tests-obsolete obsolete
diff -r 04c498ebfe6f -r f1062c5a5f01 lib/libm/Makefile
--- a/lib/libm/Makefile Tue Nov 12 16:39:39 2013 +0000
+++ b/lib/libm/Makefile Tue Nov 12 16:48:39 2013 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.145 2013/11/12 00:10:29 joerg Exp $
+# $NetBSD: Makefile,v 1.146 2013/11/12 16:48:39 joerg Exp $
#
# @(#)Makefile 5.1beta 93/09/24
#
@@ -151,7 +151,8 @@
COMMON_SRCS+= b_exp.c b_log.c b_tgamma.c \
e_acos.c e_acosf.c e_acosh.c e_acoshf.c e_asin.c e_asinf.c \
e_atan2.c e_atan2f.c e_atanh.c e_atanhf.c e_cosh.c e_coshf.c e_exp.c \
- e_expf.c e_fmod.c e_fmodf.c e_hypot.c e_hypotf.c e_j0.c e_j0f.c \
+ e_expf.c e_fmod.c e_fmodf.c e_fmodl.c e_hypot.c e_hypotf.c \
+ e_j0.c e_j0f.c \
e_j1.c e_j1f.c e_jn.c e_jnf.c e_lgamma_r.c e_lgammaf_r.c e_log.c \
e_log2.c e_log10.c e_log10f.c e_log2f.c e_logf.c e_pow.c e_powf.c \
e_rem_pio2.c e_rem_pio2f.c e_remainder.c e_remainderf.c e_scalb.c \
@@ -174,8 +175,9 @@
s_sinf.c s_tan.c s_tanf.c s_tanh.c s_tanhf.c s_tgammaf.c s_trunc.c s_truncf.c \
w_acos.c w_acosf.c w_acosh.c w_acoshf.c w_asin.c w_asinf.c w_atan2.c \
w_atan2f.c w_atanh.c w_atanhf.c w_cosh.c w_coshf.c \
- w_drem.c w_dremf.c w_exp.c w_expf.c w_fmod.c w_fmodf.c w_gamma.c \
- w_gamma_r.c w_gammaf.c w_gammaf_r.c w_hypot.c w_hypotf.c w_j0.c \
+ w_drem.c w_dremf.c w_exp.c w_expf.c w_fmod.c w_fmodf.c w_fmodl.c \
+ w_gamma.c w_gamma_r.c w_gammaf.c w_gammaf_r.c w_hypot.c w_hypotf.c \
+ w_j0.c \
w_j0f.c w_j1.c w_j1f.c w_jn.c w_jnf.c w_lgamma.c w_lgamma_r.c \
w_lgammaf.c w_lgammaf_r.c w_log.c w_log10.c w_log10f.c w_log2.c \
w_log2f.c w_logf.c \
@@ -284,7 +286,8 @@
MLINKS+=pow.3 powf.3
MLINKS+=fabs.3 fabsf.3
MLINKS+=finite.3 finitef.3
-MLINKS+=fmod.3 fmodf.3
+MLINKS+=fmod.3 fmodf.3 \
+ fmod.3 fmodl.3
MLINKS+=hypot.3 hypotf.3
MLINKS+=ieee_test.3 logb.3 ieee_test.3 logbf.3 ieee_test.3 logbl.3
MLINKS+=ieee_test.3 scalb.3 ieee_test.3 scalbf.3
diff -r 04c498ebfe6f -r f1062c5a5f01 lib/libm/man/fmod.3
--- a/lib/libm/man/fmod.3 Tue Nov 12 16:39:39 2013 +0000
+++ b/lib/libm/man/fmod.3 Tue Nov 12 16:48:39 2013 +0000
@@ -26,14 +26,15 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)fmod.3 5.1 (Berkeley) 5/2/91
-.\" $NetBSD: fmod.3,v 1.11 2003/08/07 16:44:47 agc Exp $
+.\" $NetBSD: fmod.3,v 1.12 2013/11/12 16:48:39 joerg Exp $
.\"
-.Dd May 2, 1991
+.Dd November 12, 2013
.Dt FMOD 3
.Os
.Sh NAME
.Nm fmod ,
-.Nm fmodf
+.Nm fmodf ,
+.Nm fmodl
.Nd floating-point remainder function
.Sh LIBRARY
.Lb libm
@@ -43,6 +44,8 @@
.Fn fmod "double x" "double y"
.Ft float
.Fn fmodf "float x" "float y"
+.Ft long double
+.Fn fmodl "long double x" "long double y"
.Sh DESCRIPTION
The
.Fn fmod
@@ -50,9 +53,10 @@
.Fa x Ns / Fa y .
.Sh RETURN VALUES
The
-.Fn fmod
+.Fn fmod ,
+.Fn fmodf ,
and
-.Fn fmodf
+.Fn fmodl
functions return the value
.Sm off
.Fa x - Em i * Fa y ,
diff -r 04c498ebfe6f -r f1062c5a5f01 lib/libm/src/e_fmodl.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libm/src/e_fmodl.c Tue Nov 12 16:48:39 2013 +0000
@@ -0,0 +1,157 @@
+/* @(#)e_fmod.c 1.3 95/01/18 */
+/*-
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, 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>
+__RCSID("$NetBSD: e_fmodl.c,v 1.1 2013/11/12 16:48:39 joerg Exp $");
+#if 0
+__FBSDID("$FreeBSD: head/lib/msun/src/e_fmodl.c 181063 2008-07-31 20:09:47Z das $");
+#endif
+
+#include "namespace.h"
+
+#include <float.h>
+#include <stdint.h>
+
+#include "math.h"
+#include "math_private.h"
+#include <machine/ieee.h>
+
+#ifdef __HAVE_LONG_DOUBLE
+
+#define BIAS (LDBL_MAX_EXP - 1)
+
+#if EXT_FRACLBITS > 32
+typedef uint64_t manl_t;
+#else
+typedef uint32_t manl_t;
+#endif
+
+#if EXT_FRACHBITS > 32
+typedef uint64_t manh_t;
+#else
+typedef uint32_t manh_t;
+#endif
+
+/*
+ * These macros add and remove an explicit integer bit in front of the
+ * fractional mantissa, if the architecture doesn't have such a bit by
+ * default already.
+ */
+#ifdef LDBL_IMPLICIT_NBIT
+#define SET_NBIT(hx) ((hx) | (1ULL << EXT_FRACHBITS))
+#define HFRAC_BITS EXT_FRACHBITS
+#else
+#define SET_NBIT(hx) (hx)
+#define HFRAC_BITS (EXT_FRACHBITS - 1)
+#endif
+
+#define MANL_SHIFT (EXT_FRACLBITS - 1)
+
+static const long double one = 1.0, Zero[] = {0.0, -0.0,};
+
+/*
+ * fmodl(x,y)
+ * Return x mod y in exact arithmetic
+ * Method: shift and subtract
+ *
+ * Assumptions:
+ * - The low part of the mantissa fits in a manl_t exactly.
+ * - The high part of the mantissa fits in an int64_t with enough room
+ * for an explicit integer bit in front of the fractional bits.
+ */
+long double
+__ieee754_fmodl(long double x, long double y)
+{
+ union ieee_ext_u ux = { .extu_ld = x, };
+ union ieee_ext_u uy = { .extu_ld = y, };
+ int64_t hx,hz; /* We need a carry bit even if EXT_FRACHBITS is 32. */
+ manh_t hy;
+ manl_t lx,ly,lz;
+ int ix,iy,n,sx;
+
+ sx = ux.extu_sign;
+
+ /* purge off exception values */
+ if((uy.extu_exp|uy.extu_frach|uy.extu_fracl)==0 || /* y=0 */
+ (ux.extu_exp == BIAS + LDBL_MAX_EXP) || /* or x not finite */
+ (uy.extu_exp == BIAS + LDBL_MAX_EXP &&
+ ((uy.extu_frach&~LDBL_NBIT)|uy.extu_fracl)!=0)) /* or y is NaN */
+ return (x*y)/(x*y);
+ if(ux.extu_exp<=uy.extu_exp) {
+ if((ux.extu_exp<uy.extu_exp) ||
+ (ux.extu_frach<=uy.extu_frach &&
+ (ux.extu_frach<uy.extu_frach ||
+ ux.extu_fracl<uy.extu_fracl))) {
+ return x; /* |x|<|y| return x or x-y */
+ }
+ if(ux.extu_frach==uy.extu_frach && ux.extu_fracl==uy.extu_fracl) {
+ return Zero[sx]; /* |x|=|y| return x*0*/
+ }
+ }
+
+ /* determine ix = ilogb(x) */
+ if(ux.extu_exp == 0) { /* subnormal x */
+ ux.extu_ld *= 0x1.0p512;
+ ix = ux.extu_exp - (BIAS + 512);
+ } else {
+ ix = ux.extu_exp - BIAS;
+ }
+
+ /* determine iy = ilogb(y) */
+ if(uy.extu_exp == 0) { /* subnormal y */
+ uy.extu_ld *= 0x1.0p512;
+ iy = uy.extu_exp - (BIAS + 512);
+ } else {
+ iy = uy.extu_exp - BIAS;
+ }
+
+ /* set up {hx,lx}, {hy,ly} and align y to x */
+ hx = SET_NBIT(ux.extu_frach);
+ hy = SET_NBIT(uy.extu_frach);
+ lx = ux.extu_fracl;
+ ly = uy.extu_fracl;
+
+ /* fix point fmod */
+ n = ix - iy;
+
+ while(n--) {
+ hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
+ if(hz<0){hx = hx+hx+(lx>>MANL_SHIFT); lx = lx+lx;}
+ else {
+ if ((hz|lz)==0) /* return sign(x)*0 */
+ return Zero[sx];
+ hx = hz+hz+(lz>>MANL_SHIFT); lx = lz+lz;
+ }
+ }
+ hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
+ if(hz>=0) {hx=hz;lx=lz;}
+
+ /* convert back to floating value and restore the sign */
+ if((hx|lx)==0) /* return sign(x)*0 */
+ return Zero[sx];
+ while(hx<(1LL<<HFRAC_BITS)) { /* normalize x */
+ hx = hx+hx+(lx>>MANL_SHIFT); lx = lx+lx;
+ iy -= 1;
+ }
Home |
Main Index |
Thread Index |
Old Index