activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r564621 - in /activemq/activemq-cpp/trunk/src/decaf/src: main/ main/decaf/internal/util/ main/decaf/lang/ test/ test/decaf/lang/
Date Fri, 10 Aug 2007 15:37:48 GMT
Author: tabish
Date: Fri Aug 10 08:37:42 2007
New Revision: 564621

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

Implementing the Primitive Wrappers fully

Modified:
    activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/NumberConverter.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/NumberConverter.h
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/Float.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/FloatTest.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/FloatTest.h
    activemq/activemq-cpp/trunk/src/decaf/src/test/testRegistry.cpp

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am?view=diff&rev=564621&r1=564620&r2=564621
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/Makefile.am Fri Aug 10 08:37:42 2007
@@ -58,6 +58,7 @@
    decaf/util/Config.cpp \
    decaf/internal/util/BigInt.cpp \
    decaf/internal/util/BitOps.cpp \
+   decaf/internal/util/NumberConverter.cpp \
    decaf/internal/util/FloatingPointParser.cpp \
    decaf/internal/util/HexStringParser.cpp
 
@@ -149,6 +150,7 @@
    decaf/util/logging/LogWriter.h \
    decaf/util/logging/SimpleLogger.h \
    decaf/util/logging/PropertiesChangeListener.h \
+   decaf/internal/util/NumberConverter.h \
    decaf/internal/util/FloatingPointParser.h \
    decaf/internal/util/HexStringParser.h \
    decaf/internal/util/BitOps.h \

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/NumberConverter.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/NumberConverter.cpp?view=diff&rev=564621&r1=564620&r2=564621
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/NumberConverter.cpp
(original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/NumberConverter.cpp
Fri Aug 10 08:37:42 2007
@@ -18,6 +18,12 @@
 #include "NumberConverter.h"
 
 #include <decaf/lang/Math.h>
+#include <decaf/lang/Float.h>
+#include <decaf/lang/Double.h>
+#include <decaf/lang/Integer.h>
+
+#include <decaf/internal/util/BigInt.h>
+#include <decaf/internal/util/BitOps.h>
 
 using namespace decaf;
 using namespace decaf::lang;
@@ -28,6 +34,7 @@
 const double NumberConverter::invLogOfTenBaseTwo =
     Math::log(2.0) / Math::log(10.0);
 NumberConverter::StaticInitializer NumberConverter::init;
+std::vector<long long> NumberConverter::TEN_TO_THE;
 
 ////////////////////////////////////////////////////////////////////////////////
 NumberConverter::StaticInitializer::StaticInitializer() {
@@ -35,7 +42,7 @@
     NumberConverter::TEN_TO_THE.resize(20);
     NumberConverter::TEN_TO_THE[0] = 1L;
 
-    for( int i = 1; i < TEN_TO_THE.length; ++i ) {
+    for( std::size_t i = 1; i < TEN_TO_THE.size(); ++i ) {
         long long previous = TEN_TO_THE[i - 1];
         TEN_TO_THE[i] = ( previous << 1 ) + ( previous << 3 );
     }
@@ -56,13 +63,13 @@
     unsigned int p = 1023 + 52; // the power offset (precision)
 
     // the mask to get the sign of the number
-    unsigned long long signMask = 0x8000000000000000L;
+    unsigned long long signMask = 0x8000000000000000ULL;
     // the mask to get the power bits
-    unsigned long long eMask = 0x7FF0000000000000L;
+    unsigned long long eMask = 0x7FF0000000000000ULL;
     // the mask to get the significand bits
-    unsigned long long fMask = 0x000FFFFFFFFFFFFFL;
+    unsigned long long fMask = 0x000FFFFFFFFFFFFFULL;
 
-    unsigned long long inputNumberBits = Double::doubleToLongBits(value);
+    unsigned long long inputNumberBits = Double::doubleToLongBits( value );
     // the value of the sign... 0 is positive, ~0 is negative
     std::string signString = ( inputNumberBits & signMask ) == 0 ? "" : "-";
     // the value of the 'power bits' of the value
@@ -70,7 +77,7 @@
     // the value of the 'significand bits' of the value
     unsigned long long f = inputNumberBits & fMask;
     bool mantissaIsZero = (f == 0);
-    unsigned int pow = 0, numBits = 52;
+    int pow = 0, numBits = 52;
 
     if( e == 2047 ) {
         return mantissaIsZero ? signString + "Infinity" : "NaN";
@@ -90,14 +97,14 @@
 
         pow = 1 - p; // a denormalized number
         long long ff = f;
-        while( (ff & 0x0010000000000000L) == 0 ) {
+        while( (ff & 0x0010000000000000ULL ) == 0 ) {
             ff = ff << 1;
             numBits--;
         }
     } else {
         // 0 < e < 2047
         // a "normalized" number
-        f = f | 0x0010000000000000L;
+        f = f | 0x0010000000000000ULL;
         pow = e - p;
     }
 
@@ -107,8 +114,8 @@
         bigIntDigitGeneratorInstImpl( f, pow, e == 0, mantissaIsZero, numBits );
     }
 
-    if( value >= 1e7D || value <= -1e7D ||
-        ( value > -1e-3D && value < 1e-3D ) ) {
+    if( value >= 1e7 || value <= -1e7 ||
+        ( value > -1e-3 && value < 1e-3 ) ) {
         return signString + freeFormatExponential();
     }
 
@@ -131,7 +138,7 @@
     // the value of the 'significand bits' of the value
     unsigned int f = inputNumberBits & fMask;
     bool mantissaIsZero = ( f == 0 );
-    unsigned int pow = 0, numBits = 23;
+    int pow = 0, numBits = 23;
 
     if( e == 255 ) {
         return mantissaIsZero ? signString + "Infinity" : "NaN";
@@ -178,7 +185,7 @@
 std::string NumberConverter::freeFormatExponential() {
 
     // corresponds to process "Free-Format Exponential"
-    char[25] formattedDecimal = {0};
+    char formattedDecimal[25] = {0};
     formattedDecimal[0] = (char)( '0' + uArray[getCount++] );
     formattedDecimal[1] = '.';
     // the position the next character is to be inserted into
@@ -208,7 +215,7 @@
 std::string NumberConverter::freeFormat() {
 
     // corresponds to process "Free-Format"
-    char[25] formattedDecimal = {0};
+    char formattedDecimal[25] = {0};
     // the position the next character is to be inserted into
     // formattedDecimal
     int charPos = 0;
@@ -246,8 +253,8 @@
 void NumberConverter::bigIntDigitGeneratorInstImpl(
     long long f, int e, bool isDenormalized, bool mantissaIsZero, int p ) {
 
-    static std::size_t RM_SIZE 21;
-    static std::size_t STemp_SIZE 22;
+    static const std::size_t RM_SIZE = 21;
+    static const std::size_t STemp_SIZE = 22;
 
     unsigned int RLength, SLength, TempLength, mplus_Length, mminus_Length;
     int high, low, i;
@@ -263,11 +270,11 @@
 
         *R = f;
         *mplus = *mminus = 1;
-        simpleShiftLeftHighPrecision( mminus, RM_SIZE, e );
+        BigInt::simpleShiftLeftHighPrecision( mminus, RM_SIZE, e );
 
         if( f != (2 << (p - 1)) ) {
 
-            simpleShiftLeftHighPrecision( R, RM_SIZE, e + 1 );
+            BigInt::simpleShiftLeftHighPrecision( R, RM_SIZE, e + 1 );
             *S = 2;
 
             /*
@@ -278,13 +285,13 @@
              *      470fffffffffffff = 2.0769187434139308E34
              *      4710000000000000 = 2.076918743413931E34
              */
-            simpleShiftLeftHighPrecision(mplus, RM_SIZE, e);
+            BigInt::simpleShiftLeftHighPrecision(mplus, RM_SIZE, e);
 
         } else {
 
-            simpleShiftLeftHighPrecision( R, RM_SIZE, e + 2 );
+            BigInt::simpleShiftLeftHighPrecision( R, RM_SIZE, e + 2 );
             *S = 4;
-            simpleShiftLeftHighPrecision( mplus, RM_SIZE, e + 1 );
+            BigInt::simpleShiftLeftHighPrecision( mplus, RM_SIZE, e + 1 );
         }
 
     } else {
@@ -293,34 +300,34 @@
 
             *R = f << 1;
             *S = 1;
-            simpleShiftLeftHighPrecision( S, STemp_SIZE, 1 - e );
+            BigInt::simpleShiftLeftHighPrecision( S, STemp_SIZE, 1 - e );
             *mplus = *mminus = 1;
 
         } else {
 
             *R = f << 2;
             *S = 1;
-            simpleShiftLeftHighPrecision( S, STemp_SIZE, 2 - e );
+            BigInt::simpleShiftLeftHighPrecision( S, STemp_SIZE, 2 - e );
             *mplus = 2;
             *mminus = 1;
         }
     }
 
-    k = (int) ceil ((e + p - 1) * INV_LOG_OF_TEN_BASE_2 - 1e-10);
+    k = (int)Math::ceil( (e + p - 1) * invLogOfTenBaseTwo - 1e-10 );
 
     if( k > 0 ) {
-        timesTenToTheEHighPrecision( S, STemp_SIZE, k );
+        BigInt::timesTenToTheEHighPrecision( S, STemp_SIZE, k );
     } else {
-      timesTenToTheEHighPrecision( R, RM_SIZE, -k );
-      timesTenToTheEHighPrecision( mplus, RM_SIZE, -k );
-      timesTenToTheEHighPrecision( mminus, RM_SIZE, -k );
+        BigInt::timesTenToTheEHighPrecision( R, RM_SIZE, -k );
+        BigInt::timesTenToTheEHighPrecision( mplus, RM_SIZE, -k );
+        BigInt::timesTenToTheEHighPrecision( mminus, RM_SIZE, -k );
     }
 
     RLength = mplus_Length = mminus_Length = RM_SIZE;
     SLength = TempLength = STemp_SIZE;
 
-    memset( Temp + RM_SIZE, 0, (STemp_SIZE - RM_SIZE) * sizeof (U_64) );
-    memcpy( Temp, R, RM_SIZE * sizeof (U_64) );
+    memset( Temp + RM_SIZE, 0, (STemp_SIZE - RM_SIZE) * sizeof (unsigned long long) );
+    memcpy( Temp, R, RM_SIZE * sizeof (unsigned long long) );
 
     while( RLength > 1 && R[RLength - 1] == 0 ) {
         --RLength;
@@ -336,16 +343,16 @@
     }
 
     TempLength = (RLength > mplus_Length ? RLength : mplus_Length) + 1;
-    addHighPrecision( Temp, TempLength, mplus, mplus_Length );
+    BigInt::addHighPrecision( Temp, TempLength, mplus, mplus_Length );
 
-    if( compareHighPrecision (Temp, TempLength, S, SLength) >= 0 ) {
+    if( BigInt::compareHighPrecision (Temp, TempLength, S, SLength) >= 0 ) {
         firstK = k;
     } else {
 
         firstK = k - 1;
-        simpleAppendDecimalDigitHighPrecision( R, ++RLength, 0 );
-        simpleAppendDecimalDigitHighPrecision( mplus, ++mplus_Length, 0 );
-        simpleAppendDecimalDigitHighPrecision( mminus, ++mminus_Length, 0 );
+        BigInt::simpleAppendDecimalDigitHighPrecision( R, ++RLength, 0 );
+        BigInt::simpleAppendDecimalDigitHighPrecision( mplus, ++mplus_Length, 0 );
+        BigInt::simpleAppendDecimalDigitHighPrecision( mminus, ++mminus_Length, 0 );
         while( RLength > 1 && R[RLength - 1] == 0 ) {
             --RLength;
         }
@@ -364,30 +371,30 @@
         for( i = 3; i >= 0; --i ) {
             TempLength = SLength + 1;
             Temp[SLength] = 0;
-            memcpy (Temp, S, SLength * sizeof (U_64));
-            simpleShiftLeftHighPrecision( Temp, TempLength, i );
-            if( compareHighPrecision( R, RLength, Temp, TempLength ) >= 0 ) {
-                subtractHighPrecision( R, RLength, Temp, TempLength );
+            memcpy( Temp, S, SLength * sizeof(unsigned long long) );
+            BigInt::simpleShiftLeftHighPrecision( Temp, TempLength, i );
+            if( BigInt::compareHighPrecision( R, RLength, Temp, TempLength ) >= 0 ) {
+                BigInt::subtractHighPrecision( R, RLength, Temp, TempLength );
                 U += 1 << i;
             }
         }
 
-        low = compareHighPrecision( R, RLength, mminus, mminus_Length ) <= 0;
+        low = BigInt::compareHighPrecision( R, RLength, mminus, mminus_Length ) <= 0;
 
-        memset( Temp + RLength, 0, (STemp_SIZE - RLength) * sizeof(U_64) );
-        memcpy( Temp, R, RLength * sizeof(U_64) );
+        memset( Temp + RLength, 0, (STemp_SIZE - RLength) * sizeof(unsigned long long) );
+        memcpy( Temp, R, RLength * sizeof(unsigned long long) );
         TempLength = (RLength > mplus_Length ? RLength : mplus_Length) + 1;
-        addHighPrecision( Temp, TempLength, mplus, mplus_Length );
+        BigInt::addHighPrecision( Temp, TempLength, mplus, mplus_Length );
 
-        high = compareHighPrecision( Temp, TempLength, S, SLength ) >= 0;
+        high = BigInt::compareHighPrecision( Temp, TempLength, S, SLength ) >= 0;
 
         if( low || high ) {
             break;
         }
 
-        simpleAppendDecimalDigitHighPrecision( R, ++RLength, 0 );
-        simpleAppendDecimalDigitHighPrecision( mplus, ++mplus_Length, 0 );
-        simpleAppendDecimalDigitHighPrecision( mminus, ++mminus_Length, 0 );
+        BigInt::simpleAppendDecimalDigitHighPrecision( R, ++RLength, 0 );
+        BigInt::simpleAppendDecimalDigitHighPrecision( mplus, ++mplus_Length, 0 );
+        BigInt::simpleAppendDecimalDigitHighPrecision( mminus, ++mminus_Length, 0 );
         while( RLength > 1 && R[RLength - 1] == 0 ) {
             --RLength;
         }
@@ -401,13 +408,13 @@
     }
     while( true );
 
-    simpleShiftLeftHighPrecision( R, ++RLength, 1 );
+    BigInt::simpleShiftLeftHighPrecision( R, ++RLength, 1 );
 
     if( low && !high ) {
         uArray[setCount++] = U;
     } else if( high && !low ) {
         uArray[setCount++] = U + 1;
-    } else if( compareHighPrecision( R, RLength, S, SLength) < 0 ) {
+    } else if( BigInt::compareHighPrecision( R, RLength, S, SLength) < 0 ) {
         uArray[setCount++] = U;
     } else {
         uArray[setCount++] = U + 1;
@@ -461,7 +468,7 @@
     getCount = setCount = 0; // reset indices
     bool low, high;
     int U;
-    long long[] Si = new long long[] { S, S << 1, S << 2, S << 3 };
+    long long Si[4] = { S, S << 1, S << 2, S << 3 };
     while( true ) {
         // set U to be floor (R / S) and R to be the remainder
         // using a kind of "binary search" to find the answer.

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/NumberConverter.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/NumberConverter.h?view=diff&rev=564621&r1=564620&r2=564621
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/NumberConverter.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/internal/util/NumberConverter.h Fri
Aug 10 08:37:42 2007
@@ -18,6 +18,10 @@
 #ifndef _DECAF_INTERNAL_UTIL_NUMBERCONVERTER_H_
 #define _DECAF_INTERNAL_UTIL_NUMBERCONVERTER_H_
 
+#include <decaf/util/Config.h>
+#include <vector>
+#include <string>
+
 namespace decaf{
 namespace internal{
 namespace util{
@@ -81,9 +85,9 @@
         std::string freeFormat();
 
         void bigIntDigitGeneratorInstImpl(
-            long f, int e, bool isDenormalized, bool mantissaIsZero, int p );
+            long long f, int e, bool isDenormalized, bool mantissaIsZero, int p );
         void longDigitGenerator(
-            long f, int e, bool isDenormalized, bool mantissaIsZero, int p );
+            long long f, int e, bool isDenormalized, bool mantissaIsZero, int p );
 
     };
 

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=564621&r1=564620&r2=564621
==============================================================================
--- 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 10 08:37:42
2007
@@ -17,6 +17,8 @@
 
 #include "Float.h"
 #include <decaf/lang/Integer.h>
+#include <decaf/internal/util/FloatingPointParser.h>
+#include <decaf/internal/util/NumberConverter.h>
 
 using namespace std;
 using namespace decaf;
@@ -146,7 +148,7 @@
 float Float::parseFloat( const std::string& value )
     throw ( exceptions::NumberFormatException ) {
 
-    return 0.0; // TODO
+    return internal::util::FloatingPointParser::parseFloat( value );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -235,7 +237,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 std::string Float::toString( float value ) {
-    return ""; //TODO
+    return internal::util::NumberConverter::convert( value );
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/FloatTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/FloatTest.cpp?view=diff&rev=564621&r1=564620&r2=564621
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/FloatTest.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/FloatTest.cpp Fri Aug 10 08:37:42
2007
@@ -29,5 +29,15 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void FloatTest::test() {
+void FloatTest::test_ConstructorF() {
+    // Test for method decaf.lang.Float(float)
+    Float f( 900.89f );
+    CPPUNIT_ASSERT_MESSAGE( "Created incorrect float", f.floatValue() == 900.89f );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void FloatTest::test_ConstructorString() {
+    // Test for method decaf.lang.Float(decaf.lang.String)
+    Float f( "900.89" );
+    CPPUNIT_ASSERT_MESSAGE("Created incorrect Float", f.floatValue() == 900.89f);
 }

Modified: activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/FloatTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/FloatTest.h?view=diff&rev=564621&r1=564620&r2=564621
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/FloatTest.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/decaf/lang/FloatTest.h Fri Aug 10 08:37:42
2007
@@ -27,7 +27,8 @@
     class FloatTest : public CppUnit::TestFixture
     {
         CPPUNIT_TEST_SUITE( FloatTest );
-        CPPUNIT_TEST( test );
+        CPPUNIT_TEST( test_ConstructorF );
+        CPPUNIT_TEST( test_ConstructorString );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -35,7 +36,8 @@
         FloatTest();
         virtual ~FloatTest() {}
 
-        virtual void test();
+        void test_ConstructorF();
+        void test_ConstructorString();
 
     };
 

Modified: activemq/activemq-cpp/trunk/src/decaf/src/test/testRegistry.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/test/testRegistry.cpp?view=diff&rev=564621&r1=564620&r2=564621
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/test/testRegistry.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/test/testRegistry.cpp Fri Aug 10 08:37:42 2007
@@ -31,8 +31,8 @@
 //#include <decaf/io/DataOutputStreamTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::io::DataOutputStreamTest );
 
-#include <decaf/lang/MathTest.h>
-CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::MathTest );
+//#include <decaf/lang/MathTest.h>
+//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::MathTest );
 //#include <decaf/lang/ByteTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::ByteTest );
 //#include <decaf/lang/CharacterTest.h>
@@ -45,10 +45,10 @@
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::IntegerTest );
 //#include <decaf/lang/LongTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::LongTest );
-//#include <decaf/lang/FloatTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::FloatTest );
-//#include <decaf/lang/DoubleTest.h>
-//CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::DoubleTest );
+#include <decaf/lang/FloatTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::FloatTest );
+#include <decaf/lang/DoubleTest.h>
+CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::DoubleTest );
 //#include <decaf/lang/ExceptionTest.h>
 //CPPUNIT_TEST_SUITE_REGISTRATION( decaf::lang::ExceptionTest );
 //#include <decaf/lang/ThreadTest.h>



Mime
View raw message