From 3aae5bd9a50848752ff0de23fe0c24322d5511bf Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 1 Apr 2005 01:10:42 +0000 Subject: [PATCH] Added floorf() and ceilf() (from FreeBSD, style-adjusted). Needed by the Painter. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12208 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/posix/math/Jamfile | 69 ++++++++++++++------------ src/kernel/libroot/posix/math/ceilf.c | 55 ++++++++++++++++++++ src/kernel/libroot/posix/math/floorf.c | 66 ++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 31 deletions(-) create mode 100644 src/kernel/libroot/posix/math/ceilf.c create mode 100644 src/kernel/libroot/posix/math/floorf.c diff --git a/src/kernel/libroot/posix/math/Jamfile b/src/kernel/libroot/posix/math/Jamfile index 4ec99f02bb..ee3207a036 100644 --- a/src/kernel/libroot/posix/math/Jamfile +++ b/src/kernel/libroot/posix/math/Jamfile @@ -1,37 +1,44 @@ SubDir OBOS_TOP src kernel libroot posix math ; +SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) glibc ] ; +SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) glibc include ] ; +SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) glibc include arch $(OBOS_ARCH) ] ; +SubDirHdrs [ FDirName $(SUBDIR) $(DOTDOT) glibc math ] ; + KernelMergeObject posix_math.o : - <$(SOURCE_GRIST)>acosh.c - <$(SOURCE_GRIST)>asincos.c - <$(SOURCE_GRIST)>asinh.c - <$(SOURCE_GRIST)>atan.c - <$(SOURCE_GRIST)>atan2.c - <$(SOURCE_GRIST)>atanh.c - <$(SOURCE_GRIST)>cabs.c - <$(SOURCE_GRIST)>cbrt.c - <$(SOURCE_GRIST)>cosh.c - <$(SOURCE_GRIST)>erf.c - <$(SOURCE_GRIST)>exp.c - <$(SOURCE_GRIST)>exp__E.c - <$(SOURCE_GRIST)>expm1.c - <$(SOURCE_GRIST)>floor.c - <$(SOURCE_GRIST)>fmod.c - <$(SOURCE_GRIST)>gamma.c - <$(SOURCE_GRIST)>ieee.c - <$(SOURCE_GRIST)>j0.c - <$(SOURCE_GRIST)>j1.c - <$(SOURCE_GRIST)>jn.c - <$(SOURCE_GRIST)>lgamma.c - <$(SOURCE_GRIST)>log.c - <$(SOURCE_GRIST)>log10.c - <$(SOURCE_GRIST)>log1p.c - <$(SOURCE_GRIST)>log__L.c - <$(SOURCE_GRIST)>math_globals.c - <$(SOURCE_GRIST)>pow.c - <$(SOURCE_GRIST)>sincos.c - <$(SOURCE_GRIST)>sinh.c - <$(SOURCE_GRIST)>tan.c - <$(SOURCE_GRIST)>tanh.c + acosh.c + asincos.c + asinh.c + atan.c + atan2.c + atanh.c + cabs.c + cbrt.c + ceilf.c + cosh.c + erf.c + exp.c + exp__E.c + expm1.c + floor.c + floorf.c + fmod.c + gamma.c + ieee.c + j0.c + j1.c + jn.c + lgamma.c + log.c + log10.c + log1p.c + log__L.c + math_globals.c + pow.c + sincos.c + sinh.c + tan.c + tanh.c : -fPIC -DPIC ; diff --git a/src/kernel/libroot/posix/math/ceilf.c b/src/kernel/libroot/posix/math/ceilf.c new file mode 100644 index 0000000000..11d9a5d18f --- /dev/null +++ b/src/kernel/libroot/posix/math/ceilf.c @@ -0,0 +1,55 @@ +/* s_ceilf.c -- float version of s_ceil.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ + +/* + * ==================================================== + * 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. + * ==================================================== + */ + +#include "math.h" +#include "math_private.h" + +static const float sHuge = 1.0e30; + +float +ceilf(float x) +{ + int32_t i0,j0; + u_int32_t i; + + GET_FLOAT_WORD(i0,x); + j0 = ((i0 >> 23) & 0xff) - 0x7f; + if (j0 < 23) { + if (j0 < 0) { /* raise inexact if x != 0 */ + if (sHuge + x > 0.0f) {/* return 0*sign(x) if |x|<1 */ + if (i0 < 0) + i0 = 0x80000000; + else if (i0 != 0) + i0 = 0x3f800000; + } + } else { + i = (0x007fffff) >> j0; + if ((i0 & i) == 0) + return x; /* x is integral */ + if (sHuge + x > 0.0f) { /* raise inexact flag */ + if (i0 > 0) + i0 += (0x00800000) >> j0; + i0 &= (~i); + } + } + } else { + if (j0 == 0x80) + return x + x; /* inf or NaN */ + else + return x; /* x is integral */ + } + SET_FLOAT_WORD(x, i0); + return x; +} diff --git a/src/kernel/libroot/posix/math/floorf.c b/src/kernel/libroot/posix/math/floorf.c new file mode 100644 index 0000000000..a2c7d7b344 --- /dev/null +++ b/src/kernel/libroot/posix/math/floorf.c @@ -0,0 +1,66 @@ +/* s_floorf.c -- float version of s_floor.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ + +/* + * ==================================================== + * 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. + * ==================================================== + */ + +/* + * floorf(x) + * Return x rounded toward -inf to integral value + * Method: + * Bit twiddling. + * Exception: + * Inexact flag raised if x not equal to floorf(x). + */ + +#include + +#include "math.h" +#include "math_private.h" + +static const float sHuge = 1.0e30; + +float +floorf(float x) +{ + int32 i0,j0; + uint32 i; + + GET_FLOAT_WORD(i0, x); + j0 = ((i0 >> 23) & 0xff) - 0x7f; + if (j0 < 23) { + if (j0 < 0) { /* raise inexact if x != 0 */ + if (sHuge + x > 0.0f) {/* return 0*sign(x) if |x|<1 */ + if (i0 >= 0) + i0 = 0; + else if ((i0 & 0x7fffffff) != 0) + i0 = 0xbf800000; + } + } else { + i = (0x007fffff) >> j0; + if ((i0 & i) == 0) + return x; /* x is integral */ + if (sHuge + x > 0.0f) { /* raise inexact flag */ + if (i0 < 0) + i0 += (0x00800000) >> j0; + i0 &= (~i); + } + } + } else { + if (j0 == 0x80) + return x + x; /* inf or NaN */ + else + return x; /* x is integral */ + } + SET_FLOAT_WORD(x, i0); + return x; +}