From 5ccaf4b804534527f334d250be87a160663335da Mon Sep 17 00:00:00 2001 From: joerg Date: Thu, 28 Jul 2011 22:32:28 +0000 Subject: [PATCH] Add ilogbl(3). --- distrib/sets/lists/comp/mi | 5 ++- include/math.h | 4 +- lib/libm/Makefile | 10 ++--- lib/libm/arch/i387/s_ilogbl.S | 24 +++++++++++ lib/libm/man/ilogb.3 | 17 ++++---- lib/libm/src/s_ilogb.c | 6 ++- lib/libm/src/s_ilogbl.c | 76 +++++++++++++++++++++++++++++++++++ 7 files changed, 126 insertions(+), 16 deletions(-) create mode 100644 lib/libm/arch/i387/s_ilogbl.S create mode 100644 lib/libm/src/s_ilogbl.c diff --git a/distrib/sets/lists/comp/mi b/distrib/sets/lists/comp/mi index 3ab9e6655adf..230d2f6c9858 100644 --- a/distrib/sets/lists/comp/mi +++ b/distrib/sets/lists/comp/mi @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1648 2011/07/28 21:10:25 joerg Exp $ +# $NetBSD: mi,v 1.1649 2011/07/28 22:32:28 joerg Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -6782,6 +6782,7 @@ ./usr/share/man/cat3/ilog2.0 comp-c-catman .cat ./usr/share/man/cat3/ilogb.0 comp-c-catman .cat ./usr/share/man/cat3/ilogbf.0 comp-c-catman .cat +./usr/share/man/cat3/ilogbl.0 comp-c-catman .cat ./usr/share/man/cat3/imaxabs.0 comp-c-catman .cat ./usr/share/man/cat3/imaxdiv.0 comp-c-catman .cat ./usr/share/man/cat3/inch.0 comp-c-catman .cat @@ -12877,6 +12878,7 @@ ./usr/share/man/html3/ilog2.html comp-c-htmlman html ./usr/share/man/html3/ilogb.html comp-c-htmlman html ./usr/share/man/html3/ilogbf.html comp-c-htmlman html +./usr/share/man/html3/ilogbl.html comp-c-htmlman html ./usr/share/man/html3/imaxabs.html comp-c-htmlman html ./usr/share/man/html3/imaxdiv.html comp-c-htmlman html ./usr/share/man/html3/inch.html comp-c-htmlman html @@ -18891,6 +18893,7 @@ ./usr/share/man/man3/ilog2.3 comp-c-man .man ./usr/share/man/man3/ilogb.3 comp-c-man .man ./usr/share/man/man3/ilogbf.3 comp-c-man .man +./usr/share/man/man3/ilogbl.3 comp-c-man .man ./usr/share/man/man3/imaxabs.3 comp-c-man .man ./usr/share/man/man3/imaxdiv.3 comp-c-man .man ./usr/share/man/man3/inch.3 comp-c-man .man diff --git a/include/math.h b/include/math.h index f6644855a21d..ec6ecba6c32c 100644 --- a/include/math.h +++ b/include/math.h @@ -1,4 +1,4 @@ -/* $NetBSD: math.h,v 1.55 2011/07/26 16:10:15 joerg Exp $ */ +/* $NetBSD: math.h,v 1.56 2011/07/28 22:32:28 joerg Exp $ */ /* * ==================================================== @@ -498,6 +498,8 @@ int __isnanl(long double); int __signbitl(long double); #endif +int ilogbl(long double); +long double logbl(long double); long double scalbnl(long double, int); __END_DECLS diff --git a/lib/libm/Makefile b/lib/libm/Makefile index b2f039a84ff5..adad1b7e036c 100644 --- a/lib/libm/Makefile +++ b/lib/libm/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.114 2011/07/28 21:10:29 joerg Exp $ +# $NetBSD: Makefile,v 1.115 2011/07/28 22:32:28 joerg Exp $ # # @(#)Makefile 5.1beta 93/09/24 # @@ -69,8 +69,8 @@ ARCH_SRCS = e_acos.S e_asin.S e_atan2.S e_exp.S e_expf.S e_fmod.S e_log.S \ e_remainderf.S e_scalb.S e_scalbf.S e_sqrt.S e_sqrtf.S s_atan.S \ s_atanf.S s_ceil.S s_ceilf.S s_copysign.S s_copysignf.S s_cos.S \ s_cosf.S s_finite.S s_finitef.S s_floor.S s_floorf.S s_ilogb.S \ - s_ilogbf.S s_log1p.S s_log1pf.S s_logb.S s_logbf.S s_rint.S \ - s_rintf.S s_scalbn.S s_scalbnf.S s_significand.S \ + s_ilogbf.S s_ilogbl.S s_log1p.S s_log1pf.S s_logb.S s_logbf.S \ + s_rint.S s_rintf.S s_scalbn.S s_scalbnf.S s_significand.S \ s_significandf.S s_sin.S s_sinf.S s_tan.S s_tanf.S lrint.S # do not pick up the i387 asm version, it is incorrect s_modf.o s_modf.pico s_modf.po s_modf.d: s_modf.c @@ -137,7 +137,7 @@ COMMON_SRCS+= e_acos.c e_acosf.c e_acosh.c e_acoshf.c e_asin.c e_asinf.c \ s_ceilf.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_floor.c s_floorf.c s_frexpf.c s_ilogb.c s_ilogbf.c s_ilogbl.c \ s_isinff.c s_isnanf.c s_ldexpf.c s_lib_version.c s_log1p.c \ s_log1pf.c s_logb.c s_logbf.c s_matherr.c s_modff.c s_nextafter.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 \ @@ -257,7 +257,7 @@ MLINKS+=ieee.3 finite.3 ieee.3 finitef.3 \ MLINKS+=ieee_test.3 logb.3 ieee_test.3 logbf.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 +MLINKS+=ilogb.3 ilogbf.3 ilogb.3 ilogbl.3 MLINKS+=isinff.3 isnanf.3 MLINKS+=j0.3 j0f.3 j0.3 j1.3 j0.3 j1f.3 j0.3 jn.3 j0.3 jnf.3 \ j0.3 y0.3 j0.3 y0f.3 j0.3 y1.3 j0.3 y1f.3 j0.3 yn.3 j0.3 ynf.3 diff --git a/lib/libm/arch/i387/s_ilogbl.S b/lib/libm/arch/i387/s_ilogbl.S new file mode 100644 index 000000000000..3932dc4910d3 --- /dev/null +++ b/lib/libm/arch/i387/s_ilogbl.S @@ -0,0 +1,24 @@ +/* + * Written by J.T. Conklin . + * Public domain. + */ + +#include + +RCSID("$NetBSD: s_ilogbl.S,v 1.1 2011/07/28 22:32:28 joerg Exp $") + +#include "abi.h" + +ENTRY(ilogbl) + fldt ARG_LONG_DOUBLE_ONE + fxtract + fstp %st +#ifdef __i386__ + pushl %eax + fistpl 0(%esp) + popl %eax +#else + fistpl -4(%rsp) + movl -4(%rsp), %eax +#endif + ret diff --git a/lib/libm/man/ilogb.3 b/lib/libm/man/ilogb.3 index e3e7ba7afaa4..9e94fee3dd65 100644 --- a/lib/libm/man/ilogb.3 +++ b/lib/libm/man/ilogb.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: ilogb.3,v 1.1 2011/05/10 06:38:33 jruoho Exp $ +.\" $NetBSD: ilogb.3,v 1.2 2011/07/28 22:32:29 joerg Exp $ .\" .\" Copyright (c) 2011 Jukka Ruohonen .\" All rights reserved. @@ -24,12 +24,13 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd May 10, 2011 +.Dd July 29, 2011 .Dt ILOGB 3 .Os .Sh NAME .Nm ilogb , -.Nm ilogbf +.Nm ilogbf , +.Nm ilogbl .Nd an unbiased exponent .Sh LIBRARY .Lb libm @@ -39,11 +40,14 @@ .Fn ilogb "double x" .Ft int .Fn ilogbf "float x" +.Ft int +.Fn ilogbl "long double x" .Sh DESCRIPTION The -.Fn ilogb -and +.Fn ilogb , .Fn ilogbf +and +.Fn ilogbl functions return the exponent of the non-zero real floating-point number .Fa x as a signed integer value. @@ -105,6 +109,3 @@ nor .Dv FP_ILOGBNAN is defined currently in .Nx . -Furthermore, the -.Vt long double -variant of the functions is not yet supported. diff --git a/lib/libm/src/s_ilogb.c b/lib/libm/src/s_ilogb.c index 29befbb3b163..b000997b2177 100644 --- a/lib/libm/src/s_ilogb.c +++ b/lib/libm/src/s_ilogb.c @@ -12,7 +12,7 @@ #include #if defined(LIBM_SCCS) && !defined(lint) -__RCSID("$NetBSD: s_ilogb.c,v 1.12 2002/05/26 22:01:56 wiz Exp $"); +__RCSID("$NetBSD: s_ilogb.c,v 1.13 2011/07/28 22:32:29 joerg Exp $"); #endif /* ilogb(double x) @@ -24,6 +24,10 @@ __RCSID("$NetBSD: s_ilogb.c,v 1.12 2002/05/26 22:01:56 wiz Exp $"); #include "math.h" #include "math_private.h" +#ifndef __HAVE_LONG_DOUBLE +__strong_alias(ilogbl,ilogb) +#endif + int ilogb(double x) { diff --git a/lib/libm/src/s_ilogbl.c b/lib/libm/src/s_ilogbl.c new file mode 100644 index 000000000000..fd8805f5b88b --- /dev/null +++ b/lib/libm/src/s_ilogbl.c @@ -0,0 +1,76 @@ +/* $NetBSD: s_ilogbl.c,v 1.1 2011/07/28 22:32:29 joerg Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Joerg Sonnenberger. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#include +__RCSID("$NetBSD: s_ilogbl.c,v 1.1 2011/07/28 22:32:29 joerg Exp $"); + +#include "namespace.h" + +#include +#include +#include + +#ifdef __HAVE_LONG_DOUBLE + +#if LDBL_MANT_DIG == 64 +#define FROM_UNDERFLOW 0x1p65L +#elif LDBL_MANT_DIG == 113 +#define FROM_UNDERFLOW 0x1p114L +#else +#error Unsupported long double format +#endif + +int +ilogbl(long double x) +{ + union ieee_ext_u u; + + if (x == 0.0L) + return 0x80000001; /* ilogbl(0) = 0x80000001 */ + + u.extu_ld = x; + + if (u.extu_ext.ext_exp == EXT_EXP_INFNAN) + return 0x7fffffff; + + if (u.extu_ext.ext_exp == 0) { + /* + * Scale denormalized numbers slightly, + * so that they are normal. + */ + u.extu_ld *= FROM_UNDERFLOW; + return u.extu_ext.ext_exp - EXT_EXP_BIAS - LDBL_MANT_DIG - 1; + } + return u.extu_ext.ext_exp - EXT_EXP_BIAS; + +} + +#endif