activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r562535 - in /activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang: Float.cpp Float.h
Date Fri, 03 Aug 2007 18:06:20 GMT
Author: tabish
Date: Fri Aug  3 11:06:18 2007
New Revision: 562535

URL: http://svn.apache.org/viewvc?view=rev&rev=562535
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103

Adding in more Types wrappers

Modified:
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Float.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Float.h

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Float.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Float.cpp?view=diff&rev=562535&r1=562534&r2=562535
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Float.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Float.cpp Fri Aug  3 11:06:18
2007
@@ -25,6 +25,9 @@
 ////////////////////////////////////////////////////////////////////////////////
 const float Float::MAX_VALUE = 3.40282347e+38F;
 const float Float::MIN_VALUE = 1.17549435e-38F;
+const float Float::NaN = 0.0f / 0.0f;
+const float Float::POSITIVE_INFINITY = 1.0f / 0.0f;
+const float Float::NEGATIVE_INFINITY = -1.0f / 0.0f;
 
 ////////////////////////////////////////////////////////////////////////////////
 Float::Float( float value ) {
@@ -56,4 +59,78 @@
 ////////////////////////////////////////////////////////////////////////////////
 std::string Float::toString() const {
     return ""; //TODO Float::toString( this->value, 10 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Float::isInfinite() const {
+    return Float::isInfinite( this->value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Float::isNaN() const {
+    return Float::isNaN( this->value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Float::floatToIntBits( float value ) {
+
+    int intValue = 0;
+    memcpy( &intValue, &value, sizeof( float ) );
+
+    if( ( intValue & SINGLE_EXPONENT_MASK ) == SINGLE_EXPONENT_MASK )
+    {
+        if( intValue & SINGLE_MANTISSA_MASK )
+        {
+            return SINGLE_NAN_BITS;
+        }
+    }
+
+    return intValue;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int Float::floatToRawIntBits( float value ) {
+
+    int intValue = 0;
+    memcpy( &intValue, &value, sizeof( float ) );
+    return intValue;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Float::isInfinite( float value ) {
+    return ( value == POSITIVE_INFINITY ) || ( value == NEGATIVE_INFINITY );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool Float::isNaN( float value ) {
+    return value != value;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+float Float::parseFloat( const std::string& value )
+    throw ( exceptions::NumberFormatException ) {
+
+    return 0.0; // TODO
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Float::toHexString( float value ) {
+    return ""; //TODO
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::string Float::toString( float value ) {
+    return ""; //TODO
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Float Float::valueOf( float value ) {
+    return Float( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+Float Float::valueOf( const std::string& value )
+    throw ( exceptions::NumberFormatException ) {
+
+    return valueOf( parseFloat( value ) );
 }

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Float.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Float.h?view=diff&rev=562535&r1=562534&r2=562535
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Float.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Float.h Fri Aug  3 11:06:18
2007
@@ -45,6 +45,15 @@
         /** The minimum value that the primitive type can hold */
         static const float MIN_VALUE;
 
+        /** Constant for the Not a Number Value */
+        static const float NaN;
+
+        /** Constant for Positive Infinity */
+        static const float POSITIVE_INFINITY;
+
+        /** Constant for Negative Infinitiy */
+        static const float NEGATIVE_INFINITY;
+
     public:
 
         /**
@@ -190,6 +199,201 @@
         virtual long long longValue() const {
             return (long long)this->value;
         }
+
+        /**
+         * @returns true if the float is equal to positive infinity.
+         */
+        bool isInfinite() const;
+
+        /**
+         * @returns true if the float is equal to NaN.
+         */
+        bool isNaN() const;
+
+    public:   // Statics
+
+        /**
+         * Returns a representation of the specified floating-point value according
+         * to the IEEE 754 floating-point "single format" bit layout.
+         *
+         * Bit 31 (the bit that is selected by the mask 0x80000000) represents the
+         * sign of the floating-point number. Bits 30-23 (the bits that are selected
+         * by the mask 0x7f800000) represent the exponent. Bits 22-0 (the bits that
+         * are selected by the mask 0x007fffff) represent the significand (sometimes
+         * called the mantissa) of the floating-point number.
+         *
+         * If the argument is positive infinity, the result is 0x7f800000.
+         * If the argument is negative infinity, the result is 0xff800000.
+         * If the argument is NaN, the result is 0x7fc00000.
+         *
+         * In all cases, the result is an integer that, when given to the
+         * intBitsToFloat(int) method, will produce a floating-point value the
+         * same as the argument to floatToIntBits (except all NaN values are
+         * collapsed to a single "canonical" NaN value).
+         * @param value - the float to convert to int bits
+         * @returns the int that holds the float's value
+         */
+        static int floatToIntBits( float value );
+
+        /**
+         * Returns a representation of the specified floating-point value according
+         * to the IEEE 754 floating-point "single format" bit layout, preserving
+         * Not-a-Number (NaN) values.
+         *
+         * Bit 31 (the bit that is selected by the mask 0x80000000) represents the
+         * sign of the floating-point number. Bits 30-23 (the bits that are selected
+         * by the mask 0x7f800000) represent the exponent. Bits 22-0 (the bits that
+         * are selected by the mask 0x007fffff) represent the significand (sometimes
+         * called the mantissa) of the floating-point number.
+         *
+         * If the argument is positive infinity, the result is 0x7f800000.
+         * If the argument is negative infinity, the result is 0xff800000.
+         * If the argument is NaN, the result is the integer representing the
+         * actual NaN value. Unlike the floatToIntBits method, intToRawIntBits
+         * does not collapse all the bit patterns encoding a NaN to a single
+         * "canonical" NaN value.
+         *
+         * In all cases, the result is an integer that, when given to the
+         * intBitsToFloat(int) method, will produce a floating-point value the same
+         * as the argument to floatToRawIntBits.
+         * @param the float to convert to a raw int
+         * @returns the raw int value of the float
+         */
+        static int floatToRawIntBits( float value );
+
+        /**
+         * Returns the float value corresponding to a given bit representation. The
+         * argument is considered to be a representation of a floating-point value
+         * according to the IEEE 754 floating-point "single format" bit layout.
+         *
+         * If the argument is 0x7f800000, the result is positive infinity.
+         * If the argument is 0xff800000, the result is negative infinity.
+         * If the argument is any value in the range 0x7f800001 through 0x7fffffff
+         * or in the range 0xff800001 through 0xffffffff, the result is a NaN. No
+         * IEEE 754 floating-point operation provided by C++ can distinguish
+         * between two NaN values of the same type with different bit patterns.
+         * Distinct values of NaN are only distinguishable by use of the
+         * Float::floatToRawIntBits method.
+         *
+         * @param bits - the bits of the float encoded as a float
+         * @return a new float created from the int bits.
+         */
+        static float intBitsToFloat( int bits );
+
+        /**
+         * @param value - The float to check.
+         * @returns true if the float is equal to positive infinity.
+         */
+        static bool isInfinite( float value );
+
+        /**
+         * @param value - The float to check.
+         * @returns true if the float is equal to NaN.
+         */
+        static bool isNaN( float value );
+
+        /**
+         * Returns a new float initialized to the value represented by the
+         * specified string, as performed by the valueOf method of class Float.
+         * @param value - the string to parse
+         * @returns a float parsed from the string
+         * @throw NumberFormatException
+         */
+        static float parseFloat( const std::string& value )
+            throw ( exceptions::NumberFormatException );
+
+        /**
+         * Returns a hexadecimal string representation of the float argument. All
+         * characters mentioned below are ASCII characters.
+         *
+         *  * If the argument is NaN, the result is the string "NaN".
+         *  * Otherwise, the result is a string that represents the sign and magnitude
+         *    (absolute value) of the argument. If the sign is negative, the first
+         *    character of the result is '-'; if the sign is positive, no sign
+         *    character appears in the result. As for the magnitude m:
+         *      o If m is infinity, it is represented by the string "Infinity"; thus,
+         *        positive infinity produces the result "Infinity" and negative
+         *        infinity produces the result "-Infinity".
+         *      o If m is zero, it is represented by the string "0x0.0p0"; thus,
+         *        negative zero produces the result "-0x0.0p0" and positive zero
+         *        produces the result "0x0.0p0".
+         *      o If m is a float value with a normalized representation, substrings
+         *        are used to represent the significand and exponent fields. The
+         *        significand is represented by the characters "0x1." followed by a
+         *        lowercase hexadecimal representation of the rest of the
+         *        significand as a fraction. Trailing zeros in the hexadecimal
+         *        representation are removed unless all the digits are zero, in which
+         *        case a single zero is used. Next, the exponent is represented by
+         *        "p" followed by a decimal string of the unbiased exponent as if
+         *        produced by a call to Integer.toString on the exponent value.
+         *      o If m is a float value with a subnormal representation, the
+         *        significand is represented by the characters "0x0." followed by a
+         *        hexadecimal representation of the rest of the significand as a
+         *        fraction. Trailing zeros in the hexadecimal representation are
+         *        removed. Next, the exponent is represented by "p-126". Note that
+         *        there must be at least one nonzero digit in a subnormal significand.
+         *
+         * @param value - The float to convert to a string
+         * @returns the Hex formatted float string.
+         */
+        static std::string toHexString( float value );
+
+        /**
+         * Returns a string representation of the float  argument. All characters
+         * mentioned below are ASCII characters.
+         *
+         * If the argument is NaN, the result is the string "NaN".
+         * Otherwise, the result is a string that represents the sign and magnitude
+         * (absolute value) of the argument. If the sign is negative, the first
+         * character of the result is '-'; if the sign is positive, no
+         * sign character appears in the result. As for the magnitude m:
+         *  o If m is infinity, it is represented by the characters "Infinity"; thus,
+         *    positive infinity produces the result "Infinity" and negative infinity
+         *    produces the result "-Infinity".
+         *  o If m is zero, it is represented by the characters "0.0"; thus, negative
+         *    zero produces the result "-0.0" and positive zero produces the result
+         *    "0.0".
+         *  o If m is greater than or equal to 10-3 but less than 107, then it is
+         *    represented as the integer part of m, in decimal form with no leading
+         *    zeroes, followed by '.', followed by one or more decimal digits
+         *    representing the fractional part of m.
+         *  o If m is less than 10-3 or greater than or equal to 107, then it is
+         *    represented in so-called "computerized scientific notation." Let n be
+         *    the unique integer such that 10n <= m < 10n+1; then let a be the
+         *    mathematically exact quotient of m and 10n so that 1 <= a < 10.
+         *    The magnitude is then represented as the integer part of a, as a
+         *    single decimal digit, followed by '.', followed by decimal digits
+         *    representing the fractional part of a, followed by the letter 'E',
+         *    followed by a representation of n as a decimal integer, as produced
+         *    by the method Integer.toString(int).
+         * @param value - The float to convert to a string
+         * @returns the formatted float string.
+         */
+        static std::string toString( float value );
+
+        /**
+         * Returns a Float instance representing the specified float value.
+         * @param value - float to wrap
+         * @returns new Float instance wrapping the primitive value
+         */
+        static Float valueOf( float value );
+
+        /**
+         * Returns a Float instance that wraps a primtive float which is parsed
+         * from the string value passed.
+         *
+         * @param value - the string to parse
+         * @returns a new Float instance wrapping the float parsed from value
+         * @throws NumberFormatException on error.
+         */
+        static Float valueOf( const std::string& value )
+            throw ( exceptions::NumberFormatException );
+
+    private:
+
+        static const unsigned int SINGLE_EXPONENT_MASK = 0x7F800000;
+        static const unsigned int SINGLE_MANTISSA_MASK = 0x007FFFFF;
+        static const unsigned int SINGLE_NAN_BITS = (SINGLE_EXPONENT_MASK | 0x00400000);
 
     };
 



Mime
View raw message