mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- Added llrint() function contributed by Henning Nielsen Lund. Thank you
very much! - <unistd.h> now also include <stdio.h>, 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
This commit is contained in:
@@ -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
|
# :ts=8
|
||||||
#
|
#
|
||||||
@@ -664,6 +664,7 @@ MATH_LIB = \
|
|||||||
math_ldexpf.o \
|
math_ldexpf.o \
|
||||||
math_lgamma.o \
|
math_lgamma.o \
|
||||||
math_lgammaf.o \
|
math_lgammaf.o \
|
||||||
|
math_llrint.o \
|
||||||
math_log.o \
|
math_log.o \
|
||||||
math_log10.o \
|
math_log10.o \
|
||||||
math_log10f.o \
|
math_log10f.o \
|
||||||
|
|||||||
@@ -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
|
# :ts=8
|
||||||
#
|
#
|
||||||
@@ -21,28 +21,28 @@
|
|||||||
# These are for the cross compiler, with the operating system header files
|
# 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
|
# stored in "/V/include" and the network header files in a local directory
|
||||||
# called "netinclude".
|
# called "netinclude".
|
||||||
#SDK_INCLUDE := /V/include
|
SDK_INCLUDE := /V/include
|
||||||
#NET_INCLUDE := netinclude
|
NET_INCLUDE := netinclude
|
||||||
#CC := ppc-amigaos-gcc
|
CC := ppc-amigaos-gcc
|
||||||
#AR := ppc-amigaos-ar -q
|
AR := ppc-amigaos-ar -q
|
||||||
#RANLIB := ppc-amigaos-ranlib
|
RANLIB := ppc-amigaos-ranlib
|
||||||
#COPY := cp -a
|
COPY := cp -a
|
||||||
#DELETE := rm -rf
|
DELETE := rm -rf
|
||||||
#MAKEDIR := mkdir -p
|
MAKEDIR := mkdir -p
|
||||||
#LOG_COMMAND := 2>&1 | tee -a compiler.log
|
LOG_COMMAND := 2>&1 | tee -a compiler.log
|
||||||
|
|
||||||
# The following are for the native OS4 compiler; note that the
|
# The following are for the native OS4 compiler; note that the
|
||||||
# LOG_COMMAND should not be enabled unless you have a shell
|
# LOG_COMMAND should not be enabled unless you have a shell
|
||||||
# installed which supports it.
|
# installed which supports it.
|
||||||
SDK_INCLUDE := /SDK/Include/include_h
|
#SDK_INCLUDE := /SDK/Include/include_h
|
||||||
NET_INCLUDE := /SDK/Include/netinclude
|
#NET_INCLUDE := /SDK/Include/netinclude
|
||||||
CC := distcc gcc
|
#CC := distcc gcc
|
||||||
AR := ar -q
|
#AR := ar -q
|
||||||
RANLIB := ranlib
|
#RANLIB := ranlib
|
||||||
COPY := copy
|
#COPY := copy
|
||||||
DELETE := delete all quiet force
|
#DELETE := delete all quiet force
|
||||||
MAKEDIR := makedir all force
|
#MAKEDIR := makedir all force
|
||||||
LOG_COMMAND := *>< | tee >>compiler.log
|
#LOG_COMMAND := *>< | tee >>compiler.log
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
- Added llrint() function contributed by Henning Nielsen Lund. Thank you
|
||||||
|
very much!
|
||||||
|
|
||||||
|
- <unistd.h> now also include <stdio.h>, so that the SEEK_SET, etc. macros
|
||||||
|
are defined for lseek() to use.
|
||||||
|
|
||||||
- Added a wrapper function which handles the thread-safe stdio stream
|
- Added a wrapper function which handles the thread-safe stdio stream
|
||||||
resolution.
|
resolution.
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
* :ts=4
|
||||||
*
|
*
|
||||||
@@ -297,6 +297,7 @@ extern double hypot(double x,double y);
|
|||||||
extern double lgamma(double x);
|
extern double lgamma(double x);
|
||||||
extern double log1p(double x);
|
extern double log1p(double x);
|
||||||
extern double logb(double x);
|
extern double logb(double x);
|
||||||
|
extern long long int llrint(double x);
|
||||||
extern long int lrint(double x);
|
extern long int lrint(double x);
|
||||||
extern long int lround(double x);
|
extern long int lround(double x);
|
||||||
extern double nan(const char *tagp);
|
extern double nan(const char *tagp);
|
||||||
|
|||||||
@@ -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
|
* :ts=4
|
||||||
*
|
*
|
||||||
@@ -51,6 +51,10 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#endif /* _FCNTL_H */
|
#endif /* _FCNTL_H */
|
||||||
|
|
||||||
|
#ifndef _STDIO_H
|
||||||
|
#include <stdio.h>
|
||||||
|
#endif /* _STDIO_H */
|
||||||
|
|
||||||
#if !defined(__NO_NET_API) && !defined(_SYS_SELECT_H)
|
#if !defined(__NO_NET_API) && !defined(_SYS_SELECT_H)
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#endif /* __NO_NET_API && _SYS_SELECT_H */
|
#endif /* __NO_NET_API && _SYS_SELECT_H */
|
||||||
|
|||||||
@@ -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
|
# :ts=8
|
||||||
#
|
#
|
||||||
@@ -117,6 +117,7 @@ MATH_LIB := \
|
|||||||
math_ldexpf.o \
|
math_ldexpf.o \
|
||||||
math_lgamma.o \
|
math_lgamma.o \
|
||||||
math_lgammaf.o \
|
math_lgammaf.o \
|
||||||
|
math_llrint.o \
|
||||||
math_log.o \
|
math_log.o \
|
||||||
math_log10.o \
|
math_log10.o \
|
||||||
math_log10f.o \
|
math_log10f.o \
|
||||||
|
|||||||
128
library/math_llrint.c
Normal file
128
library/math_llrint.c
Normal file
@@ -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 <olsen (at) sourcery.han.de>
|
||||||
|
* 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 */
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user