Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Sep 2005 00:40:19 GMT
From:      "Steven G. Kargl" <kargl@troutmask.apl.washington.edu>
To:        freebsd-standards@FreeBSD.org
Subject:   Re: standards/82654: C99 long double math functions are missing
Message-ID:  <200509130040.j8D0eJwi030136@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR standards/82654; it has been noted by GNATS.

From: "Steven G. Kargl" <kargl@troutmask.apl.washington.edu>
To: FreeBSD-gnats-submit@FreeBSD.org, freebsd-standards@FreeBSD.org
Cc:  
Subject: Re: standards/82654: C99 long double math functions are missing
Date: Mon, 12 Sep 2005 17:30:27 -0700 (PDT)

 --ELM1126571427-113-0_
 Content-Transfer-Encoding: 7bit
 Content-Type: text/plain; charset=US-ASCII
 
 FreeBSD-gnats-submit@FreeBSD.org wrote:
 > Thank you very much for your problem report.
 > It has the internal identification `standards/82654'.
 > The individual assigned to look at your
 > report is: freebsd-standards. 
 > 
 > You can access the state of your problem report at any time
 > via this link:
 > 
 > http://www.freebsd.org/cgi/query-pr.cgi?pr=82654
 > 
 > >Category:       standards
 > >Responsible:    freebsd-standards
 > >Synopsis:       C99 long double math functions are missing
 > >Arrival-Date:   Sat Jun 25 23:40:12 GMT 2005
 > 
 
 Attached is a new implementation of logl(3) and diff to the
 exp.3 man page.
 
 The method to my implementation of the long double log 
 should be acceptable for 64-bit precision and follow the
 following steps:
 
 1) Deal with special cases
 2) Split the argument into fraction, f, and exponent, n, with frexpl
 3) Use a look-up table for 128 entries for log(f_n) where the
    interval [1/2,1) is split into 128 equally spaced intervals.
 4) Use polynomial approximations for interpolation
    a) Start with Taylor's series where x is in [0,1/128] and
       truncate retaining the x**9 term, i.e., error of order 8e-22.
    b) Transform polynomial into range [-1,1]
    c) Rewrite transformed polynomial in an expansion of Chebyshev polynomials
    d) Reduce the Chebyshev polynomials to a polynomial of order x**8.
 5) Run a boat load of tests. 
 
 In the following test, "./log 1000000 10" means 1 million random
 arguments to logf, log, and logl are generated such that x = f*2**e
 and e is in [-10,10] and f is in [1/2,1).
 
 On i386 (53-bit precision), a comparison of logf, log, and logl to
 GMP/MPFR shows the following results.  The legend is read as follows:
 
   R --> a difference of 1 in the last decimal digit
   1 --> a difference of more than 1 in last decimal digit
   2 --> a difference occurs in the 2nd to last decimal digit
   3 --> a difference occurs in the 3rd to last decimal digit
   4 --> a difference occurs in the 4th (or larger) to last decimal digit
 
   FLT --> 24-bit floating point
   DBL --> 53-bit double floating point
   LDBL -> 53-bit long double floating point on i386
        -> 64-bit long double floating point on amd64
 
 kargl[216] ./log 1000000 1
 Checking logf, log, and logl ...
       R      1      2     3     4     Range of Failures
  FLT: 1128   85     18    0     10    9.90536e-01 1.09909e+00
  DBL: 314483 185399 6972  7062  16245 3.67892680689692e-01 1.99999806284904e+00
 LDBL: 316817 185429 6965  7071  16240 3.67892680689692e-01 1.99999806284904e+00
 kargl[217] ./log 1000000 10
 Checking logf, log, and logl ...
       R      1      2     3     4     Range of Failures
  FLT: 237    14     6     0     0     9.90536e-01 1.05196e+00
  DBL: 141135 38632  1289  1269  2959  3.67997204419225e-01 2.71815394610167e+00
 LDBL: 144160 38639  1289  1266  2957  3.67901860736310e-01 2.71815394610167e+00
 kargl[218] ./log 1000000 120
 Checking logf, log, and logl ...
       R      1      2     3     4     Range of Failures
  FLT: 32     0      0     0     0     
  DBL: 23673  3498   128   134   263   3.68287028279155e-01 2.71191326901317e+00
 LDBL: 44026  3503   128   134   263   3.68287028279155e-01 2.71191326901317e+00
 kargl[219] ./log 1000000 1020
 Checking log and logl ...
       R      1      2     3     4     Range of Failures
  DBL: 3761   439    17    9     32    3.70691583026201e-01 2.67239280417562e+00
 LDBL: 28123  437    17    10    31    3.70691583026201e-01 2.70551693812013e+00
 kargl[220] ./log 1000000 16000
 Checking logl ...
       R      1      2     3     4     Range of Failures
 LDBL: 30873  30     0     0     4     9.05885221436620e-01 2.32185203954577e+00
 
 For i386 (53-bit precision), we see the implementation of logl
 is consistent with the implementation of log.  Note, my comparison
 function converts the long double x to an ASCII string via scanf
 and the mpfr type is also converted to an ASCII string.  Thus, a 
 rounding error can occur in my numerical implementation, gdtoa,
 or mpfr_get_str and is the reason why I make a distinction between
 R and 1 in my tables.  Note, the "Range of Failures" excludes the
 differences under R and is fairly well localized to a small range
 in x.
 
 On amd64 (64-bit precision), we find
 
 troutmask:sgk[211] ./log 1000000 1
 Checking logf, log, and logl ...
       R      1      2     3     4     Range of Failures
  FLT: 4105   104    23    0     13    9.90094e-01 1.10419e+00
  DBL: 5586   0      0     0     0     
 LDBL: 124664 631825 61534 8867  95289 2.50107496511191130e-01 1.99999793246388435e+00
 troutmask:sgk[212] ./log 1000000 10
 Checking logf, log, and logl ...
       R      1      2     3     4     Range of Failures
  FLT: 1583   17     2     0     1     9.90414e-01 1.09967e+00
  DBL: 2511   0      0     0     0     
 LDBL: 480101 131205 12991 1654  17324 1.00236730759206694e-03 1.02341860389709473e+03
 troutmask:sgk[213] ./log 1000000 120
 Checking logf, log, and logl ...
       R      1      2     3     4     Range of Failures
  FLT: 254    1      0     0     0     1.05113e+00 1.05113e+00
  DBL: 407    0      0     0     0     
 LDBL: 113720 12165  1176  151   1566  5.22837305538814689e-05 2.19174624633789062e+04
 troutmask:sgk[214] ./log 1000000 1020
 Checking log and logl ...
       R      1      2     3     4     Range of Failures
  DBL: 64     0      0     0     0     
 LDBL: 26339  1465   153   17    170   1.04225044424310909e-04 1.45063449859619141e+04
 troutmask:sgk[215] ./log 1000000 16000
 Checking logl ...
       R      1      2     3     4     Range of Failures
 LDBL: 15995  78     10    2     12    2.05640358899472631e-04 2.63248902320861816e+02
 
 If I restrict the test program and logl to 53-bit precision for
 logl, we find all columns marked with 1, 2, 3, and 4 are zero
 for logl.
 
 If neither das or bde object, I would like to see logl.c committed
 to libm.  With logl committed, I have implementations of log2f, 
 log2, and log2l also ready for the tree.
 
 -- 
 Steve
 http://troutmask.apl.washington.edu/~kargl/
 
 --ELM1126571427-113-0_
 Content-Transfer-Encoding: 7bit
 Content-Type: text/x-c++src
 Content-Disposition: attachment; filename=logl.c
 Content-Description: 
 
 /*-
  * Copyright (c) 2005, 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.
  */
 
 /*
  *  Compute the natural logarithm of x by decomposing x into its base 2
  *  representation.
  *
  *  log(x) = log(F * 2**n) such that F = [1/2,1).
  *         = log(F) + n * log(2)
  *
  *  Let F = f_n + e such that f_n is interval endpoint.
  *
  *  log(F) = log(f_n + e)
  *         = log[f_n (1 + e / f_n)]
  *         = log(f_n) + log(1 + e / f_n)
  *
  *  The log(f_n) are tabulated below.  Let d = e / f_n and use
  *
  *  log(1 + d) = d - (1/2)*d**2 + (1/3)*d**3  - (1/4)*d**4 + ... + (1/9)*d**9
  *             = p(d)
  *
  *  We have d in [0,1/interval width].  This is mapped into an interval
  *  of t in [-1,1] and p(d) is converted into a polynomial p(t).  Next,
  *  p(t) is written as an expansion in Chebyshev polynomials, T_n(t), on
  *  the interval [-1,1].  Finally, T_n(t) are replaced by their polynomials
  *  in t and this is then reduced to an 8th order polynomial.
  *
  *  log(x) = n * log(2) + log(f_n) + p(t)
  *
  */
 
 #include <math.h>
 
 #define LOGL2  0x.b17217f7d1cf79acp0L  /* 6.931471805599453094e-1L */
 
 #define INTERVALS 128
 
 static long double f[INTERVALS][2] = {
    { 0x.8000000000000000p0L, -0x.b17217f7d1cf79acp0L },  /* 128/256 */
    { 0x.8100000000000000p0L, -0x.af74155120c9011cp0L },  /* 129/256 */
    { 0x.8200000000000000p0L, -0x.ad7a02e1b24efd32p0L },  /* 130/256 */
    { 0x.8300000000000000p0L, -0x.ab83d135dc633301p0L },  /* 131/256 */
    { 0x.8400000000000000p0L, -0x.a991713433c2b999p0L },  /* 132/256 */
    { 0x.8500000000000000p0L, -0x.a7a2d41ad270c9d7p0L },  /* 133/256 */
    { 0x.8600000000000000p0L, -0x.a5b7eb7cb860fb89p0L },  /* 134/256 */
    { 0x.8700000000000000p0L, -0x.a3d0a93f45169a4bp0L },  /* 135/256 */
    { 0x.8800000000000000p0L, -0x.a1ecff97c91e267bp0L },  /* 136/256 */
    { 0x.8900000000000000p0L, -0x.a00ce1092e5498c3p0L },  /* 137/256 */
    { 0x.8a00000000000000p0L, -0x.9e304061b5fda919p0L },  /* 138/256 */
    { 0x.8b00000000000000p0L, -0x.9c5710b8cbb73a43p0L },  /* 139/256 */
    { 0x.8c00000000000000p0L, -0x.9a81456cec642e10p0L },  /* 140/256 */
    { 0x.8d00000000000000p0L, -0x.98aed221a03458b6p0L },  /* 141/256 */
    { 0x.8e00000000000000p0L, -0x.96dfaabd86fa1647p0L },  /* 142/256 */
    { 0x.8f00000000000000p0L, -0x.9513c36876083696p0L },  /* 143/256 */
    { 0x.9000000000000000p0L, -0x.934b1089a6dc93c2p0L },  /* 144/256 */
    { 0x.9100000000000000p0L, -0x.918586c5f5e4bf02p0L },  /* 145/256 */
    { 0x.9200000000000000p0L, -0x.8fc31afe30b2c6dfp0L },  /* 146/256 */
    { 0x.9300000000000000p0L, -0x.8e03c24d7300395ap0L },  /* 147/256 */
    { 0x.9400000000000000p0L, -0x.8c47720791e53314p0L },  /* 148/256 */
    { 0x.9500000000000000p0L, -0x.8a8e1fb794b09134p0L },  /* 149/256 */
    { 0x.9600000000000000p0L, -0x.88d7c11e3ad53cdcp0L },  /* 150/256 */
    { 0x.9700000000000000p0L, -0x.87244c308e670a66p0L },  /* 151/256 */
    { 0x.9800000000000000p0L, -0x.8573b71682a7d21bp0L },  /* 152/256 */
    { 0x.9900000000000000p0L, -0x.83c5f8299e2b4091p0L },  /* 153/256 */
    { 0x.9a00000000000000p0L, -0x.821b05f3b01d6774p0L },  /* 154/256 */
    { 0x.9b00000000000000p0L, -0x.8072d72d903d588cp0L },  /* 155/256 */
    { 0x.9c00000000000000p0L, -0x.7ecd62bde92210bfp0L },  /* 156/256 */
    { 0x.9d00000000000000p0L, -0x.7d2a9fb80c64b379p0L },  /* 157/256 */
    { 0x.9e00000000000000p0L, -0x.7b8a855ad04f93fap0L },  /* 158/256 */
    { 0x.9f00000000000000p0L, -0x.79ed0b0f76b5cd58p0L },  /* 159/256 */
    { 0x.a000000000000000p0L, -0x.785228689c9b3653p0L },  /* 160/256 */
    { 0x.a100000000000000p0L, -0x.76b9d521325856f5p0L },  /* 161/256 */
    { 0x.a200000000000000p0L, -0x.7524091b7be9add8p0L },  /* 162/256 */
    { 0x.a300000000000000p0L, -0x.7390bc60191d0d08p0L },  /* 163/256 */
    { 0x.a400000000000000p0L, -0x.71ffe71d15532491p0L },  /* 164/256 */
    { 0x.a500000000000000p0L, -0x.707181a4fe8e7640p0L },  /* 165/256 */
    { 0x.a600000000000000p0L, -0x.6ee5846e038bec2ep0L },  /* 166/256 */
    { 0x.a700000000000000p0L, -0x.6d5be81118a42549p0L },  /* 167/256 */
    { 0x.a800000000000000p0L, -0x.6bd4a5492337419dp0L },  /* 168/256 */
    { 0x.a900000000000000p0L, -0x.6a4fb4f22b678dbdp0L },  /* 169/256 */
    { 0x.aa00000000000000p0L, -0x.68cd100893e9e323p0L },  /* 170/256 */
    { 0x.ab00000000000000p0L, -0x.674cafa857b4ec31p0L },  /* 171/256 */
    { 0x.ac00000000000000p0L, -0x.65ce8d0c4d5ab73bp0L },  /* 172/256 */
    { 0x.ad00000000000000p0L, -0x.6452a18d6fda2653p0L },  /* 173/256 */
    { 0x.ae00000000000000p0L, -0x.62d8e6a22cb7d28fp0L },  /* 174/256 */
    { 0x.af00000000000000p0L, -0x.616155ddb72feab8p0L },  /* 175/256 */
    { 0x.b000000000000000p0L, -0x.5febe8ef60546fb8p0L },  /* 176/256 */
    { 0x.b100000000000000p0L, -0x.5e7899a1f3ecf63fp0L },  /* 177/256 */
    { 0x.b200000000000000p0L, -0x.5d0761db19eec585p0L },  /* 178/256 */
    { 0x.b300000000000000p0L, -0x.5b983b9abc65c859p0L },  /* 179/256 */
    { 0x.b400000000000000p0L, -0x.5a2b20fa71a8506ap0L },  /* 180/256 */
    { 0x.b500000000000000p0L, -0x.58c00c2ceab124eep0L },  /* 181/256 */
    { 0x.b600000000000000p0L, -0x.5756f77d657cbe9bp0L },  /* 182/256 */
    { 0x.b700000000000000p0L, -0x.55efdd4f2347eb7bp0L },  /* 183/256 */
    { 0x.b800000000000000p0L, -0x.548ab81ce28f5f38p0L },  /* 184/256 */
    { 0x.b900000000000000p0L, -0x.532782785cb0efbbp0L },  /* 185/256 */
    { 0x.ba00000000000000p0L, -0x.51c63709c7106c19p0L },  /* 186/256 */
    { 0x.bb00000000000000p0L, -0x.5066d08f57a31c87p0L },  /* 187/256 */
    { 0x.bc00000000000000p0L, -0x.4f0949dcccc60ed5p0L },  /* 188/256 */
    { 0x.bd00000000000000p0L, -0x.4dad9ddaf8445bb3p0L },  /* 189/256 */
    { 0x.be00000000000000p0L, -0x.4c53c7874d738ec3p0L },  /* 190/256 */
    { 0x.bf00000000000000p0L, -0x.4afbc1f3724d4e7dp0L },  /* 191/256 */
    { 0x.c000000000000000p0L, -0x.49a58844d36e49e1p0L },  /* 192/256 */
    { 0x.c100000000000000p0L, -0x.485115b43ae350fcp0L },  /* 193/256 */
    { 0x.c200000000000000p0L, -0x.46fe658d69ae5377p0L },  /* 194/256 */
    { 0x.c300000000000000p0L, -0x.45ad732eb3edcd67p0L },  /* 195/256 */
    { 0x.c400000000000000p0L, -0x.445e3a089f91ef79p0L },  /* 196/256 */
    { 0x.c500000000000000p0L, -0x.4310b59d858b8c46p0L },  /* 197/256 */
    { 0x.c600000000000000p0L, -0x.41c4e181356189cep0L },  /* 198/256 */
    { 0x.c700000000000000p0L, -0x.407ab9589b1a43ddp0L },  /* 199/256 */
    { 0x.c800000000000000p0L, -0x.3f3238d96766f2fbp0L },  /* 200/256 */
    { 0x.c900000000000000p0L, -0x.3deb5bc9b9ffcbbep0L },  /* 201/256 */
    { 0x.ca00000000000000p0L, -0x.3ca61dffce202424p0L },  /* 202/256 */
    { 0x.cb00000000000000p0L, -0x.3b627b61a912806bp0L },  /* 203/256 */
    { 0x.cc00000000000000p0L, -0x.3a206fe4cabcf6b0p0L },  /* 204/256 */
    { 0x.cd00000000000000p0L, -0x.38dff78de01ee139p0L },  /* 205/256 */
    { 0x.ce00000000000000p0L, -0x.37a10e7077b15a1ep0L },  /* 206/256 */
    { 0x.cf00000000000000p0L, -0x.3663b0aeb79c794ep0L },  /* 207/256 */
    { 0x.d000000000000000p0L, -0x.3527da7915b3c6dep0L },  /* 208/256 */
    { 0x.d100000000000000p0L, -0x.33ed880e112cc827p0L },  /* 209/256 */
    { 0x.d200000000000000p0L, -0x.32b4b5b9ee02fe45p0L },  /* 210/256 */
    { 0x.d300000000000000p0L, -0x.317d5fd671fd1855p0L },  /* 211/256 */
    { 0x.d400000000000000p0L, -0x.304782caa3478377p0L },  /* 212/256 */
    { 0x.d500000000000000p0L, -0x.2f131b0a8898e67cp0L },  /* 213/256 */
    { 0x.d600000000000000p0L, -0x.2de02516ead57739p0L },  /* 214/256 */
    { 0x.d700000000000000p0L, -0x.2cae9d7d182673e3p0L },  /* 215/256 */
    { 0x.d800000000000000p0L, -0x.2b7e80d6a87b63f7p0L },  /* 216/256 */
    { 0x.d900000000000000p0L, -0x.2a4fcbc9436b19f4p0L },  /* 217/256 */
    { 0x.da00000000000000p0L, -0x.29227b06676ac1bdp0L },  /* 218/256 */
    { 0x.db00000000000000p0L, -0x.27f68b4b32519714p0L },  /* 219/256 */
    { 0x.dc00000000000000p0L, -0x.26cbf9602b202c5fp0L },  /* 220/256 */
    { 0x.dd00000000000000p0L, -0x.25a2c2190d0273aep0L },  /* 221/256 */
    { 0x.de00000000000000p0L, -0x.247ae25493840349p0L },  /* 222/256 */
    { 0x.df00000000000000p0L, -0x.235456fc47ee53c7p0L },  /* 223/256 */
    { 0x.e000000000000000p0L, -0x.222f1d044fc8f7bcp0L },  /* 224/256 */
    { 0x.e100000000000000p0L, -0x.210b316b3c740d11p0L },  /* 225/256 */
    { 0x.e200000000000000p0L, -0x.1fe89139dbd56595p0L },  /* 226/256 */
    { 0x.e300000000000000p0L, -0x.1ec739830a111fccp0L },  /* 227/256 */
    { 0x.e400000000000000p0L, -0x.1da727638446a250p0L },  /* 228/256 */
    { 0x.e500000000000000p0L, -0x.1c885801bc4b2369p0L },  /* 229/256 */
    { 0x.e600000000000000p0L, -0x.1b6ac88dad5b1be0p0L },  /* 230/256 */
    { 0x.e700000000000000p0L, -0x.1a4e7640b1bc37a9p0L },  /* 231/256 */
    { 0x.e800000000000000p0L, -0x.19335e5d594988aep0L },  /* 232/256 */
    { 0x.e900000000000000p0L, -0x.18197e2f40e3f01cp0L },  /* 233/256 */
    { 0x.ea00000000000000p0L, -0x.1700d30aeac0e0f4p0L },  /* 234/256 */
    { 0x.eb00000000000000p0L, -0x.15e95a4d9791cb7dp0L },  /* 235/256 */
    { 0x.ec00000000000000p0L, -0x.14d3115d207eac5ep0L },  /* 236/256 */
    { 0x.ed00000000000000p0L, -0x.13bdf5a7d1ee642fp0L },  /* 237/256 */
    { 0x.ee00000000000000p0L, -0x.12aa04a44717a48cp0L },  /* 238/256 */
    { 0x.ef00000000000000p0L, -0x.11973bd1465566d1p0L },  /* 239/256 */
    { 0x.f000000000000000p0L, -0x.108598b59e3a0689p0L },  /* 240/256 */
    { 0x.f100000000000000p0L, -0x.f7518e0035c3dd83p-4L },  /* 241/256 */
    { 0x.f200000000000000p0L, -0x.e65b9e6eed965c37p-4L },  /* 242/256 */
    { 0x.f300000000000000p0L, -0x.d5779687d887e0d2p-4L },  /* 243/256 */
    { 0x.f400000000000000p0L, -0x.c4a550a4fd9a19a9p-4L },  /* 244/256 */
    { 0x.f500000000000000p0L, -0x.b3e4a796a5dac208p-4L },  /* 245/256 */
    { 0x.f600000000000000p0L, -0x.a33576a16f1f4c64p-4L },  /* 246/256 */
    { 0x.f700000000000000p0L, -0x.9297997c68c1f4d7p-4L },  /* 247/256 */
    { 0x.f800000000000000p0L, -0x.820aec4f3a222381p-4L },  /* 248/256 */
    { 0x.f900000000000000p0L, -0x.718f4bb052abc632p-4L },  /* 249/256 */
    { 0x.fa00000000000000p0L, -0x.612494a3232afa2ep-4L },  /* 250/256 */
    { 0x.fb00000000000000p0L, -0x.50caa49660330273p-4L },  /* 251/256 */
    { 0x.fc00000000000000p0L, -0x.408159624d611d28p-4L },  /* 252/256 */
    { 0x.fd00000000000000p0L, -0x.3048914711455441p-4L },  /* 253/256 */
    { 0x.fe00000000000000p0L, -0x.20202aeb11bce252p-4L },  /* 254/256 */
    { 0x.ff00000000000000p0L, -0x.10080559588b357ep-4L }   /* 255/256 */
 };
 /*
  *  Chebyshev reduced coefficients in power series.
  */
 #define M00  0x.ff805515885e0250p-8L     /*  0.389864041565732301e-2L */
 #define M01  0x.ff00ff00ff0591f1p-8L     /*  0.389105058365765103e-2L */
 #define M02 -0x.7f017e027d037c00p-16L     /* -0.757013732229102636e-5L */
 #define M03  0x.545751e06188aaabp-24L     /*  0.196371909896990662e-7L */
 #define M04 -0x.3f027b08b2000000p-32L     /* -0.573069790783262763e-10L */
 #define M05  0x.327f5b4288888889p-40L     /*  0.179403110200483648e-12L */
 #define M05  0x.327f5b4288888889p-40L     /*  0.179403110200483648e-12L */
 #define M06 -0x.29ae215555555555p-48L     /* -0.578428917628910401e-15L */
 #define M07 -0x.29ae215555555555p-48L     /* -0.578428917628910401e-15L */
 #define M08 -0x.1f00000000000000p-64L     /* -0.656450534122082763e-20L */
 #define M09  0x.1c71c71c71c71c72p-72L     /*  0.235286929792861205e-22L */
 
 static long double zero = 0.0L;
 
 long double logl(long double x) {
 
    int i, j, n;
    long double ff, d, t, val;
 
    /* log(+Inf) = +Inf */
    if (isinf(x))
       return x*x+x;
 
    /* log(NaN) =  NaN with signal */
    if (isnan(x))
       return (x+x);
 
    /* log(x) = sNaN if x < 0. */
    if (x < zero)
       return (x - x) / (x - x);
 
    /* log(+-0) = -Inf with signal */
    if (x == zero)
       return (- 1.0L / zero);
 
    /* Break x into ff * 2**n */
    ff = frexpl(x, &n);
 
    /* Find index for the relevant interval */
    i = 2 * ff * INTERVALS - INTERVALS;
      
    d = (ff - f[i][0]) / f[i][0];   /* d in [0,1/INTERVALS] */
 
    /* Polynomial mapped into in [-1,1] */
    t = 2 * INTERVALS * d - 1.0L;
 
    val = M08 + M09 * t;
    val = M07 + val * t;
    val = M06 + val * t;
    val = M05 + val * t;
    val = M04 + val * t;
    val = M03 + val * t;
    val = M02 + val * t;
    val = M01 + val * t;
    val = M00 + val * t;
 
    val += n * LOGL2 + f[i][1];
 
    return val;
 
 }
 
 --ELM1126571427-113-0_
 Content-Transfer-Encoding: 7bit
 Content-Type: text/x-patch
 Content-Disposition: attachment; filename=exp.3.diff
 Content-Description: 
 
 --- /mnt1/src/lib/msun/man/exp.3	Wed Aug 24 21:02:10 2005
 +++ exp.3	Mon Sep 12 16:51:12 2005
 @@ -45,8 +45,10 @@
  .Nm expm1f ,
  .Nm log ,
  .Nm logf ,
 +.Nm logl ,
  .Nm log10 ,
  .Nm log10f ,
 +.Nm log10l ,
  .Nm log1p ,
  .Nm log1pf ,
  .Nm pow ,
 @@ -72,10 +74,14 @@
  .Fn log "double x"
  .Ft float
  .Fn logf "float x"
 +.Ft "long double"
 +.Fn logl "long double x"
  .Ft double
  .Fn log10 "double x"
  .Ft float
  .Fn log10f "float x"
 +.Ft "long double"
 +.Fn log10l "long double x"
  .Ft double
  .Fn log1p "double x"
  .Ft float
 @@ -109,16 +115,18 @@
  .Fa x .
  .Pp
  The
 -.Fn log
 -and the
 -.Fn logf
 +.Fn log ,
 +.Fn logf ,
 +and
 +.Fn logl
  functions compute the value of the natural logarithm of argument
  .Fa x .
  .Pp
  The
 -.Fn log10
 -and the
 -.Fn log10f
 +.Fn log10 ,
 +.Fn log10f ,
 +and
 +.Fn log10l
  functions compute the value of the logarithm of argument
  .Fa x
  to base 10.
 
 --ELM1126571427-113-0_--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200509130040.j8D0eJwi030136>