Add logbl(3) to libm.

This commit is contained in:
das 2007-12-17 03:53:38 +00:00
parent 42e5c27a87
commit d717f8cf06
9 changed files with 184 additions and 32 deletions

View File

@ -78,8 +78,8 @@ SYMBOL_MAPS= ${SYM_MAPS}
COMMON_SRCS+= s_copysignl.c s_fabsl.c s_modfl.c
.if ${LDBL_PREC} != 53
# If long double != double use these; otherwise, we alias the double versions.
COMMON_SRCS+= s_fmal.c s_frexpl.c s_nanl.c s_nextafterl.c s_nexttoward.c \
s_scalbnl.c
COMMON_SRCS+= s_fmal.c s_frexpl.c s_logbl.c s_nanl.c \
s_nextafterl.c s_nexttoward.c s_scalbnl.c
.endif
# C99 complex functions
@ -146,7 +146,7 @@ MLINKS+=hypot.3 cabs.3 hypot.3 cabsf.3 hypot.3 hypotf.3
MLINKS+=ieee_test.3 scalb.3 ieee_test.3 scalbf.3
MLINKS+=ieee_test.3 significand.3 ieee_test.3 significandf.3
MLINKS+=ilogb.3 ilogbf.3 ilogb.3 ilogbl.3 \
ilogb.3 logb.3 ilogb.3 logbf.3
ilogb.3 logb.3 ilogb.3 logbf.3 ilogb.3 logbl.3
MLINKS+=j0.3 j1.3 j0.3 jn.3 j0.3 y0.3 j0.3 y1.3 j0.3 y1f.3 j0.3 yn.3
MLINKS+=j0.3 j0f.3 j0.3 j1f.3 j0.3 jnf.3 j0.3 y0f.3 j0.3 ynf.3
MLINKS+=lgamma.3 gamma.3 lgamma.3 gammaf.3 lgamma.3 lgammaf.3 lgamma.3 tgamma.3

View File

@ -190,6 +190,7 @@ FBSD_1.1 {
cargf;
csqrt;
csqrtf;
logbl;
nan;
nanf;
nanl;

View File

@ -1,6 +1,7 @@
# $FreeBSD$
ARCH_SRCS = e_sqrt.S e_sqrtf.S s_llrint.S s_llrintf.S s_lrint.S s_lrintf.S \
ARCH_SRCS = e_sqrt.S e_sqrtf.S s_llrint.S s_llrintf.S \
s_logbl.S s_lrint.S s_lrintf.S \
s_remquo.S s_remquof.S s_scalbn.S s_scalbnf.S s_scalbnl.S
LDBL_PREC = 64
SYM_MAPS += ${.CURDIR}/amd64/Symbol.map

44
lib/msun/amd64/s_logbl.S Normal file
View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 1993,94 Winning Strategies, Inc.
* 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 Winning Strategies, Inc.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* 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.
*/
/*
* Written by:
* J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
*/
#include <machine/asm.h>
RCSID("$FreeBSD$")
ENTRY(logbl)
fldt 4(%esp)
fxtract
fstp %st
ret

View File

@ -13,7 +13,7 @@ ARCH_SRCS+= e_log10f.S e_logf.S e_remainderf.S \
s_remquof.S s_rintf.S s_scalbnf.S s_significandf.S s_truncf.S
# long double counterparts
ARCH_SRCS+= s_ceill.S s_copysignl.S s_floorl.S s_scalbnl.S s_truncl.S
ARCH_SRCS+= s_ceill.S s_copysignl.S s_floorl.S s_logbl.S s_scalbnl.S s_truncl.S
LDBL_PREC = 64 # XXX 64-bit format, but truncated to 53 bits
SYM_MAPS += ${.CURDIR}/i387/Symbol.map

44
lib/msun/i387/s_logbl.S Normal file
View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 1993,94 Winning Strategies, Inc.
* 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 Winning Strategies, Inc.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* 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.
*/
/*
* Written by:
* J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
*/
#include <machine/asm.h>
RCSID("$FreeBSD$")
ENTRY(logbl)
fldt 4(%esp)
fxtract
fstp %st
ret

View File

@ -28,7 +28,7 @@
.\" from: @(#)ieee.3 6.4 (Berkeley) 5/6/91
.\" $FreeBSD$
.\"
.Dd November 6, 2005
.Dd December 16, 2007
.Dt ILOGB 3
.Os
.Sh NAME
@ -36,7 +36,8 @@
.Nm ilogbf ,
.Nm ilogbl ,
.Nm logb ,
.Nm logbf
.Nm logbf ,
.Nm logbl
.Nd extract exponent
.Sh LIBRARY
.Lb libm
@ -52,6 +53,8 @@
.Fn logb "double x"
.Ft float
.Fn logbf "float x"
.Ft long double
.Fn logbl "long double x"
.Sh DESCRIPTION
.Fn ilogb ,
.Fn ilogbf
@ -71,9 +74,10 @@ and
returns
.Dv FP_ILOGB0 .
.Pp
.Fn logb x
.Fn logb x ,
.Fn logbf x ,
and
.Fn logbf x
.Fn logbl x
return
.Fa x Ns 's exponent
in floating\-point format with the same precision as
@ -92,32 +96,29 @@ The
.Fn ilogb ,
.Fn ilogbf ,
.Fn ilogbl ,
.Fn logb
.Fn logb ,
.Fn logbf ,
and
.Fn logbf
.Fn logbl
routines conform to
.St -isoC-99 .
.Fn logb
and
.Fn logbf
The latter three
implement the logb function recommended by
.St -ieee754 .
.Sh HISTORY
The
.Fn logb
function appeared in
.Bx 4.3 .
The
.Fn ilogb
function appeared in
.Fx 1.1.5 .
The
.Fn ilogbf
and
.Fn logbf
functions appeared in
.Fx 2.0 .
The
.Fn ilogbl
function appeared in
.Fx 5.4 .
.Bl -tag -width "Function " -compact
.It Em Function
.Em "First Appeared In"
.It Fn logb
.Bx 4.3
.It Fn ilogb
.Fx 1.1.5
.It Fn ilogbf
.Fx 2.0
.It Fn logbf
.Fx 2.0
.It Fn ilogbl
.Fx 5.4
.It Fn logbl
.Fx 8.0
.El

View File

@ -20,6 +20,8 @@ static char rcsid[] = "$FreeBSD$";
* Use ilogb instead.
*/
#include <float.h>
#include "math.h"
#include "math_private.h"
@ -42,3 +44,7 @@ logb(double x)
} else
return (double) ((ix>>20)-1023);
}
#if (LDBL_MANT_DIG == 53)
__weak_reference(logb, logbl);
#endif

55
lib/msun/src/s_logbl.c Normal file
View File

@ -0,0 +1,55 @@
/*
* From: @(#)s_ilogb.c 5.1 93/09/24
* ====================================================
* 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.
* ====================================================
*/
#ifndef lint
static char rcsid[] = "$FreeBSD$";
#endif
#include <float.h>
#include <limits.h>
#include <math.h>
#include "fpmath.h"
long double
logbl(long double x)
{
union IEEEl2bits u;
unsigned long m;
int b;
u.e = x;
if (u.bits.exp == 0) {
if ((u.bits.manl | u.bits.manh) == 0) { /* x == 0 */
u.bits.sign = 1;
return (1.0L / u.e);
}
/* denormalized */
if (u.bits.manh == 0) {
m = 1lu << (LDBL_MANL_SIZE - 1);
for (b = LDBL_MANH_SIZE; !(u.bits.manl & m); m >>= 1)
b++;
} else {
m = 1lu << (LDBL_MANH_SIZE - 1);
for (b = 0; !(u.bits.manh & m); m >>= 1)
b++;
}
#ifdef LDBL_IMPLICIT_NBIT
b++;
#endif
return ((long double)(LDBL_MIN_EXP - b - 1));
}
if (u.bits.exp < (LDBL_MAX_EXP << 1) - 1) /* normal */
return ((long double)(u.bits.exp - LDBL_MAX_EXP + 1));
else /* +/- inf or nan */
return (x * x);
}