activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r563501 - in /activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang: Math.cpp Math.h
Date Tue, 07 Aug 2007 13:56:39 GMT
Author: tabish
Date: Tue Aug  7 06:56:38 2007
New Revision: 563501

URL: http://svn.apache.org/viewvc?view=rev&rev=563501
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=563501&r1=563500&r2=563501
==============================================================================
--- 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 Tue Aug  7 06:56:38
2007
@@ -33,9 +33,112 @@
 const double Math::PI = 3.141592653589793;
 
 ////////////////////////////////////////////////////////////////////////////////
+float Math::abs( float value ) {
+    return Float::intBitsToFloat( Float::floatToIntBits( value ) & 0x7FFFFFFF );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+double Math::abs( double value ) {
+    return Double::longBitsToDouble( Double::doubleToLongBits( value ) & 0x7FFFFFFFFFFFFFFFULL
);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+float Math::min( float a, float b ) {
+
+    if( a > b ) {
+        return b;
+    } else if( a < b ) {
+        return a;
+    }
+
+    // if either arg is NaN, return NaN
+    if( a != b ) {
+        return Float::NaN;
+    }
+
+    // min( +0.0,-0.0) == -0.0
+    if( a == 0.0f &&
+        ( (Float::floatToIntBits( a ) | Float::floatToIntBits( b )) & 0x80000000) !=
0) {
+
+        return 0.0f * (-1.0f);
+    }
+
+    return a;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+double Math::min( double a, double b ) {
+
+    if( a > b ) {
+        return b;
+    } else if( a < b ) {
+        return a;
+    }
+
+    // if either arg is NaN, return NaN
+    if( a != b ) {
+        return Double::NaN;
+    }
+
+    // min( +0.0,-0.0) == -0.0
+    if( a == 0.0 &&
+        ( (Double::doubleToLongBits( a ) | Double::doubleToLongBits( b )) & 0x8000000000000000ULL)
!= 0 ) {
+        return 0.0 * (-1.0);
+    }
+
+    return a;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+float Math::max( float a, float b ) {
+
+    if( a > b ) {
+        return a;
+    } else if( a < b ) {
+        return b;
+    }
+
+    // if either arg is NaN, return NaN
+    if( a != b ) {
+        return Float::NaN;
+    }
+    // max( +0.0,-0.0) == +0.0
+    if( a == 0.0f &&
+        ( (Float::floatToIntBits( a ) & Float::floatToIntBits( b ) ) & 0x80000000
) == 0 ) {
+
+        return 0.0f;
+    }
+
+    return a;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+double Math::max( double a, double b ) {
+
+    if( a > b ) {
+        return a;
+    } else if( a < b ) {
+        return b;
+    }
+
+    // if either arg is NaN, return NaN
+    if( a != b ) {
+        return Double::NaN;
+    }
+    // max( +0.0,-0.0) == +0.0
+    if( a == 0.0f &&
+        ( (Double::doubleToLongBits( a ) & Double::doubleToLongBits( b ) ) & 0x80000000
) == 0 ) {
+
+        return 0.0f;
+    }
+
+    return a;
+}
+
+////////////////////////////////////////////////////////////////////////////////
 double Math::log( double value ) {
 
-    if( value != value || value < 0.0 ) {
+    if( Double::isNaN( value ) || value < 0.0 ) {
         return Double::NaN;
     } else if( value == Double::POSITIVE_INFINITY ) {
         return Double::POSITIVE_INFINITY;
@@ -47,6 +150,36 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+double Math::log10( double value ) {
+
+    if( Double::isNaN( value ) || value < 0.0 ) {
+        return Double::NaN;
+    } else if( value == Double::POSITIVE_INFINITY ) {
+        return Double::POSITIVE_INFINITY;
+    } else if( value == 0.0 || value == -0.0 ) {
+        return Double::NEGATIVE_INFINITY;
+    }
+
+    return std::log10( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+double Math::log1p( double value ) {
+
+    if( Double::isNaN( value ) || value < -1.0 ) {
+        return Double::NaN;
+    } else if( value == Double::POSITIVE_INFINITY ) {
+        return Double::POSITIVE_INFINITY;
+    } else if( value == -1.0 ) {
+        return Double::NEGATIVE_INFINITY;
+    } else if( value == 0.0 || value == -0.0 ) {
+        return value;
+    }
+
+    return log1p( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
 double Math::ceil( double value ) {
 
     if( Double::isNaN( value ) || Double::isInfinite( value ) ) {
@@ -70,4 +203,23 @@
     }
 
     return std::floor( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Math::round( float value ) {
+    if( Float::isNaN( value ) ) {
+        return 0;
+    }
+
+    return (int)Math::floor( value + 0.5f );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long Math::round( double value ) {
+
+    if( Double::isNaN( value ) ) {
+        return 0;
+    }
+
+    return (long long)Math::floor( value + 0.5 );
 }

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=563501&r1=563500&r2=563501
==============================================================================
--- 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 Tue Aug  7 06:56:38 2007
@@ -45,6 +45,65 @@
     public:
 
         /**
+         * Returns the absolute value of an int value. If the argument is not
+         * negative, the argument is returned. If the argument is negative, the
+         * negation of the argument is returned.
+         * @param value - the value to return the abs of
+         * @returns the value if positive, otherwise the negative of value
+         */
+        static int abs( int value ) {
+            return value < 0 ? -value : value;
+        }
+
+        /**
+         * Returns the absolute value of an long long value. If the argument is not
+         * negative, the argument is returned. If the argument is negative, the
+         * negation of the argument is returned.
+         * @param value - the value to return the abs of
+         * @returns the value if positive, otherwise the negative of value
+         */
+        static long long abs( long long value ) {
+            return value < 0 ? -value : value;
+        }
+
+        /**
+         * Returns the absolute value of a float value. If the argument is not
+         * negative, the argument is returned. If the argument is negative,
+         * the negation of the argument is returned. Special cases:
+         *
+         * o If the argument is positive zero or negative zero, the result is
+         *   positive zero.
+         * o If the argument is infinite, the result is positive infinity.
+         * o If the argument is NaN, the result is NaN.
+         *
+         * In other words, the result is the same as the value of the expression:
+         *    Float::intBitsToFloat( 0x7fffffff & Float::floatToIntBits( value ) )
+         *
+         * @param value - the value to return the abs of
+         * @returns the value if positive, otherwise the negative of value
+         */
+        static float abs( float value );
+
+        /**
+         * Returns the absolute value of a double value. If the argument is not
+         * negative, the argument is returned. If the argument is negative,
+         * the negation of the argument is returned. Special cases:
+         *
+         * o If the argument is positive zero or negative zero, the result is
+         *   positive zero.
+         * o If the argument is infinite, the result is positive infinity.
+         * o If the argument is NaN, the result is NaN.
+         *
+         * In other words, the result is the same as the value of the expression:
+         *    Double::longBitsToDouble( 0x7fffffffffffffffULL &
+         *                              Double::doubleToLongBits( value ) )
+         *
+         * @param value - the value to return the abs of
+         * @returns the value if positive, otherwise the negative of value
+         */
+        static double abs( double value );
+
+        /**
          * Returns the smaller of two <code>short</code> values. That is,
          * the result the argument closer to the value of
          * <code>Short::MIN_VALUE</code>.  If the arguments have the same
@@ -71,6 +130,47 @@
         }
 
         /**
+         * Returns the smaller of two <code>long long</code> values. That is,
+         * the result the argument closer to the value of
+         * <code>Long::MIN_VALUE</code>.  If the arguments have the same
+         * value, the result is that same value.
+         * @param a - an argument.
+         * @param b - another argument.
+         * @return the smaller of <code>a</code> and <code>b</code>.
+         */
+        static long long min( long long a, long long b ) {
+            return ( a <= b ? a : b );
+        }
+
+        /**
+         * Returns the smaller of two float values. That is, the result is the
+         * value closer to negative infinity. If the arguments have the same value,
+         * the result is that same value. If either value is NaN, then the result
+         * is NaN. Unlike the numerical comparison operators, this method considers
+         * negative zero to be strictly smaller than positive zero. If one argument
+         * is positive zero and the other is negative zero, the result is negative
+         * zero.
+         * @param a - an argument.
+         * @param b - another argument.
+         * @return the smaller of <code>a</code> and <code>b</code>.
+         */
+        static float min( float a, float b );
+
+        /**
+         * Returns the smaller of two double values. That is, the result is the
+         * value closer to negative infinity. If the arguments have the same value,
+         * the result is that same value. If either value is NaN, then the result
+         * is NaN. Unlike the numerical comparison operators, this method considers
+         * negative zero to be strictly smaller than positive zero. If one argument
+         * is positive zero and the other is negative zero, the result is negative
+         * zero.
+         * @param a - an argument.
+         * @param b - another argument.
+         * @return the smaller of <code>a</code> and <code>b</code>.
+         */
+        static double min( double a, double b );
+
+        /**
          * Returns the larger of two <code>short</code> values. That is,
          * the result the argument closer to the value of
          * <code>Short::MAX_VALUE</code>.  If the arguments have the same
@@ -97,6 +197,46 @@
         }
 
         /**
+         * Returns the larger of two <code>long long</code> values. That is,
+         * the result the argument closer to the value of
+         * <code>Long::MAX_VALUE</code>.  If the arguments have the same
+         * value, the result is that same value.
+         * @param a - an argument.
+         * @param b - another argument.
+         * @return the larger of <code>a</code> and <code>b</code>.
+         */
+        static long long max( long long a, long long b ) {
+            return ( a >= b ? a : b );
+        }
+
+        /**
+         * Returns the greater of two float values. That is, the result is the
+         * argument closer to positive infinity. If the arguments have the same
+         * value, the result is that same value. If either value is NaN, then the
+         * result is NaN. Unlike the numerical comparison operators, this method
+         * considers negative zero to be strictly smaller than positive zero. If
+         * one argument is positive zero and the other negative zero, the result
+         * is positive zero.
+         * @param a - an argument.
+         * @param b - another argument.
+         * @return the larger of <code>a</code> and <code>b</code>.
+         */
+        static float max( float a, float b );
+
+        /**
+         * Returns the greater of two double values. That is, the result is the
+         * argument closer to positive infinity. If the arguments have the same value,
+         * the result is that same value. If either value is NaN, then the result is
+         * NaN. Unlike the numerical comparison operators, this method considers
+         * negative zero to be strictly smaller than positive zero. If one argument
+         * is positive zero and the other negative zero, the result is positive zero.
+         * @param a - an argument.
+         * @param b - another argument.
+         * @return the larger of <code>a</code> and <code>b</code>.
+         */
+        static double max( double a, double b );
+
+        /**
          * Returns the natural logarithm (base e) of a double  value. Special cases:
          *
          *  o If the argument is NaN or less than zero, then the result is NaN.
@@ -111,6 +251,40 @@
         static double log( double value );
 
         /**
+         * Returns the base 10 logarithm of a double value. Special cases:
+         *
+         *   o If the argument is NaN or less than zero, then the result is NaN.
+         *   o If the argument is positive infinity, then the result is positive
+         *     infinity.
+         *   o If the argument is positive zero or negative zero, then the result is
+         *     negative infinity.
+         *   o If the argument is equal to 10n for integer n, then the result is n.
+         *
+         * @param value - the value to operate on
+         * @returns the long base 10 of value
+         */
+        static double log10( double value );
+
+        /**
+         * Returns the natural logarithm of the sum of the argument and 1. Note that
+         * for small values x, the result of log1p(x) is much closer to the true
+         * result of ln(1 + x) than the floating-point evaluation of log(1.0+x).
+         *
+         * Special cases:
+         *
+         *   o If the argument is NaN or less than -1, then the result is NaN.
+         *   o If the argument is positive infinity, then the result is positive
+         *     infinity.
+         *   o If the argument is negative one, then the result is negative infinity.
+         *   o If the argument is zero, then the result is a zero with the same sign
+         *     as the argument.
+         *
+         * @param value - the value to operate on
+         * @returns the the value ln(x + 1), the natural log of x + 1
+         */
+        static double log1p( double value );
+
+        /**
          * Returns the smallest (closest to negative infinity) double value that is
          * greater than or equal to the argument and is equal to a mathematical
          * integer. Special cases:
@@ -146,6 +320,44 @@
          * integer.
          */
         static double floor( double value );
+
+        /**
+         * Returns the closest int to the argument. The result is rounded to an
+         * integer by adding 1/2, taking the floor of the result, and casting the
+         * result to type int. In other words, the result is equal to the value
+         * of the expression:  (int)Math.floor( a + 0.5f )
+         *
+         *   o If the argument is NaN, the result is 0.
+         *   o If the argument is negative infinity or any value less than or equal
+         *     to the value of Integer::MIN_VALUE, the result is equal to the value of
+         *     Integer::MIN_VALUE.
+         *   o If the argument is positive infinity or any value greater than or equal
+         *     to the value of Integer::MAX_VALUE, the result is equal to the value of
+         *     Integer::MAX_VALUE.
+         *
+         * @param value - the value to round
+         * @returns the value of the argument rounded to the nearest integral value.
+         */
+        static int round( float value );
+
+        /**
+         * Returns the closest long long to the argument. The result is rounded to
+         * an integer by adding 1/2, taking the floor of the result, and casting the
+         * result to type long long. In other words, the result is equal to the value
+         * of the expression:  (long long)Math.floor(a + 0.5d)
+         *
+         *   o If the argument is NaN, the result is 0.
+         *   o If the argument is negative infinity or any value less than or equal
+         *     to the value of Long::MIN_VALUE, the result is equal to the value of
+         *     Long::MIN_VALUE.
+         *   o If the argument is positive infinity or any value greater than or equal
+         *     to the value of Long::MAX_VALUE, the result is equal to the value of
+         *     Long::MAX_VALUE.
+         *
+         * @param value - the value to round
+         * @returns the value of the argument rounded to the nearest integral value.
+         */
+        static long long round( double value );
 
     };
 



Mime
View raw message