BSD 4_4 release
[unix-history] / usr / src / lib / libm / common_source / log1p.c
index 767d8ab..cbf9fcd 100644 (file)
@@ -1,20 +1,39 @@
-/* 
- * Copyright (c) 1985 Regents of the University of California.
- * 
- * Use and reproduction of this software are granted  in  accordance  with
- * the terms and conditions specified in  the  Berkeley  Software  License
- * Agreement (in particular, this entails acknowledgement of the programs'
- * source, and inclusion of this notice) with the additional understanding
- * that  all  recipients  should regard themselves as participants  in  an
- * ongoing  research  project and hence should  feel  obligated  to report
- * their  experiences (good or bad) with these elementary function  codes,
- * using "sendbug 4bsd-bugs@BERKELEY", to the authors.
+/*
+ * Copyright (c) 1985, 1993
+ *     The Regents of the University of California.  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, 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] =
-"@(#)log1p.c   1.3 (Berkeley) 8/21/85; 5.1 (ucb.elefunt) %G%";
-#endif /* not lint */
+static char sccsid[] = "@(#)log1p.c    8.1 (Berkeley) 6/4/93";
+#endif /* not lint */
 
 /* LOG1P(x) 
  * RETURN THE LOGARITHM OF 1+x
 
 /* LOG1P(x) 
  * RETURN THE LOGARITHM OF 1+x
@@ -75,37 +94,30 @@ static char sccsid[] =
  * shown.
  */
 
  * shown.
  */
 
-#if defined(vax)||defined(tahoe)       /* VAX D format */
 #include <errno.h>
 #include <errno.h>
-#ifdef vax
-#define _0x(A,B)       0x/**/A/**/B
-#else  /* vax */
-#define _0x(A,B)       0x/**/B/**/A
-#endif /* vax */
-/* static double */
-/* ln2hi  =  6.9314718055829871446E-1    , Hex  2^  0   *  .B17217F7D00000 */
-/* ln2lo  =  1.6465949582897081279E-12   , Hex  2^-39   *  .E7BCD5E4F1D9CC */
-/* sqrt2  =  1.4142135623730950622E0     ; Hex  2^  1   *  .B504F333F9DE65 */
-static long     ln2hix[] = { _0x(7217,4031), _0x(0000,f7d0)};
-static long     ln2lox[] = { _0x(bcd5,2ce7), _0x(d9cc,e4f1)};
-static long     sqrt2x[] = { _0x(04f3,40b5), _0x(de65,33f9)};
-#define    ln2hi    (*(double*)ln2hix)
-#define    ln2lo    (*(double*)ln2lox)
-#define    sqrt2    (*(double*)sqrt2x)
-#else  /* defined(vax)||defined(tahoe) */
-static double
-ln2hi  =  6.9314718036912381649E-1    , /*Hex  2^ -1   *  1.62E42FEE00000 */
-ln2lo  =  1.9082149292705877000E-10   , /*Hex  2^-33   *  1.A39EF35793C76 */
-sqrt2  =  1.4142135623730951455E0     ; /*Hex  2^  0   *  1.6A09E667F3BCD */
-#endif /* defined(vax)||defined(tahoe) */
+#include "mathimpl.h"
+
+vc(ln2hi, 6.9314718055829871446E-1  ,7217,4031,0000,f7d0,   0, .B17217F7D00000)
+vc(ln2lo, 1.6465949582897081279E-12 ,bcd5,2ce7,d9cc,e4f1, -39, .E7BCD5E4F1D9CC)
+vc(sqrt2, 1.4142135623730950622E0   ,04f3,40b5,de65,33f9,   1, .B504F333F9DE65)
+
+ic(ln2hi, 6.9314718036912381649E-1,   -1, 1.62E42FEE00000)
+ic(ln2lo, 1.9082149292705877000E-10, -33, 1.A39EF35793C76)
+ic(sqrt2, 1.4142135623730951455E0,     0, 1.6A09E667F3BCD)
+
+#ifdef vccast
+#define        ln2hi   vccast(ln2hi)
+#define        ln2lo   vccast(ln2lo)
+#define        sqrt2   vccast(sqrt2)
+#endif
 
 double log1p(x)
 double x;
 {
 
 double log1p(x)
 double x;
 {
-       static double zero=0.0, negone= -1.0, one=1.0, 
+       const static double zero=0.0, negone= -1.0, one=1.0, 
                      half=1.0/2.0, small=1.0E-20;   /* 1+small == 1 */
                      half=1.0/2.0, small=1.0E-20;   /* 1+small == 1 */
-       double logb(),copysign(),scalb(),log__L(),z,s,t,c;
-       int k,finite();
+       double z,s,t,c;
+       int k;
 
 #if !defined(vax)&&!defined(tahoe)
        if(x!=x) return(x);     /* x is NaN */
 
 #if !defined(vax)&&!defined(tahoe)
        if(x!=x) return(x);     /* x is NaN */
@@ -125,7 +137,7 @@ double x;
           /* compute log(1+x)  */
               s = x/(2+x); t = x*x*half;
              c += (k*ln2lo-c*x);
           /* compute log(1+x)  */
               s = x/(2+x); t = x*x*half;
              c += (k*ln2lo-c*x);
-             z = c+s*(t+log__L(s*s));
+             z = c+s*(t+__log__L(s*s));
              x += (z - t) ;
 
              return(k*ln2hi+x);
              x += (z - t) ;
 
              return(k*ln2hi+x);
@@ -134,7 +146,6 @@ double x;
 
            else {
 #if defined(vax)||defined(tahoe)
 
            else {
 #if defined(vax)||defined(tahoe)
-               extern double infnan();
                if ( x == negone )
                    return (infnan(-ERANGE));   /* -INF */
                else
                if ( x == negone )
                    return (infnan(-ERANGE));   /* -INF */
                else