You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2007/08/09 16:40:51 UTC

svn commit: r564226 - in /activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util: BigInt.cpp BigInt.h BitOps.cpp BitOps.h FloatingPointParser.cpp FloatingPointParser.h HexStringParser.cpp HexStringParser.h

Author: tabish
Date: Thu Aug  9 07:40:50 2007
New Revision: 564226

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

Implementing the Primitive Wrappers fully

Added:
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BitOps.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BitOps.h
Modified:
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BigInt.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BigInt.h
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/FloatingPointParser.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/FloatingPointParser.h
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/HexStringParser.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/HexStringParser.h

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BigInt.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BigInt.cpp?view=diff&rev=564226&r1=564225&r2=564226
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BigInt.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BigInt.cpp Thu Aug  9 07:40:50 2007
@@ -19,15 +19,13 @@
 
 #include <decaf/lang/Double.h>
 #include <decaf/lang/Float.h>
+#include <decaf/internal/util/BitOps.h>
 
 using namespace decaf;
 using namespace decaf::lang;
 using namespace decaf::internal;
 using namespace decaf::internal::util;
 
-#define HIGH_IN_U64(u64) ((u64) >> 32)
-#define LOW_IN_U64(u64) ((u64) & 0x00000000FFFFFFFFLL)
-
 ////////////////////////////////////////////////////////////////////////////////
 BigInt::BigInt() {
 }
@@ -61,7 +59,7 @@
     index = -1;
     for( count = 0; count < length2; ++count ) {
         simpleMultiplyAddHighPrecision( arg1, length1,
-                                        arg2[count] & LONG_LO_MASK,
+                                        arg2[count] & BitOps::LONG_LO_MASK,
                                         resultIn32 + (++index) );
         simpleMultiplyAddHighPrecision( arg1, length1,
                                         ( arg2[count] >> 32 ),
@@ -80,17 +78,19 @@
       digit <<= 32;
       do
         {
-          arg = arg1[index] & LONG_LO_MASK;
-          digit = ( digit >> 32 ) + TIMES_TEN( arg );
-          LOW_U32_FROM_LONG64_PTR( arg1 + index ) = LOW_U32_FROM_LONG64( digit );
+          arg = arg1[index] & BitOps::LONG_LO_MASK;
+          digit = ( digit >> 32 ) + BitOps::TIMES_TEN( arg );
+          BitOps::LOW_U32_FROM_LONG64_PTR( arg1 + index ) =
+              BitOps::LOW_U32_FROM_LONG64( digit );
 
           arg = arg1[index] >> 32;
-          digit = ( digit >> 32 ) + TIMES_TEN( arg );
-          HIGH_U32_FROM_LONG64_PTR( arg1 + index ) = LOW_U32_FROM_LONG64( digit );
+          digit = ( digit >> 32 ) + BitOps::TIMES_TEN( arg );
+          BitOps::HIGH_U32_FROM_LONG64_PTR( arg1 + index ) =
+              BitOps::LOW_U32_FROM_LONG64( digit );
         }
       while (++index < length);
 
-      return HIGH_U32_FROM_LONG64( digit );
+      return BitOps::HIGH_U32_FROM_LONG64( digit );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -109,21 +109,21 @@
     if( length == 0 ) {
         return 0.0;
     } else if( length > 16 ) {
-        result = EXPONENT_MASK;
+        result = BitOps::EXPONENT_MASK;
     } else if( length == 1 ) {
 
         highBit = highestSetBit (arg);
         if( highBit <= 53 ) {
             highBit = 53 - highBit;
             mantissa = *arg << highBit;
-            result = CREATE_DOUBLE_BITS( mantissa, -highBit );
+            result = BitOps::CREATE_DOUBLE_BITS( mantissa, -highBit );
         } else {
             highBit -= 53;
             mantissa = *arg >> highBit;
-            result = CREATE_DOUBLE_BITS( mantissa, highBit );
+            result = BitOps::CREATE_DOUBLE_BITS( mantissa, highBit );
 
             // perform rounding, round to even in case of tie
-            test = ( LOW_U32_FROM_LONG64_PTR( arg ) << ( 11 - highBit ) ) & 0x7FF;
+            test = ( BitOps::LOW_U32_FROM_LONG64_PTR( arg ) << ( 11 - highBit ) ) & 0x7FF;
             if( test > 0x400 || ((test == 0x400) && (mantissa & 1)) ) {
                 result = result + 1;
             }
@@ -138,13 +138,13 @@
             } else {
                 mantissa = arg[length];
             }
-            result = CREATE_DOUBLE_BITS( mantissa, length * 64 - highBit );
+            result = BitOps::CREATE_DOUBLE_BITS( mantissa, length * 64 - highBit );
 
             // perform rounding, round to even in case of tie
             test64 = arg[--length] << highBit;
-            if( test64 > SIGN_MASK || ((test64 == SIGN_MASK) && (mantissa & 1)) ) {
+            if( test64 > BitOps::SIGN_MASK || ((test64 == BitOps::SIGN_MASK) && (mantissa & 1)) ) {
                 result = result + 1;
-            } else if( test64 == SIGN_MASK ) {
+            } else if( test64 == BitOps::SIGN_MASK ) {
                 while( --length >= 0 ) {
                     if( arg[length] != 0 ) {
                         result = result + 1;
@@ -155,10 +155,10 @@
         } else {
             highBit -= 53;
             mantissa = arg[length] >> highBit;
-            result = CREATE_DOUBLE_BITS( mantissa, length * 64 + highBit );
+            result = BitOps::CREATE_DOUBLE_BITS( mantissa, length * 64 + highBit );
 
             // perform rounding, round to even in case of tie
-            test = ( LOW_U32_FROM_LONG64_PTR( arg + length ) << ( 11 - highBit ) ) & 0x7FF;
+            test = ( BitOps::LOW_U32_FROM_LONG64_PTR( arg + length ) << ( 11 - highBit ) ) & 0x7FF;
             if( test > 0x400 || ((test == 0x400) && (mantissa & 1)) ) {
                 result = result + 1;
             } else if( test == 0x400 ) {
@@ -202,10 +202,10 @@
 
       unsigned long long m = Double::doubleToLongBits( z );
 
-      if ((m & EXPONENT_MASK) != 0)
-        m = (m & MANTISSA_MASK) | NORMAL_MASK;
+      if ((m & BitOps::EXPONENT_MASK) != 0)
+        m = (m & BitOps::MANTISSA_MASK) | BitOps::NORMAL_MASK;
       else
-        m = (m & MANTISSA_MASK);
+        m = (m & BitOps::MANTISSA_MASK);
 
       return m;
 }
@@ -284,9 +284,9 @@
     int k = ( (unsigned long long )Double::doubleToLongBits( z ) >> 52 );
 
     if( k ) {
-        k -= E_OFFSET;
+        k -= BitOps::E_OFFSET;
     } else {
-        k = 1 - E_OFFSET;
+        k = 1 - BitOps::E_OFFSET;
     }
 
     return k;
@@ -302,11 +302,11 @@
 
     do {
 
-        product = ( product >> 32 ) + arg2 * LOW_U32_FROM_LONG64_PTR( arg1 + index );
-        LOW_U32_FROM_LONG64_PTR( arg1 + index ) = LOW_U32_FROM_LONG64( product );
+        product = ( product >> 32 ) + arg2 * BitOps::LOW_U32_FROM_LONG64_PTR( arg1 + index );
+        BitOps::LOW_U32_FROM_LONG64_PTR( arg1 + index ) = BitOps::LOW_U32_FROM_LONG64( product );
 
-        product = ( product >> 32 ) + arg2 * HIGH_U32_FROM_LONG64_PTR( arg1 + index );
-        HIGH_U32_FROM_LONG64_PTR( arg1 + index ) = LOW_U32_FROM_LONG64( product );
+        product = ( product >> 32 ) + arg2 * BitOps::HIGH_U32_FROM_LONG64_PTR( arg1 + index );
+        BitOps::HIGH_U32_FROM_LONG64_PTR( arg1 + index ) = BitOps::LOW_U32_FROM_LONG64( product );
 
     } while( ++index < length );
 
@@ -375,24 +375,24 @@
     }
 
     if( *y & 0x00000000FFFFFFFFULL ) {
-      x = LOW_U32_FROM_LONG64_PTR( y );
+      x = BitOps::LOW_U32_FROM_LONG64_PTR( y );
       result = 0;
     } else {
-      x = HIGH_U32_FROM_LONG64_PTR( y );
+      x = BitOps::HIGH_U32_FROM_LONG64_PTR( y );
       result = 32;
     }
 
     if( !( x & 0xFFFF ) ) {
-      x = bitSection( x, 0xFFFF0000, 16 );
+      x = BitOps::bitSection( x, 0xFFFF0000, 16 );
       result += 16;
     }
 
     if( !( x & 0xFF) ) {
-      x = bitSection( x, 0xFF00, 8 );
+      x = BitOps::bitSection( x, 0xFF00, 8 );
       result += 8;
     }
     if( !( x & 0xF ) ) {
-      x = bitSection( x, 0xF0, 4 );
+      x = BitOps::bitSection( x, 0xF0, 4 );
       result += 4;
     }
 
@@ -428,7 +428,7 @@
     // simpleAappendDecimalDigit() so just pick 10e3 as that point for
     // now.
     while( exp10 >= 19 ) {
-        overflow = simpleMultiplyHighPrecision64( result, length, TEN_E19 );
+        overflow = simpleMultiplyHighPrecision64( result, length, BitOps::TEN_E19 );
         if( overflow ) {
             result[length++] = overflow;
         }
@@ -436,7 +436,7 @@
     }
 
     while( exp10 >= 9 ) {
-        overflow = simpleMultiplyHighPrecision( result, length, TEN_E9 );
+        overflow = simpleMultiplyHighPrecision( result, length, BitOps::TEN_E9 );
         if( overflow ) {
               result[length++] = overflow;
         }
@@ -460,32 +460,32 @@
             result[length++] = overflow;
         }
     } else if( exp10 == 3 ) {
-        overflow = simpleMultiplyHighPrecision( result, length, TEN_E3 );
+        overflow = simpleMultiplyHighPrecision( result, length, BitOps::TEN_E3 );
         if( overflow ) {
             result[length++] = overflow;
         }
     } else if( exp10 == 4 ) {
-        overflow = simpleMultiplyHighPrecision( result, length, TEN_E4 );
+        overflow = simpleMultiplyHighPrecision( result, length, BitOps::TEN_E4 );
         if( overflow ) {
             result[length++] = overflow;
         }
     } else if( exp10 == 5 ) {
-        overflow = simpleMultiplyHighPrecision( result, length, TEN_E5 );
+        overflow = simpleMultiplyHighPrecision( result, length, BitOps::TEN_E5 );
         if( overflow ) {
             result[length++] = overflow;
         }
     } else if( exp10 == 6 ) {
-        overflow = simpleMultiplyHighPrecision( result, length, TEN_E6);
+        overflow = simpleMultiplyHighPrecision( result, length, BitOps::TEN_E6);
         if( overflow ) {
             result[length++] = overflow;
         }
     } else if( exp10 == 7 ) {
-        overflow = simpleMultiplyHighPrecision( result, length, TEN_E7 );
+        overflow = simpleMultiplyHighPrecision( result, length, BitOps::TEN_E7 );
         if( overflow ) {
             result[length++] = overflow;
         }
     } else if( exp10 == 8 ) {
-        overflow = simpleMultiplyHighPrecision( result, length, TEN_E8 );
+        overflow = simpleMultiplyHighPrecision( result, length, BitOps::TEN_E8 );
         if( overflow ) {
             result[length++] = overflow;
         }
@@ -508,24 +508,24 @@
     do {
 
         product =
-            ( product >> 32 ) + result[at( resultIndex )] +
-            arg2 * LOW_U32_FROM_LONG64_PTR( arg1 + index );
-        result[at( resultIndex )] = LOW_U32_FROM_LONG64( product );
+            ( product >> 32 ) + result[BitOps::at( resultIndex )] +
+            arg2 * BitOps::LOW_U32_FROM_LONG64_PTR( arg1 + index );
+        result[BitOps::at( resultIndex )] = BitOps::LOW_U32_FROM_LONG64( product );
         ++resultIndex;
 
         product =
-            ( product >> 32 ) + result[at( resultIndex )] +
-            arg2 * HIGH_U32_FROM_LONG64_PTR( arg1 + index );
-        result[at( resultIndex )] = LOW_U32_FROM_LONG64( product );
+            ( product >> 32 ) + result[BitOps::at( resultIndex )] +
+            arg2 * BitOps::HIGH_U32_FROM_LONG64_PTR( arg1 + index );
+        result[BitOps::at( resultIndex )] = BitOps::LOW_U32_FROM_LONG64( product );
         ++resultIndex;
 
     } while( ++index < length );
 
-    result[at( resultIndex )] += HIGH_U32_FROM_LONG64( product );
-    if( result[at( resultIndex )] < HIGH_U32_FROM_LONG64( product ) ) {
+    result[BitOps::at( resultIndex )] += BitOps::HIGH_U32_FROM_LONG64( product );
+    if( result[BitOps::at( resultIndex )] < BitOps::HIGH_U32_FROM_LONG64( product ) ) {
         // must be careful with ++ operator and macro expansion
         ++resultIndex;
-        while( ++result[at( resultIndex )] == 0 ) {
+        while( ++result[BitOps::at( resultIndex )] == 0 ) {
             ++resultIndex;
         }
     }
@@ -542,26 +542,26 @@
     }
 
     if( *y & 0xFFFFFFFF00000000LL ) {
-        x = HIGH_U32_FROM_LONG64_PTR(y);
+        x = BitOps::HIGH_U32_FROM_LONG64_PTR(y);
         result = 32;
     } else {
-        x = LOW_U32_FROM_LONG64_PTR(y);
+        x = BitOps::LOW_U32_FROM_LONG64_PTR(y);
         result = 0;
     }
 
     if( x & 0xFFFF0000 )
     {
-        x = bitSection( x, 0xFFFF0000, 16 );
+        x = BitOps::bitSection( x, 0xFFFF0000, 16 );
         result += 16;
     }
 
     if( x & 0xFF00 ) {
-        x = bitSection( x, 0xFF00, 8 );
+        x = BitOps::bitSection( x, 0xFF00, 8 );
         result += 8;
     }
 
     if( x & 0xF0 ) {
-        x = bitSection( x, 0xF0, 4 );
+        x = BitOps::bitSection( x, 0xF0, 4 );
         result += 4;
     }
 
@@ -630,10 +630,10 @@
 
     unsigned int m = (unsigned int)Float::floatToIntBits( z );
 
-    if( ( m & FLOAT_EXPONENT_MASK ) != 0 )
-        m = ( m & FLOAT_MANTISSA_MASK ) | FLOAT_NORMAL_MASK;
+    if( ( m & BitOps::FLOAT_EXPONENT_MASK ) != 0 )
+        m = ( m & BitOps::FLOAT_MANTISSA_MASK ) | BitOps::FLOAT_NORMAL_MASK;
     else
-        m = ( m & FLOAT_MANTISSA_MASK );
+        m = ( m & BitOps::FLOAT_MANTISSA_MASK );
 
     return m;
 }
@@ -659,8 +659,8 @@
 
         if( (*pArg1 != 0) || (intermediate != 0) ) {
 
-            prod1 = (unsigned long long)LOW_U32_FROM_LONG64(arg2) *
-                    (unsigned long long)LOW_U32_FROM_LONG64_PTR(pArg1);
+            prod1 = (unsigned long long)BitOps::LOW_U32_FROM_LONG64(arg2) *
+                    (unsigned long long)BitOps::LOW_U32_FROM_LONG64_PTR(pArg1);
 
             sum = intermediate + prod1;
             if( (sum < prod1) || (sum < intermediate) ) {
@@ -669,10 +669,10 @@
                 carry1 = 0;
             }
 
-            prod1 = (unsigned long long)LOW_U32_FROM_LONG64(arg2) *
-                    (unsigned long long)HIGH_U32_FROM_LONG64_PTR(pArg1);
-            prod2 = (unsigned long long)HIGH_U32_FROM_LONG64(arg2) *
-                    (unsigned long long)LOW_U32_FROM_LONG64_PTR(pArg1);
+            prod1 = (unsigned long long)BitOps::LOW_U32_FROM_LONG64(arg2) *
+                    (unsigned long long)BitOps::HIGH_U32_FROM_LONG64_PTR(pArg1);
+            prod2 = (unsigned long long)BitOps::HIGH_U32_FROM_LONG64(arg2) *
+                    (unsigned long long)BitOps::LOW_U32_FROM_LONG64_PTR(pArg1);
 
             intermediate = carry2 + ( sum >> 32 ) + prod1 + prod2;
 
@@ -682,11 +682,11 @@
                 carry2 = 0;
             }
 
-            LOW_U32_FROM_LONG64_PTR(pArg1) = LOW_U32_FROM_LONG64(sum);
-            buf32 = HIGH_U32_FROM_LONG64_PTR (pArg1);
-            HIGH_U32_FROM_LONG64_PTR(pArg1) = LOW_U32_FROM_LONG64(intermediate);
+            BitOps::LOW_U32_FROM_LONG64_PTR(pArg1) = BitOps::LOW_U32_FROM_LONG64(sum);
+            buf32 = BitOps::HIGH_U32_FROM_LONG64_PTR (pArg1);
+            BitOps::HIGH_U32_FROM_LONG64_PTR(pArg1) = BitOps::LOW_U32_FROM_LONG64(intermediate);
             intermediate = carry1 + ( intermediate >> 32 ) +
-                           (unsigned long long)HIGH_U32_FROM_LONG64 (arg2) *
+                           (unsigned long long)BitOps::HIGH_U32_FROM_LONG64 (arg2) *
                            (unsigned long long)buf32;
         }
 
@@ -724,9 +724,9 @@
     int k = Float::floatToIntBits( z ) >> 23;
 
     if( k ) {
-        k -= FLOAT_E_OFFSET;
+        k -= BitOps::FLOAT_E_OFFSET;
     } else {
-        k = 1 - FLOAT_E_OFFSET;
+        k = 1 - BitOps::FLOAT_E_OFFSET;
     }
 
     return k;

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BigInt.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BigInt.h?view=diff&rev=564226&r1=564225&r2=564226
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BigInt.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BigInt.h Thu Aug  9 07:40:50 2007
@@ -26,47 +26,6 @@
 namespace util{
 
     class BigInt {
-    private:
-
-        // Used to make masking easier
-        typedef union {
-            unsigned long long longValue;
-            unsigned int intValue[2];
-            double doubleValue;
-        } LONG_UNION;
-
-        #ifdef APR_IS_BIGENDIAN
-            static const int HiWord = 0;
-            static const int LoWord = 1;
-        #else
-            static const int HiWord = 1;
-            static const int LoWord = 0;
-        #endif
-
-        static const long long TEN_E1 = 0xALL;
-        static const long long TEN_E2 = 0x64LL;
-        static const long long TEN_E3 = 0x3E8LL;
-        static const long long TEN_E4 = 0x2710LL;
-        static const long long TEN_E5 = 0x186A0LL;
-        static const long long TEN_E6 = 0xF4240LL;
-        static const long long TEN_E7 = 0x989680LL;
-        static const long long TEN_E8 = 0x5F5E100LL;
-        static const long long TEN_E9 = 0x3B9ACA00LL;
-        static const long long TEN_E19 = 0x8AC7230489E80000LL;
-
-        static const int E_OFFSET = 1075;
-
-        static const unsigned long long LONG_HI_MASK = 0xFFFFFFFF00000000ULL;
-        static const unsigned long long LONG_LO_MASK = 0x00000000FFFFFFFFULL;
-        static const unsigned long long MANTISSA_MASK = 0x000FFFFFFFFFFFFFULL;
-        static const unsigned long long EXPONENT_MASK = 0x7FF0000000000000ULL;
-        static const unsigned long long NORMAL_MASK = 0x0010000000000000ULL;
-        static const unsigned long long SIGN_MASK = 0x8000000000000000ULL;
-        static const unsigned int FLOAT_MANTISSA_MASK = 0x007FFFFF;
-        static const unsigned int FLOAT_EXPONENT_MASK = 0x7F800000;
-        static const unsigned int FLOAT_NORMAL_MASK = 0x00800000;
-        static const unsigned int FLOAT_E_OFFSET = 150;
-
     public:
 
         BigInt();
@@ -138,57 +97,6 @@
                                            unsigned long long arg2 );
 
         static int floatExponent( float z );
-
-    private:
-
-        static unsigned int TIMES_TEN( unsigned int x ) {
-            return ((x) << 3) + ((x) << 1);
-        }
-
-        static unsigned long long TIMES_TEN( unsigned long long x ) {
-            return ((x) << 3) + ((x) << 1);
-        }
-
-        static unsigned long long CREATE_DOUBLE_BITS(
-            unsigned long long normalizedM, unsigned long long e ) {
-
-            return ( normalizedM & MANTISSA_MASK ) | ( ( e + E_OFFSET ) << 52 );
-        }
-
-        static unsigned long long bitSection(
-            unsigned long long x, unsigned long long mask, int shift ) {
-
-            return ( x & mask ) >> shift;
-        }
-        static unsigned int bitSection(
-            unsigned int x, unsigned int mask, int shift ) {
-
-            return ( x & mask ) >> shift;
-        }
-
-        static unsigned int LOW_U32_FROM_LONG64( unsigned long long long64 ) {
-            return LOW_U32_FROM_LONG64_PTR( &long64 );
-        }
-
-        static unsigned int HIGH_U32_FROM_LONG64( unsigned long long long64 ) {
-            return HIGH_U32_FROM_LONG64_PTR( &long64 );
-        }
-
-        static unsigned int& LOW_U32_FROM_LONG64_PTR( unsigned long long* long64ptr ) {
-            return ( (LONG_UNION*)long64ptr )->intValue[LoWord];
-        }
-
-        static unsigned int& HIGH_U32_FROM_LONG64_PTR( unsigned long long* long64ptr ) {
-            return ( (LONG_UNION*)long64ptr )->intValue[HiWord];
-        }
-
-        static unsigned int at( unsigned int i ) {
-            #ifdef APR_IS_BIGENDIAN
-                return i^1;
-            #else
-                return i;
-            #endif
-        }
 
     };
 

Added: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BitOps.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BitOps.cpp?view=auto&rev=564226
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BitOps.cpp (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BitOps.cpp Thu Aug  9 07:40:50 2007
@@ -0,0 +1,26 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include "BitOps.h"
+
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::internal::util;
+
+////////////////////////////////////////////////////////////////////////////////
+BitOps::BitOps() {
+}

Added: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BitOps.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BitOps.h?view=auto&rev=564226
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BitOps.h (added)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/BitOps.h Thu Aug  9 07:40:50 2007
@@ -0,0 +1,157 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#ifndef _DECAF_INTERNAL_UTIL_BITOPS_H_
+#define _DECAF_INTERNAL_UTIL_BITOPS_H_
+
+#include <decaf/util/Config.h>
+#include <apr.h>
+
+namespace decaf{
+namespace internal{
+namespace util{
+
+    /**
+     * Class with static methods for operation on values in bit patterns.
+     */
+    class BitOps {
+    public:
+
+        // Used to make masking easier
+        typedef union {
+            unsigned long long longValue;
+            unsigned int intValue[2];
+            int sintValue[2];
+            double doubleValue;
+        } LONG_UNION;
+
+        #ifdef APR_IS_BIGENDIAN
+            static const int HiWord = 0;
+            static const int LoWord = 1;
+        #else
+            static const int HiWord = 1;
+            static const int LoWord = 0;
+        #endif
+
+        static const unsigned long long LONG_HI_MASK = 0xFFFFFFFF00000000ULL;
+        static const unsigned long long LONG_LO_MASK = 0x00000000FFFFFFFFULL;
+        static const long long TEN_E1 = 0xALL;
+        static const long long TEN_E2 = 0x64LL;
+        static const long long TEN_E3 = 0x3E8LL;
+        static const long long TEN_E4 = 0x2710LL;
+        static const long long TEN_E5 = 0x186A0LL;
+        static const long long TEN_E6 = 0xF4240LL;
+        static const long long TEN_E7 = 0x989680LL;
+        static const long long TEN_E8 = 0x5F5E100LL;
+        static const long long TEN_E9 = 0x3B9ACA00LL;
+        static const long long TEN_E19 = 0x8AC7230489E80000LL;
+
+        static const int E_OFFSET = 1075;
+
+        static const long long INFINITE_LONGBITS = 0x7FF0000000000000LL;
+        static const unsigned long long MANTISSA_MASK = 0x000FFFFFFFFFFFFFULL;
+        static const unsigned long long EXPONENT_MASK = 0x7FF0000000000000ULL;
+        static const unsigned long long NORMAL_MASK = 0x0010000000000000ULL;
+        static const unsigned long long SIGN_MASK = 0x8000000000000000ULL;
+        static const unsigned int FLOAT_MANTISSA_MASK = 0x007FFFFF;
+        static const unsigned int FLOAT_EXPONENT_MASK = 0x7F800000;
+        static const unsigned int FLOAT_NORMAL_MASK = 0x00800000;
+        static const unsigned int FLOAT_E_OFFSET = 150;
+
+    public:
+
+        BitOps();
+        virtual ~BitOps() {}
+
+    public:  // Statics
+
+        static unsigned int TIMES_TEN( unsigned int x ) {
+            return ((x) << 3) + ((x) << 1);
+        }
+
+        static unsigned long long TIMES_TEN( unsigned long long x ) {
+            return ((x) << 3) + ((x) << 1);
+        }
+
+        static unsigned long long CREATE_DOUBLE_BITS(
+            unsigned long long normalizedM, unsigned long long e ) {
+
+            return ( normalizedM & MANTISSA_MASK ) | ( ( e + E_OFFSET ) << 52 );
+        }
+
+        static unsigned long long CREATE_DOUBLE_BITS(
+            unsigned long long* normalizedM, int index, unsigned long long e ) {
+
+            return ( normalizedM[index] & MANTISSA_MASK ) | ( ( e + E_OFFSET ) << 52 );
+        }
+
+        static unsigned long long bitSection(
+            unsigned long long x, unsigned long long mask, int shift ) {
+
+            return ( x & mask ) >> shift;
+        }
+        static unsigned int bitSection(
+            unsigned int x, unsigned int mask, int shift ) {
+
+            return ( x & mask ) >> shift;
+        }
+
+        static unsigned int& LOW_U32_FROM_LONG64( unsigned long long long64 ) {
+            return LOW_U32_FROM_LONG64_PTR( &long64 );
+        }
+
+        static unsigned int& HIGH_U32_FROM_LONG64( unsigned long long long64 ) {
+            return HIGH_U32_FROM_LONG64_PTR( &long64 );
+        }
+
+        static int& LOW_I32_FROM_LONG64( unsigned long long long64 ) {
+            return LOW_I32_FROM_LONG64_PTR( &long64 );
+        }
+
+        static int& HIGH_I32_FROM_LONG64( unsigned long long long64 ) {
+            return HIGH_I32_FROM_LONG64_PTR( &long64 );
+        }
+
+        static unsigned int& LOW_U32_FROM_LONG64_PTR( unsigned long long* long64ptr ) {
+            return ( (LONG_UNION*)long64ptr )->intValue[LoWord];
+        }
+
+        static unsigned int& HIGH_U32_FROM_LONG64_PTR( unsigned long long* long64ptr ) {
+            return ( (LONG_UNION*)long64ptr )->intValue[HiWord];
+        }
+
+        static int& LOW_I32_FROM_LONG64_PTR( unsigned long long* long64ptr ) {
+            return ( (LONG_UNION*)long64ptr )->sintValue[LoWord];
+        }
+
+        static int& HIGH_I32_FROM_LONG64_PTR( unsigned long long* long64ptr ) {
+            return ( (LONG_UNION*)long64ptr )->sintValue[HiWord];
+        }
+
+        static unsigned int at( unsigned int i ) {
+            #ifdef APR_IS_BIGENDIAN
+                return i^1;
+            #else
+                return i;
+            #endif
+        }
+
+    };
+
+}}}
+
+#endif /*_DECAF_INTERNAL_UTIL_BITOPS_H_*/

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/FloatingPointParser.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/FloatingPointParser.cpp?view=diff&rev=564226&r1=564225&r2=564226
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/FloatingPointParser.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/FloatingPointParser.cpp Thu Aug  9 07:40:50 2007
@@ -23,6 +23,8 @@
 #include <decaf/lang/Double.h>
 #include <decaf/lang/Character.h>
 #include <decaf/internal/util/HexStringParser.h>
+#include <decaf/internal/util/BigInt.h>
+#include <decaf/internal/util/BitOps.h>
 #include <apr_lib.h>
 
 using namespace std;
@@ -37,21 +39,21 @@
 
     // assumes s is a null terminated string with at least one
     // character in it
-    LONG_UNION def[17];
-    LONG_UNION defBackup[17];
-    LONG_UNION* f;
-    LONG_UNION* fNoOverflow;
+    unsigned long long def[17];
+    unsigned long long defBackup[17];
+    unsigned long long* f;
+    unsigned long long* fNoOverflow;
     unsigned long long* g;
     unsigned long long* tempBackup;
     unsigned int overflow = 0;
-    double result = 0.0;
+    unsigned long long result = 0;
     int index = 1;
     int unprocessedDigits = 0;
     std::string::const_iterator valItr = value.begin();
 
     f = def;
     fNoOverflow = defBackup;
-    (*f).longValue = 0;
+    (*f) = 0;
     tempBackup = g = 0;
 
     do {
@@ -63,75 +65,77 @@
             // MAX_ACCURACY_WIDTH.
 
             memcpy( fNoOverflow, f, sizeof(unsigned long long) * index );
-            overflow = simpleAppendDecimalDigitHighPrecision( f, index, *valItr - '0' );
-//            if( overflow ) {
-//                f[index++] = overflow;
-//                /* There is an overflow, but there is no more room
-//                 * to store the result. We really only need the top 52
-//                 * bits anyway, so we must back out of the overflow,
-//                 * and ignore the rest of the string.
-//                 */
-//                if (index >= MAX_ACCURACY_WIDTH) {
-//                  index--;
-//                  memcpy (f, fNoOverflow, sizeof (U_64) * index);
-//                  break;
-//                }
-//
-//                if (tempBackup) {
-//                  fNoOverflow = tempBackup;
-//                }
-//            }
-//        } else {
-//            index = -1;
-//        }
+            overflow = BigInt::simpleAppendDecimalDigitHighPrecision(
+                    f, index, *valItr - '0' );
+
+            if( overflow ) {
+                f[index++] = overflow;
+                /* There is an overflow, but there is no more room
+                 * to store the result. We really only need the top 52
+                 * bits anyway, so we must back out of the overflow,
+                 * and ignore the rest of the string.
+                 */
+                if( index >= MAX_ACCURACY_WIDTH ) {
+                    index--;
+                    memcpy( f, fNoOverflow, sizeof(unsigned long long) * index);
+                    break;
+                }
+
+                if( tempBackup ) {
+                    fNoOverflow = tempBackup;
+                }
+            }
+        } else {
+            index = -1;
+        }
 
     } while( index > 0 && *(++valItr) != '\0' );
-//
-//    /* We've broken out of the parse loop either because we've reached
-//     * the end of the string or we've overflowed the maximum accuracy
-//     * limit of a double. If we still have unprocessed digits in the
-//     * given string, then there are three possible results:
-//     *   1. (unprocessed digits + e) == 0, in which case we simply
-//     *      convert the existing bits that are already parsed
-//     *   2. (unprocessed digits + e) < 0, in which case we simply
-//     *      convert the existing bits that are already parsed along
-//     *      with the given e
-//     *   3. (unprocessed digits + e) > 0 indicates that the value is
-//     *      simply too big to be stored as a double, so return Infinity
-//     */
-//    if( ( unprocessedDigits = strlen (s) ) > 0 ) {
-//
-//        e += unprocessedDigits;
-//        if( index > -1 ) {
-//
-//            if (e == 0) {
-//                result = toDoubleHighPrecision (f, index);
-//            }
-//            else if (e < 0) {
-//                result = createDouble1 (env, f, index, e);
-//            } else {
-//                DOUBLE_TO_LONGBITS (result) = INFINITE_LONGBITS;
-//            }
-//        } else {
-//
-//            LOW_I32_FROM_VAR( result ) = -1;
-//            HIGH_I32_FROM_VAR( result ) = -1;
-//        }
-//    } else {
-//
-//        if( index > -1 ) {
-//            if( e == 0 ) {
-//                result = toDoubleHighPrecision( f, index );
-//            } else {
-//                result = createDouble1( env, f, index, e );
-//            } else {
-//                LOW_I32_FROM_VAR( result ) = -1;
-//                HIGH_I32_FROM_VAR( result ) = -1;
-//            }
-//        }
-//    }
 
-    return result;
+    /* We've broken out of the parse loop either because we've reached
+     * the end of the string or we've overflowed the maximum accuracy
+     * limit of a double. If we still have unprocessed digits in the
+     * given string, then there are three possible results:
+     *   1. (unprocessed digits + e) == 0, in which case we simply
+     *      convert the existing bits that are already parsed
+     *   2. (unprocessed digits + e) < 0, in which case we simply
+     *      convert the existing bits that are already parsed along
+     *      with the given e
+     *   3. (unprocessed digits + e) > 0 indicates that the value is
+     *      simply too big to be stored as a double, so return Infinity
+     */
+    if( ( unprocessedDigits = value.length() ) > 0 ) {
+
+        exp += unprocessedDigits;
+        if( index > -1 ) {
+
+            if( exp == 0 ) {
+                return BigInt::toDoubleHighPrecision( f, index );
+            } else if( exp < 0 ) {
+                return BitOps::CREATE_DOUBLE_BITS( f, index, exp );
+            } else {
+                result = BitOps::INFINITE_LONGBITS;
+            }
+
+        } else {
+
+            BitOps::LOW_I32_FROM_LONG64( result ) = -1;
+            BitOps::HIGH_I32_FROM_LONG64( result ) = -1;
+        }
+    } else {
+
+        if( index > -1 ) {
+            if( exp == 0 ) {
+                return BigInt::toDoubleHighPrecision( f, index );
+            } else {
+                return BitOps::CREATE_DOUBLE_BITS( f, index, exp );
+            }
+        } else {
+            BitOps::LOW_I32_FROM_LONG64( result ) = -1;
+            BitOps::HIGH_I32_FROM_LONG64( result ) = -1;
+        }
+    }
+
+    return Double::longBitsToDouble( result );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -433,28 +437,4 @@
     }
 
     return value;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-unsigned int FloatingPointParser::simpleAppendDecimalDigitHighPrecision(
-    LONG_UNION* arg1, int length, unsigned long long digit )
-{
-    // assumes digit is less than 32 bits
-    unsigned long long arg;
-    IDATA index = 0;
-
-    digit <<= 32;
-
-    do {
-        arg = LOW_IN_U64 (arg1[index]);
-        digit = HIGH_IN_U64 (digit) + TIMES_TEN (arg);
-        LOW_U32_FROM_PTR (arg1 + index) = LOW_U32_FROM_VAR (digit);
-
-        arg = HIGH_IN_U64 (arg1[index]);
-        digit = HIGH_IN_U64 (digit) + TIMES_TEN (arg);
-        HIGH_U32_FROM_PTR (arg1 + index) = LOW_U32_FROM_VAR (digit);
-    }
-    while( ++index < length );
-
-    return HIGH_U32_FROM_VAR( digit );
 }

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/FloatingPointParser.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/FloatingPointParser.h?view=diff&rev=564226&r1=564225&r2=564226
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/FloatingPointParser.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/FloatingPointParser.h Thu Aug  9 07:40:50 2007
@@ -47,12 +47,8 @@
             }
         };
 
-        // Used to make masking easier
-        typedef union {
-            unsigned long long longValue;
-            unsigned int intValue[2];
-            double doubleValue;
-        } LONG_UNION;
+        static const int MAX_ACCURACY_WIDTH = 17;
+        static const int DEFAULT_WIDTH = MAX_ACCURACY_WIDTH;
 
     public:
 

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/HexStringParser.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/HexStringParser.cpp?view=diff&rev=564226&r1=564225&r2=564226
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/HexStringParser.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/HexStringParser.cpp Thu Aug  9 07:40:50 2007
@@ -253,7 +253,9 @@
     const std::string& strIntegerPart, const std::string& strDecimalPart ) {
 
     std::string significand = strIntegerPart + strDecimalPart;
-    significand = significand.replaceFirst( "^0+", "" );
+
+    replaceFirst( significand, "^0x", "" );
+
     if( significand.length() == 0 ) {
         significand = "0"; //$NON-NLS-1$
     }
@@ -264,7 +266,9 @@
 int HexStringParser::getOffset(
     const std::string& strIntegerPart, const std::string& strDecimalPart ) {
 
-    strIntegerPart = strIntegerPart.replaceFirst( "^0+", "" );
+    std::string strIntegerPart2 = strIntegerPart;
+
+    replaceFirst( strIntegerPart2, "^0+", "" );
 
     //If the Interger part is a nonzero number.
     if( strIntegerPart.length() != 0 ) {
@@ -275,9 +279,9 @@
 
     //If the Interger part is a zero number.
     int i;
-    for( i = 0; i < strDecimalPart.length() && strDecimalPart.at(i) == '0'; i++ );
+    for( i = 0; (std::size_t)i < strDecimalPart.length() && strDecimalPart.at(i) == '0'; i++ );
 
-    if( i == strDecimalPart.length() ) {
+    if( (std::size_t)i == strDecimalPart.length() ) {
         return 0;
     }
 

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/HexStringParser.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/HexStringParser.h?view=diff&rev=564226&r1=564225&r2=564226
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/HexStringParser.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/HexStringParser.h Thu Aug  9 07:40:50 2007
@@ -177,6 +177,16 @@
          */
         static std::string* getSegmentsFromHexString( const std::string& hexString );
 
+        std::string& replaceFirst( std::string& target,
+                                   const std::string& find,
+                                   const std::string& replace ) {
+
+            std::string::size_type pos = std::string::npos;
+
+            if( ( pos = target.find_first_of( find, 0 ) ) != std::string::npos ) {
+                return target.replace( pos, find.length(), replace );
+            }
+        }
     };
 
 }}}