Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Michael Zimmermann <sigmaepsilo...@gmail.com> --- StdLib/Include/math.h | 8 ++++++ StdLib/LibC/Math/Math.inf | 1 + StdLib/LibC/Math/s_floorf.c | 64 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 StdLib/LibC/Math/s_floorf.c
diff --git a/StdLib/Include/math.h b/StdLib/Include/math.h index 3041120..2b5746b 100644 --- a/StdLib/Include/math.h +++ b/StdLib/Include/math.h @@ -304,6 +304,14 @@ double fabs(double Arg); **/ double floor(double); +/** Compute the largest integer value not greater than Arg. + + @param[in] Arg The value to compute the floor of. + + @return The largest integer value not greater than Arg, expressed as a floating-point number. +**/ +float floorf(float); + /** Compute the floating-point remainder of A1 / A2. @param[in] A1 The dividend. diff --git a/StdLib/LibC/Math/Math.inf b/StdLib/LibC/Math/Math.inf index ec5c71a..9d6c66d 100644 --- a/StdLib/LibC/Math/Math.inf +++ b/StdLib/LibC/Math/Math.inf @@ -64,6 +64,7 @@ s_fabs.c s_ceil.c s_floor.c + s_floorf.c s_trunc.c # wrapper functions diff --git a/StdLib/LibC/Math/s_floorf.c b/StdLib/LibC/Math/s_floorf.c new file mode 100644 index 0000000..d6e201f --- /dev/null +++ b/StdLib/LibC/Math/s_floorf.c @@ -0,0 +1,64 @@ +/* s_floorf.c -- float version of s_floor.c. + * Conversion to float by Ian Lance Taylor, Cygnus Support, i...@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 <LibConfig.h> +#include <sys/EfiCdefs.h> +#if defined(LIBM_SCCS) && !defined(lint) +__RCSID("$NetBSD: s_floor.c,v 1.11 2002/05/26 22:01:56 wiz Exp $"); +#endif + +/* + * 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 "math.h" +#include "math_private.h" + +static const float huge = 1.0e30; + +float +floorf(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(huge+x>(float)0.0) {/* 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(huge+x>(float)0.0) { /* 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; +} -- 2.6.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel