Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 92790 invoked from network); 8 Aug 2007 13:21:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Aug 2007 13:21:15 -0000 Received: (qmail 69398 invoked by uid 500); 8 Aug 2007 13:21:14 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 69379 invoked by uid 500); 8 Aug 2007 13:21:13 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 69369 invoked by uid 99); 8 Aug 2007 13:21:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Aug 2007 06:21:13 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Aug 2007 13:21:14 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D3F751A981A; Wed, 8 Aug 2007 06:20:53 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r563851 - in /activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang: Math.cpp Math.h Date: Wed, 08 Aug 2007 13:20:53 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070808132053.D3F751A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tabish Date: Wed Aug 8 06:20:52 2007 New Revision: 563851 URL: http://svn.apache.org/viewvc?view=rev&rev=563851 Log: http://issues.apache.org/activemq/browse/AMQCPP-103 Implementing more of the Math functions Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Math.cpp activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Math.h Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Math.cpp URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Math.cpp?view=diff&rev=563851&r1=563850&r2=563851 ============================================================================== --- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Math.cpp (original) +++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Math.cpp Wed Aug 8 06:20:52 2007 @@ -197,6 +197,23 @@ } //////////////////////////////////////////////////////////////////////////////// +double Math::expm1( double value ) { + + if( Double::isNaN( value ) ) { + return Double::NaN; + } else if( value == Double::POSITIVE_INFINITY ) { + return Double::POSITIVE_INFINITY; + } else if( value == Double::NEGATIVE_INFINITY ) { + return -1.0; + } else if( value > 0 || value < 0 ) { + return expm1( value ); + } + + // +-0.0 + return value; +} + +//////////////////////////////////////////////////////////////////////////////// float Math::min( float a, float b ) { if( a > b ) { @@ -352,15 +369,17 @@ if( Double::isNaN( value ) || Double::isInfinite( value ) ) { return value; - } else if( value == 0.0 || value == -0.0 ) { - return value; + } else if( value > 0 || value < 0 ) { + return std::floor( value ); } - return std::floor( value ); + // +-0.0 + return value; } //////////////////////////////////////////////////////////////////////////////// int Math::round( float value ) { + if( Float::isNaN( value ) ) { return 0; } @@ -376,4 +395,101 @@ } return (long long)Math::floor( value + 0.5 ); +} + +//////////////////////////////////////////////////////////////////////////////// +double Math::IEEEremainder( double f1, double f2 ) { + + if( Double::isNaN( f1 ) || Double::isNaN( f2 ) || + Double::isInfinite( f1 ) || !( f2 < 0 || f2 > 0 ) ) { + return Double::NaN; + } else if( Double::isInfinite( f2 ) ) { + return f1; + } + + return remainder( f1, f2 ); +} + +//////////////////////////////////////////////////////////////////////////////// +float Math::signum( float value ) { + + if( Float::isNaN( value ) ) { + return Float::NaN; + } else if( value > 0 ) { + return 1.0; + } else if( value < 0 ) { + return -1.0; + } + + return value; +} + +//////////////////////////////////////////////////////////////////////////////// +double Math::signum( double value ) { + + if( Double::isNaN( value ) ) { + return Double::NaN; + } else if( value > 0 ) { + return 1.0; + } else if( value < 0 ) { + return -1.0; + } + + return value; +} + +//////////////////////////////////////////////////////////////////////////////// +double Math::hypot( double x, double y ) { + + if( Double::isInfinite( x ) || Double::isInfinite( y ) ) { + return Double::POSITIVE_INFINITY; + } else if( Double::isNaN( x ) || Double::isNaN( y ) ) { + return Double::NaN; + } + + return hypot( x, y ); +} + +//////////////////////////////////////////////////////////////////////////////// +double Math::pow( double base, double exp ) { + + if( !( exp < 0 || exp > 0 ) ) { + return 1.0; + } else if( Double::isNaN( exp ) ) { + return Double::NaN; + } else if( Double::isNaN( base ) && ( exp < 0 || exp > 0 ) ) { + return Double::NaN; + } + + return std::pow( base, exp ); +} + +//////////////////////////////////////////////////////////////////////////////// +float Math::ulp( float value ) { + + if( Float::isNaN( value ) ) { + return Float::NaN; + } else if( Float::isInfinite( value ) ) { + return Float::POSITIVE_INFINITY; + } else if( value == Float::MAX_VALUE || value == -Float::MAX_VALUE ) { + return (float)pow( 2, 104 ); + } + + value = abs( value ); + return nextafterf( value, Float::MAX_VALUE ) - value; +} + +//////////////////////////////////////////////////////////////////////////////// +double Math::ulp( double value ) { + + if( Double::isNaN( value ) ) { + return Double::NaN; + } else if( Double::isInfinite( value ) ) { + return Double::POSITIVE_INFINITY; + } else if( value == Double::MAX_VALUE || value == -Double::MAX_VALUE ) { + return pow( 2, 971 ); + } + + value = abs( value ); + return nextafterf( value, Double::MAX_VALUE ) - value; } Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Math.h URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Math.h?view=diff&rev=563851&r1=563850&r2=563851 ============================================================================== --- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Math.h (original) +++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Math.h Wed Aug 8 06:20:52 2007 @@ -301,6 +301,24 @@ static double sqrt( double value ); /** + * Returns the value of the first argument raised to the power of the second + * argument. Special cases: + * + * o If the second argument is positive or negative zero, then the result + * is 1.0. + * o If the second argument is 1.0, then the result is the same as the first + * argument. + * o If the second argument is NaN, then the result is NaN. + * o If the first argument is NaN and the second argument is nonzero, + * then the result is NaN. + * + * @param base - the base + * @param exp - the exponent + * @return the base raised to the power of exp. + */ + static double pow( double base, double exp ); + + /** * Returns the double value that is closest in value to the argument and * is equal to a mathematical integer. If two double values that are * mathematical integers are equally close, the result is the integer @@ -573,6 +591,27 @@ static long long round( double value ); /** + * Computes the remainder operation on two arguments as prescribed by the + * IEEE 754 standard. The remainder value is mathematically equal to + * f1 - f2 × n, where n is the mathematical integer closest to the exact + * mathematical value of the quotient f1/f2, and if two mathematical + * integers are equally close to f1/f2, then n is the integer that is even. + * If the remainder is zero, its sign is the same as the sign of the first + * argument. Special cases: + * + * o If either argument is NaN, or the first argument is infinite, or the + * second argument is positive zero or negative zero, then the result is + * NaN. + * o If the first argument is finite and the second argument is infinite, + * then the result is the same as the first argument. + * + * @param f1 - the dividend. + * @param f2 - the divisor + * @return the IEEE remainder of value + */ + static double IEEEremainder( double f1, double f2 ); + + /** * Returns a double value with a positive sign, greater than or equal to 0.0 * and less than 1.0. Returned values are chosen pseudorandomly with * (approximately) uniform distribution from that range. @@ -604,6 +643,64 @@ static double exp( double value ); /** + * Returns e^x - 1. Note that for values of x near 0, the exact sum of + * expm1(x) + 1 is much closer to the true result of ex than exp(x). + * Special cases: + * + * o If the argument is NaN, the result is NaN. + * o If the argument is positive infinity, then the result is positive infinity. + * o If the argument is negative infinity, then the result is -1.0. + * o If the argument is zero, then the result is a zero with the same sign as + * the argument. + * + * @param the value to raise e^x - 1 + * @returns the value ex - 1. + */ + static double expm1( double value ); + + /** + * Returns sqrt(x^2 + y^2) without intermediate overflow or underflow. + * Special cases: + * + * If either argument is infinite, then the result is positive infinity. + * If either argument is NaN and neither argument is infinite, then the + * result is NaN. + * + * @param x - an argument + * @param y - another argument + * @returns the sqrt(x^2 + y^2) without intermediate overflow or underflow + */ + static double hypot( double x, double y ); + + /** + * Returns the signum function of the argument; zero if the argument is zero, + * 1.0f if the argument is greater than zero, -1.0f if the argument is less + * than zero. Special Cases: + * + * o If the argument is NaN, then the result is NaN. + * o If the argument is positive zero or negative zero, then the result is + * the same as the argument. + * + * @param value - the floating-point value whose signum is to be returned + * @returns the signum function of the argument + */ + static float signum( float value ); + + /** + * Returns the signum function of the argument; zero if the argument is zero, + * 1.0f if the argument is greater than zero, -1.0f if the argument is less + * than zero. Special Cases: + * + * o If the argument is NaN, then the result is NaN. + * o If the argument is positive zero or negative zero, then the result is + * the same as the argument. + * + * @param value - the floating-point value whose signum is to be returned + * @returns the signum function of the argument + */ + static double signum( double value ); + + /** * Returns the measure in radians of the supplied degree angle * @param angdeg - an angle in degrees * @return the radian measure of the angle. @@ -617,9 +714,45 @@ * @param angrad - an angle in radians * @return the degree measure of the angle. */ - double toDegrees( double angrad ) { + static double toDegrees( double angrad ) { return angrad * 180 / PI; } + + /** + * Returns the size of an ulp of the argument. An ulp of a float value is + * the positive distance between this floating-point value and the float + * value next larger in magnitude. Note that for non-NaN x, ulp(-x) == ulp(x). + * Special Cases: + * + * o If the argument is NaN, then the result is NaN. + * o If the argument is positive or negative infinity, then the result is + * positive infinity. + * o If the argument is positive or negative zero, then the result is + * Float::MIN_VALUE. + * o If the argument is ±Float::MAX_VALUE, then the result is equal to 2^104. + * + * @param value - the floating-point value whose ulp is to be returned + * @returns the size of an ulp of the argument + */ + static float ulp( float value ); + + /** + * Returns the size of an ulp of the argument. An ulp of a double value is + * the positive distance between this floating-point value and the double + * value next larger in magnitude. Note that for non-NaN x, ulp(-x) == ulp(x). + * Special Cases: + * + * o If the argument is NaN, then the result is NaN. + * o If the argument is positive or negative infinity, then the result is + * positive infinity. + * o If the argument is positive or negative zero, then the result is + * Double::MIN_VALUE. + * o If the argument is ±Float::MAX_VALUE, then the result is equal to 2^971. + * + * @param value - the floating-point value whose ulp is to be returned + * @returns the size of an ulp of the argument + */ + static double ulp( double value ); };