From e5a2a2b4519f28de888929c866446dcb1e07bba7 Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Sat, 6 Jan 2007 10:09:49 +0000 Subject: [PATCH] - Added llrint() function contributed by Henning Nielsen Lund. Thank you very much! - now also include , so that the SEEK_SET, etc. macros are defined for lseek() to use. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15172 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- library/GNUmakefile.68k | 3 +- library/GNUmakefile.os4 | 38 ++++++------ library/changes | 6 ++ library/include/math.h | 3 +- library/include/unistd.h | 6 +- library/libm.gmk | 3 +- library/math_llrint.c | 128 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 164 insertions(+), 23 deletions(-) create mode 100644 library/math_llrint.c diff --git a/library/GNUmakefile.68k b/library/GNUmakefile.68k index 8cf4c72..9b40b48 100644 --- a/library/GNUmakefile.68k +++ b/library/GNUmakefile.68k @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.68k,v 1.100 2006-11-16 14:39:23 obarthel Exp $ +# $Id: GNUmakefile.68k,v 1.101 2007-01-06 10:09:48 obarthel Exp $ # # :ts=8 # @@ -664,6 +664,7 @@ MATH_LIB = \ math_ldexpf.o \ math_lgamma.o \ math_lgammaf.o \ + math_llrint.o \ math_log.o \ math_log10.o \ math_log10f.o \ diff --git a/library/GNUmakefile.os4 b/library/GNUmakefile.os4 index 4b1a71d..0dffe56 100644 --- a/library/GNUmakefile.os4 +++ b/library/GNUmakefile.os4 @@ -1,5 +1,5 @@ # -# $Id: GNUmakefile.os4,v 1.110 2006-11-13 09:25:28 obarthel Exp $ +# $Id: GNUmakefile.os4,v 1.111 2007-01-06 10:09:48 obarthel Exp $ # # :ts=8 # @@ -21,28 +21,28 @@ # These are for the cross compiler, with the operating system header files # stored in "/V/include" and the network header files in a local directory # called "netinclude". -#SDK_INCLUDE := /V/include -#NET_INCLUDE := netinclude -#CC := ppc-amigaos-gcc -#AR := ppc-amigaos-ar -q -#RANLIB := ppc-amigaos-ranlib -#COPY := cp -a -#DELETE := rm -rf -#MAKEDIR := mkdir -p -#LOG_COMMAND := 2>&1 | tee -a compiler.log +SDK_INCLUDE := /V/include +NET_INCLUDE := netinclude +CC := ppc-amigaos-gcc +AR := ppc-amigaos-ar -q +RANLIB := ppc-amigaos-ranlib +COPY := cp -a +DELETE := rm -rf +MAKEDIR := mkdir -p +LOG_COMMAND := 2>&1 | tee -a compiler.log # The following are for the native OS4 compiler; note that the # LOG_COMMAND should not be enabled unless you have a shell # installed which supports it. -SDK_INCLUDE := /SDK/Include/include_h -NET_INCLUDE := /SDK/Include/netinclude -CC := distcc gcc -AR := ar -q -RANLIB := ranlib -COPY := copy -DELETE := delete all quiet force -MAKEDIR := makedir all force -LOG_COMMAND := *>< | tee >>compiler.log +#SDK_INCLUDE := /SDK/Include/include_h +#NET_INCLUDE := /SDK/Include/netinclude +#CC := distcc gcc +#AR := ar -q +#RANLIB := ranlib +#COPY := copy +#DELETE := delete all quiet force +#MAKEDIR := makedir all force +#LOG_COMMAND := *>< | tee >>compiler.log ############################################################################## diff --git a/library/changes b/library/changes index 07ae28e..d8acb1c 100644 --- a/library/changes +++ b/library/changes @@ -1,3 +1,9 @@ +- Added llrint() function contributed by Henning Nielsen Lund. Thank you + very much! + +- now also include , so that the SEEK_SET, etc. macros + are defined for lseek() to use. + - Added a wrapper function which handles the thread-safe stdio stream resolution. diff --git a/library/include/math.h b/library/include/math.h index 8cc95f4..14d5f4a 100644 --- a/library/include/math.h +++ b/library/include/math.h @@ -1,5 +1,5 @@ /* - * $Id: math.h,v 1.21 2006-01-08 12:06:14 obarthel Exp $ + * $Id: math.h,v 1.22 2007-01-06 10:09:49 obarthel Exp $ * * :ts=4 * @@ -297,6 +297,7 @@ extern double hypot(double x,double y); extern double lgamma(double x); extern double log1p(double x); extern double logb(double x); +extern long long int llrint(double x); extern long int lrint(double x); extern long int lround(double x); extern double nan(const char *tagp); diff --git a/library/include/unistd.h b/library/include/unistd.h index 46b1bd1..e3efc5f 100644 --- a/library/include/unistd.h +++ b/library/include/unistd.h @@ -1,5 +1,5 @@ /* - * $Id: unistd.h,v 1.22 2006-11-13 09:51:53 obarthel Exp $ + * $Id: unistd.h,v 1.23 2007-01-06 10:09:49 obarthel Exp $ * * :ts=4 * @@ -51,6 +51,10 @@ #include #endif /* _FCNTL_H */ +#ifndef _STDIO_H +#include +#endif /* _STDIO_H */ + #if !defined(__NO_NET_API) && !defined(_SYS_SELECT_H) #include #endif /* __NO_NET_API && _SYS_SELECT_H */ diff --git a/library/libm.gmk b/library/libm.gmk index a06da9b..df971f1 100755 --- a/library/libm.gmk +++ b/library/libm.gmk @@ -1,5 +1,5 @@ # -# $Id: libm.gmk,v 1.2 2006-11-13 09:51:53 obarthel Exp $ +# $Id: libm.gmk,v 1.3 2007-01-06 10:09:48 obarthel Exp $ # # :ts=8 # @@ -117,6 +117,7 @@ MATH_LIB := \ math_ldexpf.o \ math_lgamma.o \ math_lgammaf.o \ + math_llrint.o \ math_log.o \ math_log10.o \ math_log10f.o \ diff --git a/library/math_llrint.c b/library/math_llrint.c new file mode 100644 index 0000000..d239646 --- /dev/null +++ b/library/math_llrint.c @@ -0,0 +1,128 @@ +/* + * $Id: math_llrint.c,v 1.1 2007-01-06 10:09:48 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2006 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) + +/****************************************************************************/ + +/* Adding a double, x, to 2^52 will cause the result to be rounded based on + the fractional part of x, according to the implementation's current rounding + mode. 2^52 is the smallest double that can be represented using all 52 significant + digits. */ +static const double TWO52[2]={ + 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */ + -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */ +}; + +/****************************************************************************/ + +long long int +llrint(double x) +{ + LONG i0,j0,sx; + ULONG i1; + double t; + volatile double w; + long long int result; + + EXTRACT_WORDS(i0,i1,x); + + /* Extract sign bit. */ + sx = (i0>>31)&1; + + /* Extract exponent field. */ + j0 = ((i0 & 0x7ff00000) >> 20) - 1023; + + if(j0 < 20) + { + if(j0 < -1) + return 0; + else + { + w = TWO52[sx] + x; + t = w - TWO52[sx]; + GET_HIGH_WORD(i0, t); + /* Detect the all-zeros representation of plus and + minus zero, which fails the calculation below. */ + if ((i0 & ~(1 << 31)) == 0) + return 0; + j0 = ((i0 & 0x7ff00000) >> 20) - 1023; + i0 &= 0x000fffff; + i0 |= 0x00100000; + result = i0 >> (20 - j0); + } + } + else if (j0 < (int)(8 * sizeof (long long int)) - 1) + { + if (j0 >= 52) + result = ((long long int) ((i0 & 0x000fffff) | 0x0010000) << (j0 - 20)) | + (i1 << (j0 - 52)); + else + { + w = TWO52[sx] + x; + t = w - TWO52[sx]; + EXTRACT_WORDS (i0, i1, t); + j0 = ((i0 & 0x7ff00000) >> 20) - 1023; + i0 &= 0x000fffff; + i0 |= 0x00100000; + result = ((long long int) i0 << (j0 - 20)) | (i1 >> (52 - j0)); + } + } + else + { + return (long long int) x; + } + + return sx ? -result : result; +} + +/****************************************************************************/ + +#endif /* FLOATING_POINT_SUPPORT */ + +