Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add initial version of ceill, floorl and roundl from FreeBSD.



details:   https://anonhg.NetBSD.org/src/rev/2867c6fa317b
branches:  trunk
changeset: 791288:2867c6fa317b
user:      joerg <joerg%NetBSD.org@localhost>
date:      Mon Nov 11 23:57:34 2013 +0000

description:
Add initial version of ceill, floorl and roundl from FreeBSD.

diffstat:

 lib/libm/Makefile        |   13 +-
 lib/libm/src/namespace.h |    6 +-
 lib/libm/src/s_ceil.c    |    7 +-
 lib/libm/src/s_ceill.c   |  112 +++++++++++++++++++++++
 lib/libm/src/s_floor.c   |    7 +-
 lib/libm/src/s_floorl.c  |  112 +++++++++++++++++++++++
 lib/libm/src/s_round.c   |    7 +-
 lib/libm/src/s_roundl.c  |   63 +++++++++++++
 lib/libm/src/s_truncl.c  |   22 ++-
 tests/lib/libm/t_ceil.c  |  220 ++++++++++++++++++++++++++++++++++++++++++++++-
 tests/lib/libm/t_round.c |    9 +-
 11 files changed, 557 insertions(+), 21 deletions(-)

diffs (truncated from 802 to 300 lines):

diff -r c5fbeaa0f9ea -r 2867c6fa317b lib/libm/Makefile
--- a/lib/libm/Makefile Mon Nov 11 23:51:36 2013 +0000
+++ b/lib/libm/Makefile Mon Nov 11 23:57:34 2013 +0000
@@ -1,4 +1,4 @@
-#  $NetBSD: Makefile,v 1.143 2013/10/15 23:59:36 joerg Exp $
+#  $NetBSD: Makefile,v 1.144 2013/11/11 23:57:34 joerg Exp $
 #
 #  @(#)Makefile 5.1beta 93/09/24
 #
@@ -158,15 +158,18 @@
        e_scalbf.c e_sinh.c e_sinhf.c e_sqrt.c e_sqrtf.c \
        k_cos.c k_cosf.c k_rem_pio2.c k_rem_pio2f.c k_sin.c k_sinf.c \
        k_standard.c k_tan.c k_tanf.c \
-       s_asinh.c s_asinhf.c s_atan.c s_atanf.c s_cbrt.c s_cbrtf.c s_ceil.c \
-       s_ceilf.c s_copysign.c s_copysignf.c s_copysignl.c s_cos.c s_cosf.c s_erf.c \
+       s_asinh.c s_asinhf.c s_atan.c s_atanf.c s_cbrt.c s_cbrtf.c \
+       s_ceil.c s_ceilf.c s_ceill.c s_copysign.c s_copysignf.c s_copysignl.c \
+       s_cos.c s_cosf.c s_erf.c \
        s_erff.c s_exp2.c s_exp2f.c s_expm1.c s_expm1f.c s_fabsf.c s_fabsl.c \
        s_finite.c s_finitef.c \
-       s_floor.c s_floorf.c s_frexpf.c s_ilogb.c s_ilogbf.c s_ilogbl.c \
+       s_floor.c s_floorf.c s_floorl.c s_frexpf.c \
+       s_ilogb.c s_ilogbf.c s_ilogbl.c \
        s_isinff.c s_isnanf.c s_lib_version.c s_log1p.c \
        s_log1pf.c s_logb.c s_logbf.c s_logbl.c \
        s_matherr.c s_modff.c s_nextafter.c s_nextafterl.c \
-       s_nextafterf.c s_remquo.c s_remquof.c s_rint.c s_rintf.c s_round.c s_roundf.c s_scalbn.c \
+       s_nextafterf.c s_remquo.c s_remquof.c s_rint.c s_rintf.c \
+       s_round.c s_roundf.c s_roundl.c s_scalbn.c \
        s_scalbnf.c s_scalbnl.c s_signgam.c s_significand.c s_significandf.c s_sin.c \
        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 \
diff -r c5fbeaa0f9ea -r 2867c6fa317b lib/libm/src/namespace.h
--- a/lib/libm/src/namespace.h  Mon Nov 11 23:51:36 2013 +0000
+++ b/lib/libm/src/namespace.h  Mon Nov 11 23:57:34 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: namespace.h,v 1.5 2013/01/28 06:26:20 matt Exp $ */
+/* $NetBSD: namespace.h,v 1.6 2013/11/11 23:57:34 joerg Exp $ */
 
 #define atan2 _atan2
 #define atan2f _atan2f
@@ -45,3 +45,7 @@
 #define scalbln _scalbln
 #define scalblnf _scalblnf
 #define scalblnl _scalblnl
+
+#define ceill _ceill
+#define floorl _floorl
+#define roundl _roundl
diff -r c5fbeaa0f9ea -r 2867c6fa317b lib/libm/src/s_ceil.c
--- a/lib/libm/src/s_ceil.c     Mon Nov 11 23:51:36 2013 +0000
+++ b/lib/libm/src/s_ceil.c     Mon Nov 11 23:57:34 2013 +0000
@@ -12,7 +12,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBM_SCCS) && !defined(lint)
-__RCSID("$NetBSD: s_ceil.c,v 1.13 2009/02/16 01:22:18 lukem Exp $");
+__RCSID("$NetBSD: s_ceil.c,v 1.14 2013/11/11 23:57:34 joerg Exp $");
 #endif
 
 /*
@@ -29,6 +29,11 @@
 
 static const double huge = 1.0e300;
 
+#ifndef __HAVE_LONG_DOUBLE
+__strong_alias(_ceill, ceil)
+__weak_alias(ceill, ceil)
+#endif
+
 double
 ceil(double x)
 {
diff -r c5fbeaa0f9ea -r 2867c6fa317b lib/libm/src/s_ceill.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libm/src/s_ceill.c    Mon Nov 11 23:57:34 2013 +0000
@@ -0,0 +1,112 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ *
+ * From: @(#)s_ceil.c 5.1 93/09/24
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: s_ceill.c,v 1.1 2013/11/11 23:57:34 joerg Exp $");
+#if 0
+__FBSDID("$FreeBSD: head/lib/msun/src/s_ceill.c 176280 2008-02-14 15:10:34Z bde $");
+#endif
+
+/*
+ * ceill(x)
+ * Return x rounded toward -inf to integral value
+ * Method:
+ *     Bit twiddling.
+ * Exception:
+ *     Inexact flag raised if x not equal to ceill(x).
+ */
+#include "namespace.h"
+
+#include <float.h>
+#include <math.h>
+#include <stdint.h>
+#include <machine/ieee.h>
+
+#ifdef __HAVE_LONG_DOUBLE
+
+#ifdef __weak_alias
+__weak_alias(ceill, _ceill)
+#endif
+
+#ifdef LDBL_IMPLICIT_NBIT
+#define        MANH_SIZE       (EXT_FRACHBITS + 1)
+#define        INC_MANH(ux, c) do {                                    \
+       uint64_t oi = ux.extu_frach;                            \
+       ux.extu_frach += (c);                                   \
+       if (ux.extu_frach < oi)                                 \
+               ux.extu_exp++;                                  \
+} while (0)
+#else
+#define        MANH_SIZE       EXT_FRACHBITS
+#define        INC_MANH(ux, c) do {                                    \
+       uint64_t oi = ux.extu_frach;                            \
+       ux.extu_frach += (c);                                   \
+       if (ux.extu_frach < oi) {                               \
+               ux.extu_exp++;                                  \
+               ux.extu_frach |= 1llu << (EXT_FRACHBITS - 1);   \
+       }                                                       \
+} while (0)
+#endif
+
+static const long double huge = 1.0e300;
+
+long double
+ceill(long double x)
+{
+       union ieee_ext_u ux = { .extu_ld = x, };
+       int e = ux.extu_exp - LDBL_MAX_EXP + 1;
+
+       if (e < MANH_SIZE - 1) {
+               if (e < 0) {                    /* raise inexact if x != 0 */
+                       if (huge + x > 0.0)
+                               if (ux.extu_exp > 0 ||
+                                   (ux.extu_frach | ux.extu_fracl) != 0)
+                                       ux.extu_ld = ux.extu_sign ? -0.0 : 1.0;
+               } else {
+                       uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1);
+                       if (((ux.extu_frach & m) | ux.extu_fracl) == 0)
+                               return (x);     /* x is integral */
+                       if (!ux.extu_sign) {
+#ifdef LDBL_IMPLICIT_NBIT
+                               if (e == 0)
+                                       ux.extu_exp++;
+                               else
+#endif
+                               INC_MANH(ux, 1llu << (MANH_SIZE - e - 1));
+                       }
+                       if (huge + x > 0.0) {   /* raise inexact flag */
+                               ux.extu_frach &= ~m;
+                               ux.extu_fracl = 0;
+                       }
+               }
+       } else if (e < LDBL_MANT_DIG - 1) {
+               uint64_t m = (uint64_t)-1 >> (64 - LDBL_MANT_DIG + e + 1);
+               if ((ux.extu_fracl & m) == 0)
+                       return (x);     /* x is integral */
+               if (!ux.extu_sign) {
+                       if (e == MANH_SIZE - 1)
+                               INC_MANH(ux, 1);
+                       else {
+                               uint64_t o = ux.extu_fracl;
+                               ux.extu_fracl += 1llu << (LDBL_MANT_DIG - e - 1);
+                               if (ux.extu_fracl < o)  /* got a carry */
+                                       INC_MANH(ux, 1);
+                       }
+               }
+               if (huge + x > 0.0)             /* raise inexact flag */
+                       ux.extu_fracl &= ~m;
+       }
+       return (ux.extu_ld);
+}
+
+#endif /* __HAVE_LONG_DOUBLE */
diff -r c5fbeaa0f9ea -r 2867c6fa317b lib/libm/src/s_floor.c
--- a/lib/libm/src/s_floor.c    Mon Nov 11 23:51:36 2013 +0000
+++ b/lib/libm/src/s_floor.c    Mon Nov 11 23:57:34 2013 +0000
@@ -12,7 +12,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBM_SCCS) && !defined(lint)
-__RCSID("$NetBSD: s_floor.c,v 1.13 2009/02/16 01:27:36 lukem Exp $");
+__RCSID("$NetBSD: s_floor.c,v 1.14 2013/11/11 23:57:34 joerg Exp $");
 #endif
 
 /*
@@ -27,6 +27,11 @@
 #include "math.h"
 #include "math_private.h"
 
+#ifndef __HAVE_LONG_DOUBLE
+__strong_alias(_floorl, floor)
+__weak_alias(floorl, floor)
+#endif
+
 static const double huge = 1.0e300;
 
 double
diff -r c5fbeaa0f9ea -r 2867c6fa317b lib/libm/src/s_floorl.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libm/src/s_floorl.c   Mon Nov 11 23:57:34 2013 +0000
@@ -0,0 +1,112 @@
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ *
+ * From: @(#)s_floor.c 5.1 93/09/24
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: s_floorl.c,v 1.1 2013/11/11 23:57:34 joerg Exp $");
+#if 0
+__FBSDID("$FreeBSD: head/lib/msun/src/s_floorl.c 176280 2008-02-14 15:10:34Z bde $");
+#endif
+
+/*
+ * floorl(x)
+ * Return x rounded toward -inf to integral value
+ * Method:
+ *     Bit twiddling.
+ * Exception:
+ *     Inexact flag raised if x not equal to floorl(x).
+ */
+#include "namespace.h"
+
+#include <float.h>
+#include <math.h>
+#include <stdint.h>
+#include <machine/ieee.h>
+
+#ifdef __HAVE_LONG_DOUBLE
+
+#ifdef __weak_alias
+__weak_alias(floorl, _floorl)
+#endif
+
+#ifdef LDBL_IMPLICIT_NBIT
+#define        MANH_SIZE       (EXT_FRACHBITS + 1)
+#define        INC_MANH(ux, c) do {                                    \
+       uint64_t oi = ux.extu_frach;                            \
+       ux.extu_frach += (c);                                   \
+       if (ux.extu_frach < oi)                                 \
+               ux.extu_exp++;                                  \
+} while (0)
+#else
+#define        MANH_SIZE       EXT_FRACHBITS
+#define        INC_MANH(ux, c) do {                                    \
+       uint64_t oi = ux.extu_frach;                            \
+       ux.extu_frach += (c);                                   \
+       if (ux.extu_frach < oi) {                               \
+               ux.extu_exp++;                                  \
+               ux.extu_frach |= 1llu << (EXT_FRACHBITS - 1);   \
+       }                                                       \
+} while (0)
+#endif
+
+static const long double huge = 1.0e300;
+
+long double
+floorl(long double x)
+{
+       union ieee_ext_u ux = { .extu_ld = x, };
+       int e = ux.extu_exp - LDBL_MAX_EXP + 1;
+
+       if (e < MANH_SIZE - 1) {
+               if (e < 0) {                    /* raise inexact if x != 0 */
+                       if (huge + x > 0.0)
+                               if (ux.extu_exp > 0 ||
+                                   (ux.extu_frach | ux.extu_fracl) != 0)
+                                       ux.extu_ld = ux.extu_sign ? -1.0 : 0.0;
+               } else {
+                       uint64_t m = ((1llu << MANH_SIZE) - 1) >> (e + 1);
+                       if (((ux.extu_frach & m) | ux.extu_fracl) == 0)
+                               return (x);     /* x is integral */
+                       if (ux.extu_sign) {
+#ifdef LDBL_IMPLICIT_NBIT
+                               if (e == 0)
+                                       ux.extu_exp++;
+                               else



Home | Main Index | Thread Index | Old Index