Source-Changes-HG archive

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

[src/trunk]: src Add cbrtl(3) and sqrtl(3), from FreeBSD.



details:   https://anonhg.NetBSD.org/src/rev/897d482da437
branches:  trunk
changeset: 791471:897d482da437
user:      joerg <joerg%NetBSD.org@localhost>
date:      Tue Nov 19 19:24:33 2013 +0000

description:
Add cbrtl(3) and sqrtl(3), from FreeBSD.

diffstat:

 distrib/sets/lists/comp/mi  |    8 +-
 lib/libm/Makefile           |   11 +-
 lib/libm/man/sqrt.3         |   27 ++++--
 lib/libm/src/e_sqrtl.c      |  161 ++++++++++++++++++++++++++++++++++++++++++++
 lib/libm/src/k_standard.c   |   10 ++-
 lib/libm/src/math_private.h |    3 +-
 lib/libm/src/namespace.h    |    4 +-
 lib/libm/src/s_cbrt.c       |    8 +-
 lib/libm/src/s_cbrtl.c      |  145 +++++++++++++++++++++++++++++++++++++++
 lib/libm/src/w_sqrt.c       |    8 +-
 lib/libm/src/w_sqrtl.c      |   40 ++++++++++
 tests/lib/libm/t_cbrt.c     |  124 +++++++++++++++++++++++++++++++++-
 tests/lib/libm/t_sqrt.c     |  123 +++++++++++++++++++++++++++++++++-
 13 files changed, 647 insertions(+), 25 deletions(-)

diffs (truncated from 944 to 300 lines):

diff -r 5755aaada4ce -r 897d482da437 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Tue Nov 19 19:10:29 2013 +0000
+++ b/distrib/sets/lists/comp/mi        Tue Nov 19 19:24:33 2013 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.1861 2013/11/16 13:01:38 alnsn Exp $
+#      $NetBSD: mi,v 1.1862 2013/11/19 19:24:34 joerg Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -5666,6 +5666,7 @@
 ./usr/share/man/cat3/cbreak.0                  comp-c-catman           .cat
 ./usr/share/man/cat3/cbrt.0                    comp-c-catman           .cat
 ./usr/share/man/cat3/cbrtf.0                   comp-c-catman           .cat
+./usr/share/man/cat3/cbrtl.0                   comp-c-catman           .cat
 ./usr/share/man/cat3/ccos.0                    comp-c-catman           complex,.cat
 ./usr/share/man/cat3/ccosf.0                   comp-c-catman           complex,.cat
 ./usr/share/man/cat3/ccosh.0                   comp-c-catman           complex,.cat
@@ -8804,6 +8805,7 @@
 ./usr/share/man/cat3/sprintf.0                 comp-c-catman           .cat
 ./usr/share/man/cat3/sqrt.0                    comp-c-catman           .cat
 ./usr/share/man/cat3/sqrtf.0                   comp-c-catman           .cat
+./usr/share/man/cat3/sqrtl.0                   comp-c-catman           .cat
 ./usr/share/man/cat3/sradixsort.0              comp-c-catman           .cat
 ./usr/share/man/cat3/srand.0                   comp-c-catman           .cat
 ./usr/share/man/cat3/srand48.0                 comp-c-catman           .cat
@@ -12269,6 +12271,7 @@
 ./usr/share/man/html3/cbreak.html              comp-c-htmlman          html
 ./usr/share/man/html3/cbrt.html                        comp-c-htmlman          html
 ./usr/share/man/html3/cbrtf.html               comp-c-htmlman          html
+./usr/share/man/html3/cbrtl.html               comp-c-htmlman          html
 ./usr/share/man/html3/ccos.html                        comp-c-htmlman          complex,html
 ./usr/share/man/html3/ccosf.html               comp-c-htmlman          complex,html
 ./usr/share/man/html3/ccosh.html               comp-c-htmlman          complex,html
@@ -15299,6 +15302,7 @@
 ./usr/share/man/html3/sprintf.html             comp-c-htmlman          html
 ./usr/share/man/html3/sqrt.html                        comp-c-htmlman          html
 ./usr/share/man/html3/sqrtf.html               comp-c-htmlman          html
+./usr/share/man/html3/sqrtl.html               comp-c-htmlman          html
 ./usr/share/man/html3/sradixsort.html          comp-c-htmlman          html
 ./usr/share/man/html3/srand.html               comp-c-htmlman          html
 ./usr/share/man/html3/srand48.html             comp-c-htmlman          html
@@ -18696,6 +18700,7 @@
 ./usr/share/man/man3/cbreak.3                  comp-c-man              .man
 ./usr/share/man/man3/cbrt.3                    comp-c-man              .man
 ./usr/share/man/man3/cbrtf.3                   comp-c-man              .man
+./usr/share/man/man3/cbrtl.3                   comp-c-man              .man
 ./usr/share/man/man3/ccos.3                    comp-c-man              complex,.man
 ./usr/share/man/man3/ccosf.3                   comp-c-man              complex,.man
 ./usr/share/man/man3/ccosh.3                   comp-c-man              complex,.man
@@ -21830,6 +21835,7 @@
 ./usr/share/man/man3/sprintf.3                 comp-c-man              .man
 ./usr/share/man/man3/sqrt.3                    comp-c-man              .man
 ./usr/share/man/man3/sqrtf.3                   comp-c-man              .man
+./usr/share/man/man3/sqrtl.3                   comp-c-man              .man
 ./usr/share/man/man3/sradixsort.3              comp-c-man              .man
 ./usr/share/man/man3/srand.3                   comp-c-man              .man
 ./usr/share/man/man3/srand48.3                 comp-c-man              .man
diff -r 5755aaada4ce -r 897d482da437 lib/libm/Makefile
--- a/lib/libm/Makefile Tue Nov 19 19:10:29 2013 +0000
+++ b/lib/libm/Makefile Tue Nov 19 19:24:33 2013 +0000
@@ -1,4 +1,4 @@
-#  $NetBSD: Makefile,v 1.149 2013/11/13 22:09:55 joerg Exp $
+#  $NetBSD: Makefile,v 1.150 2013/11/19 19:24:33 joerg Exp $
 #
 #  @(#)Makefile 5.1beta 93/09/24
 #
@@ -156,11 +156,11 @@
        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 \
-       e_scalbf.c e_sinh.c e_sinhf.c e_sqrt.c e_sqrtf.c \
+       e_scalbf.c e_sinh.c e_sinhf.c e_sqrt.c e_sqrtf.c e_sqrtl.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 \
        ldbl_dummy.c \
-       s_asinh.c s_asinhf.c s_atan.c s_atanf.c s_cbrt.c s_cbrtf.c \
+       s_asinh.c s_asinhf.c s_atan.c s_atanf.c s_cbrt.c s_cbrtf.c s_cbrtl.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 \
@@ -184,7 +184,7 @@
        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 \
        w_pow.c w_powf.c w_remainder.c w_remainderf.c w_scalb.c w_scalbf.c \
-       w_sinh.c w_sinhf.c w_sqrt.c w_sqrtf.c \
+       w_sinh.c w_sinhf.c w_sqrt.c w_sqrtf.c w_sqrtl.c \
        lrint.c lrintf.c llrint.c llrintf.c lround.c lroundf.c llround.c \
        llroundf.c s_frexp.c s_frexpl.c s_modf.c \
        s_fmax.c s_fmaxf.c s_fmaxl.c \
@@ -313,7 +313,8 @@
        scalbn.3 scalbnl.3
 MLINKS+=sin.3 sinf.3
 MLINKS+=sin.3 sinhf.3
-MLINKS+=sqrt.3 sqrtf.3 sqrt.3 cbrt.3 sqrt.3 cbrtf.3
+MLINKS+=sqrt.3 sqrtf.3 sqrt.3 sqrtl.3 \
+       sqrt.3 cbrt.3 sqrt.3 cbrtf.3 sqrt.3 cbrtl.3
 MLINKS+=tan.3 tanf.3
 MLINKS+=tanh.3 tanhf.3
 MLINKS+=round.3 roundf.3 \
diff -r 5755aaada4ce -r 897d482da437 lib/libm/man/sqrt.3
--- a/lib/libm/man/sqrt.3       Tue Nov 19 19:10:29 2013 +0000
+++ b/lib/libm/man/sqrt.3       Tue Nov 19 19:24:33 2013 +0000
@@ -26,16 +26,18 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     from: @(#)sqrt.3       6.4 (Berkeley) 5/6/91
-.\"    $NetBSD: sqrt.3,v 1.13 2003/08/07 16:44:49 agc Exp $
+.\"    $NetBSD: sqrt.3,v 1.14 2013/11/19 19:24:33 joerg Exp $
 .\"
-.Dd May 6, 1991
+.Dd November 19, 2013
 .Dt SQRT 3
 .Os
 .Sh NAME
 .Nm cbrt ,
 .Nm cbrtf ,
+.Nm cbrtl ,
 .Nm sqrt ,
-.Nm sqrtf
+.Nm sqrtf ,
+.Nm sqrtl
 .Nd cube root and square root functions
 .Sh LIBRARY
 .Lb libm
@@ -45,30 +47,37 @@
 .Fn cbrt "double x"
 .Ft float
 .Fn cbrtf "float x"
+.Ft long double
+.Fn cbrtl "long double x"
 .Ft double
 .Fn sqrt "double x"
 .Ft float
 .Fn sqrtf "float x"
+.Ft long double
+.Fn sqrtl "long double x"
 .Sh DESCRIPTION
 The
-.Fn cbrt
+.Fn cbrt ,
+.Fn cbrtf
 and
-.Fn cbrtf
+.Fn cbrtl
 functions compute
 the cube root of
 .Ar x .
 .Pp
 The
-.Fn sqrt
+.Fn sqrt ,
+.Fn sqrtf
 and
-.Fn sqrtf
+.Fn sqrtl
 functions compute
 the non-negative square root of x.
 .Sh RETURN VALUES
 If x is negative,
-.Fn sqrt "x"
+.Fn sqrt "x" ,
+.Fn sqrtf "x"
 and
-.Fn sqrtf "x"
+.Fn sqrtl "x"
 .\" POSIX_MODE
 set the global variable
 .Va errno
diff -r 5755aaada4ce -r 897d482da437 lib/libm/src/e_sqrtl.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libm/src/e_sqrtl.c    Tue Nov 19 19:24:33 2013 +0000
@@ -0,0 +1,161 @@
+/*-
+ * Copyright (c) 2007 Steven G. Kargl
+ * All rights reserved.
+ *
+ * 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 unmodified, 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#include <sys/cdefs.h>
+#if 0
+__FBSDID("$FreeBSD: head/lib/msun/src/e_sqrtl.c 176720 2008-03-02 01:47:58Z das $");
+#endif
+__RCSID("$NetBSD: e_sqrtl.c,v 1.1 2013/11/19 19:24:34 joerg Exp $");
+
+#include <machine/ieee.h>
+#include <fenv.h>
+#include <float.h>
+
+#include "math.h"
+#include "math_private.h"
+
+#ifdef __HAVE_LONG_DOUBLE
+
+/* Return (x + ulp) for normal positive x. Assumes no overflow. */
+static inline long double
+inc(long double x)
+{
+       union ieee_ext_u ux = { .extu_ld = x, };
+
+       if (++ux.extu_fracl == 0) {
+               if (++ux.extu_frach == 0) {
+                       ux.extu_exp++;
+                       ux.extu_frach |= LDBL_NBIT;
+               }
+       }
+       return (ux.extu_ld);
+}
+
+/* Return (x - ulp) for normal positive x. Assumes no underflow. */
+static inline long double
+dec(long double x)
+{
+       union ieee_ext_u ux = { .extu_ld = x, };
+
+       if (ux.extu_fracl-- == 0) {
+               if (ux.extu_frach-- == LDBL_NBIT) {
+                       ux.extu_exp--;
+                       ux.extu_frach |= LDBL_NBIT;
+               }
+       }
+       return (ux.extu_ld);
+}
+
+/*
+ * This is slow, but simple and portable. You should use hardware sqrt
+ * if possible.
+ */
+
+long double
+__ieee754_sqrtl(long double x)
+{
+       union ieee_ext_u ux = { .extu_ld = x, };
+       int k, r;
+       long double lo, xn;
+       fenv_t env;
+
+       /* If x = NaN, then sqrt(x) = NaN. */
+       /* If x = Inf, then sqrt(x) = Inf. */
+       /* If x = -Inf, then sqrt(x) = NaN. */
+       if (ux.extu_exp == LDBL_MAX_EXP * 2 - 1)
+               return (x * x + x);
+
+       /* If x = +-0, then sqrt(x) = +-0. */
+       if ((ux.extu_frach | ux.extu_fracl | ux.extu_exp) == 0)
+               return (x);
+
+       /* If x < 0, then raise invalid and return NaN */
+       if (ux.extu_sign)
+               return ((x - x) / (x - x));
+
+       feholdexcept(&env);
+
+       if (ux.extu_exp == 0) {
+               /* Adjust subnormal numbers. */
+               ux.extu_ld *= 0x1.0p514;
+               k = -514;
+       } else {
+               k = 0;
+       }
+       /*
+        * ux.extu_ld is a normal number, so break it into ux.extu_ld = e*2^n where
+        * ux.extu_ld = (2*e)*2^2k for odd n and ux.extu_ld = (4*e)*2^2k for even n.
+        */
+       if ((ux.extu_exp - EXT_EXP_BIAS) & 1) { /* n is even.     */
+               k += ux.extu_exp - EXT_EXP_BIAS - 1; /* 2k = n - 2.   */
+               ux.extu_exp = EXT_EXP_BIAS + 1; /* ux.extu_ld in [2,4). */
+       } else {
+               k += ux.extu_exp - EXT_EXP_BIAS;        /* 2k = n - 1.   */
+               ux.extu_exp = EXT_EXP_BIAS;     /* ux.extu_ld in [1,2). */
+       }
+
+       /*
+        * Newton's iteration.
+        * Split ux.extu_ld into a high and low part to achieve additional precision.
+        */
+       xn = sqrt(ux.extu_ld);                  /* 53-bit estimate of sqrtl(x). */
+#if LDBL_MANT_DIG > 100
+       xn = (xn + (ux.extu_ld / xn)) * 0.5;    /* 106-bit estimate. */
+#endif
+       lo = ux.extu_ld;



Home | Main Index | Thread Index | Old Index