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
This commit is contained in:
Ingo Weinhold 2005-04-01 01:10:42 +00:00
parent 07f6a74c53
commit 3aae5bd9a5
3 changed files with 159 additions and 31 deletions

View File

@ -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
;

View File

@ -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;
}

View File

@ -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 <SupportDefs.h>
#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;
}