Index: libm/common/isgreater.c =================================================================== RCS file: libm/common/isgreater.c diff -N libm/common/isgreater.c --- /dev/null 2006-11-30 19:00:00.000000000 -0500 +++ libm/common/isgreater.c 2009-02-25 23:35:40.000000000 -0500 @@ -0,0 +1,75 @@ +/* isgreater.c: This file contains no source code, but rather only the + * man-page comments. All of the documented "functions" are actually macros + * defined in math.h (q.v.). */ +/* +FUNCTION +<>, <>, <>, <>, <>, and <>--comparison macros +INDEX + isgreater +INDEX + isgreaterequal +INDEX + isless +INDEX + islessequal +INDEX + islessgreater +INDEX + isunordered + +ANSI_SYNOPSIS + #include + int isgreater(real-floating <[x]>, real-floating <[y]>); + int isgreaterequal(real-floating <[x]>, real-floating <[y]>); + int isless(real-floating <[x]>, real-floating <[y]>); + int islessequal(real-floating <[x]>, real-floating <[y]>); + int islessgreater(real-floating <[x]>, real-floating <[y]>); + int isunordered(real-floating <[x]>, real-floating <[y]>); + +DESCRIPTION +<>, <>, <>, <>, +<>, and <> are macros defined for use in +comparing floating-point numbers without raising any floating-point +exceptions. + +The relational operators (i.e. <, >, <=, and >=) support the usual mathematical +relationships between numeric values. For any ordered pair of numeric +values exactly one of the relationships--less, greater, and equal--is +true. Relational operators may raise the "invalid" floating-point +exception when argument values are NaNs. For a NaN and a numeric value, or +for two NaNs, just the unordered relationship is true (i.e., if one or both +of the arguments a NaN, the relationship is called unordered). The specified +macros are quiet (non floating-point exception raising) versions of the +relational operators, and other comparison macros that facilitate writing +efficient code that accounts for NaNs without suffering the "invalid" +floating-point exception. In the synopses shown, "real-floating" indicates +that the argument is an expression of real floating type. + +Please note that saying that the macros do not raise floating-point +exceptions, it is referring to the function that they are performing. It +is certainly possible to give them an expression which causes an exception. +For example: +o+ +o NaN < 1.0 + causes an "invalid" exception, +o isless(NaN, 1.0) + does not, and +o isless(NaN*0., 1.0) + causes an exception due to the "NaN*0.", but not from the +resultant reduced comparison of isless(NaN, 1.0). +o- + +RETURNS +@comment Formatting note: "$@" forces a new line +No floating-point exceptions are raised for any of the macros.@* +The <> macro returns the value of (x) > (y).@* +The <> macro returns the value of (x) >= (y).@* +The <> macro returns the value of (x) < (y).@* +The <> macro returns the value of (x) <= (y).@* +The <> macro returns the value of (x) < (y) || (x) > (y).@* +The <> macro returns 1 if either of its arguments is NaN and 0 otherwise. + +PORTABILITY +C99, POSIX. + +*/ Index: libm/common/log2.c =================================================================== RCS file: libm/common/log2.c diff -N libm/common/log2.c --- /dev/null 2006-11-30 19:00:00.000000000 -0500 +++ libm/common/log2.c 2009-02-17 23:42:49.000000000 -0500 @@ -0,0 +1,40 @@ +/* log2.c: This file contains no source code, but rather only the + * man-page comments. All of the documented "functions" are actually macros + * defined in math.h (q.v.). */ +/* +FUNCTION +<>, <>--base 2 logarithms + +INDEX + log2 +INDEX + log2f + +ANSI_SYNOPSIS + #include + int log2(double <[x]>); + int log2f(float <[x]>); + +DESCRIPTION +The <> functions compute the base-2 logarithm of <[x]>. A domain error +occurs if the argument is less than zero. A range error occurs if the +argument is zero. + +The Newlib implementations are not full, intrinisic calculations, but +rather are derivative macros defined in math.h: +. #define log2(x) (log (x) / _M_LOG2_E) +. #define log2f(x) (logf (x) / (float) _M_LOG2_E) + +RETURNS +The <> functions return +@ifnottex +<)>>. +@end ifnottex +@tex +$log_2(x)$. +@end tex + +PORTABILITY +C99, POSIX. + +*/ Index: libm/common/s_llround.c =================================================================== RCS file: libm/common/s_llround.c diff -N libm/common/s_llround.c --- /dev/null 2006-11-30 19:00:00.000000000 -0500 +++ libm/common/s_llround.c 2009-01-18 22:58:03.000000000 -0500 @@ -0,0 +1,68 @@ +/* lround adapted to be llround for Newlib, 2009 by Craig Howland. */ +/* + * ==================================================== + * 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 "fdlibm.h" + +#ifndef _DOUBLE_IS_32BITS + +long long int +llround(double x) +{ + __int32_t sign, exponent_less_1023; + /* Most significant word, least significant word. */ + __uint32_t msw, lsw; + long long int result; + + EXTRACT_WORDS(msw, lsw, x); + + /* Extract sign. */ + sign = ((msw & 0x80000000) ? -1 : 1); + /* Extract exponent field. */ + exponent_less_1023 = ((msw & 0x7ff00000) >> 20) - 1023; + msw &= 0x000fffff; + msw |= 0x00100000; + + if (exponent_less_1023 < 20) + { + if (exponent_less_1023 < 0) + { + if (exponent_less_1023 < -1) + return 0; + else + return sign; + } + else + { + msw += 0x80000 >> exponent_less_1023; + result = msw >> (20 - exponent_less_1023); + } + } + else if (exponent_less_1023 < (8 * sizeof (long long int)) - 1) + { + if (exponent_less_1023 >= 52) + result = ((long long int) msw << (exponent_less_1023 - 20)) | (lsw << (exponent_less_1023 - 52)); + else + { + unsigned int tmp = lsw + (0x80000000 >> (exponent_less_1023 - 20)); + if (tmp < lsw) + ++msw; + result = ((long long int) msw << (exponent_less_1023 - 20)) | (tmp >> (52 - exponent_less_1023)); + } + } + else + /* Result is too large to be represented by a long long int. */ + return (long long int)x; + + return sign * result; +} + +#endif /* _DOUBLE_IS_32BITS */ Index: libm/common/sf_llround.c =================================================================== RCS file: libm/common/sf_llround.c diff -N libm/common/sf_llround.c --- /dev/null 2006-11-30 19:00:00.000000000 -0500 +++ libm/common/sf_llround.c 2009-01-18 23:02:22.000000000 -0500 @@ -0,0 +1,55 @@ +/* lroundf adapted to be llroundf for Newlib, 2009 by Craig Howland. */ +/* + * ==================================================== + * 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 "fdlibm.h" + +long long int +llroundf(float x) +{ + __int32_t exponent_less_127; + __uint32_t w; + long long int result; + __int32_t sign; + + GET_FLOAT_WORD (w, x); + exponent_less_127 = ((w & 0x7f800000) >> 23) - 127; + sign = (w & 0x80000000) != 0 ? -1 : 1; + w &= 0x7fffff; + w |= 0x800000; + + if (exponent_less_127 < (int)((8 * sizeof (long long int)) - 1)) + { + if (exponent_less_127 < 0) + return exponent_less_127 < -1 ? 0 : sign; + else if (exponent_less_127 >= 23) + result = (long long int) w << (exponent_less_127 - 23); + else + { + w += 0x400000 >> exponent_less_127; + result = w >> (23 - exponent_less_127); + } + } + else + return (long long int) x; + + return sign * result; +} + +#ifdef _DOUBLE_IS_32BITS + +long long int +llround(double x) +{ + return llroundf((float) x); +} + +#endif /* defined(_DOUBLE_IS_32BITS) */