From c18e21ee367d63c0ebdd04ea4a3b780c4bb19699 Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Thu, 12 Aug 2004 12:31:29 +0000 Subject: [PATCH] - Added "math_logb.c"; I still have to verify that it works as expected. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14705 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- library/GNUmakefile.68k | 3 +- library/GNUmakefile.os4 | 3 +- library/include/math.h | 3 +- library/math_headers.h | 3 +- library/math_logb.c | 136 ++++++++++++++++++++++++++++++++++++++++ library/releasenotes | 3 + library/smakefile | 3 +- 7 files changed, 149 insertions(+), 5 deletions(-) create mode 100644 library/math_logb.c diff --git a/library/GNUmakefile.68k b/library/GNUmakefile.68k index 70d3d14..b49f6cc 100644 --- a/library/GNUmakefile.68k +++ b/library/GNUmakefile.68k @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.68k,v 1.3 2004-08-07 09:15:32 obarthel Exp $ +# $Id: GNUmakefile.68k,v 1.4 2004-08-12 12:31:14 obarthel Exp $ # # :ts=8 # @@ -458,6 +458,7 @@ MATH_LIB = \ math_ldexp.o \ math_log.o \ math_log10.o \ + math_logb.o \ math_modf.o \ math_pow.o \ math_rint.o \ diff --git a/library/GNUmakefile.os4 b/library/GNUmakefile.os4 index 19c7a11..7f481aa 100644 --- a/library/GNUmakefile.os4 +++ b/library/GNUmakefile.os4 @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.os4,v 1.3 2004-08-07 09:15:32 obarthel Exp $ +# $Id: GNUmakefile.os4,v 1.4 2004-08-12 12:31:15 obarthel Exp $ # # :ts=8 # @@ -450,6 +450,7 @@ MATH_LIB = \ math_ldexp.o \ math_log.o \ math_log10.o \ + math_logb.o \ math_modf.o \ math_pow.o \ math_rint.o \ diff --git a/library/include/math.h b/library/include/math.h index 79bdc2c..d2e8471 100644 --- a/library/include/math.h +++ b/library/include/math.h @@ -1,5 +1,5 @@ /* - * $Id: math.h,v 1.2 2004-08-07 09:15:33 obarthel Exp $ + * $Id: math.h,v 1.3 2004-08-12 12:31:29 obarthel Exp $ * * :ts=4 * @@ -89,6 +89,7 @@ extern double rint(double x); extern float rintf(float x); extern int isinf(double x); extern int isnan(double x); +extern double logb(double x); /****************************************************************************/ diff --git a/library/math_headers.h b/library/math_headers.h index 7cd574b..7a2cfb0 100644 --- a/library/math_headers.h +++ b/library/math_headers.h @@ -1,5 +1,5 @@ /* - * $Id: math_headers.h,v 1.1.1.1 2004-07-26 16:30:45 obarthel Exp $ + * $Id: math_headers.h,v 1.2 2004-08-12 12:31:16 obarthel Exp $ * * :ts=4 * @@ -38,6 +38,7 @@ #include #include +#include #include /****************************************************************************/ diff --git a/library/math_logb.c b/library/math_logb.c new file mode 100644 index 0000000..c2d74a3 --- /dev/null +++ b/library/math_logb.c @@ -0,0 +1,136 @@ +/* + * $Id: math_logb.c,v 1.1 2004-08-12 12:31:16 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2004 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. + * + * + * PowerPC math library based in part on work by Sun Microsystems + * 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 _MATH_HEADERS_H +#include "math_headers.h" +#endif /* _MATH_HEADERS_H */ + +/****************************************************************************/ + +#if defined(FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +#if defined(IEEE_FLOATING_POINT_SUPPORT) || defined(M68881_FLOATING_POINT_SUPPORT) + +/****************************************************************************/ + +INLINE static const double +__logb(double x) +{ + double result; + + result = log(x) / log(FLT_RADIX); + + return(result); +} + +#endif /* IEEE_FLOATING_POINT_SUPPORT || M68881_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +#if defined(PPC_FLOATING_POINT_SUPPORT) + +INLINE static const double +__logb(double x) +{ + unsigned int lx,ix; + + EXTRACT_WORDS(ix,lx,x); + + ix &= 0x7fffffff; /* high |x| */ + if((ix|lx)==0) + return -1.0/fabs(x); + + if(ix>=0x7ff00000) + return x*x; + + if((ix>>=20)==0) /* IEEE 754 logb */ + return -1022.0; + else + return (double) (ix-1023); +} + +#endif /* PPC_FLOATING_POINT_SUPPORT */ + +/****************************************************************************/ + +double +logb(double x) +{ + double result; + + int sign; + + if(x == 0.0) + { + result = -HUGE_VAL; + goto out; + } + + if(isnan(x)) + { + result = x; + goto out; + } + + sign = isinf(x); + if(sign != 0) + { + if(sign < 0) + result = (-x); + else + result = x; + + goto out; + } + + result = __logb(x); + + out: + + return(result); +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ diff --git a/library/releasenotes b/library/releasenotes index 106a370..018c22b 100644 --- a/library/releasenotes +++ b/library/releasenotes @@ -1,3 +1,6 @@ +- Added "math_logb.c"; I still have to verify that it works as expected. + + c.lib 1.169 (8.8.2004) - Since the 'long double' data type is not really supported by the GCC diff --git a/library/smakefile b/library/smakefile index 4117a80..26c4807 100644 --- a/library/smakefile +++ b/library/smakefile @@ -1,5 +1,5 @@ # -# $Id: smakefile,v 1.4 2004-08-07 09:15:32 obarthel Exp $ +# $Id: smakefile,v 1.5 2004-08-12 12:31:27 obarthel Exp $ # # :ts=8 # @@ -195,6 +195,7 @@ MATH_OBJ = \ math_ldexp.o \ math_log.o \ math_log10.o \ + math_logb.o \ math_modf.o \ math_pow.o \ math_rint.o \