ActiveMQ C++ Client
  1. ActiveMQ C++ Client
  2. AMQCPP-375

decaf::lang::Long::to{Hex,Binary,Octal}String problems

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: 3.3.0
    • Fix Version/s: 3.5.0
    • Component/s: Decaf
    • Labels:
      None
    • Patch Info:
      Patch Available

      Description

      decaf::lang::Long::to

      {Hex,Binary,Octal}

      String return the wrong result for numbers less than -2^32 (on platforms with 64 bit long long): the returned string only represents the low 32 bits.
      A separate problem causes decaf::lang::

      {Integer,Long}

      ::toOctalString to return the wrong result for negative numbers because there are not an even multiple of 3 bits.

      This test program demonstrates the problems
      $ cat test.cpp

      #include <iostream>

      #include <decaf/lang/Integer.h>
      #include <decaf/lang/Long.h>

      using namespace std;
      using namespace decaf::lang;

      void testLong (long long value)

      { cout << "testLong(" << dec << value << "LL)\n" << "\ndec:\t" << dec << value << "\ntoB10:\t" << Long::toString(value, 10) << "\nhex:\t" << hex << value << "\ntoHex:\t" << Long::toHexString(value) << "\noct:\t" << oct << value << "\ntoOct:\t" << Long::toOctalString(value) << "\noct:\t" << oct << value << "\ntoB8:\t" << Long::toString(value, 8) << "\nhex:\t" << hex << value << "\ntoBin:\t" << Long::toBinaryString(value) << "\n\n"; }

      void testInteger (int value)

      { cout << "testInteger(" << dec << value << ")\n" << "\ndec:\t" << dec << value << "\ntoB10:\t" << Integer::toString(value, 10) << "\nhex:\t" << hex << value << "\ntoHex:\t" << Integer::toHexString(value) << "\noct:\t" << oct << value << "\ntoOct:\t" << Integer::toOctalString(value) << "\noct:\t" << oct << value << "\ntoB8:\t" << Integer::toString(value, 8) << "\nhex:\t" << hex << value << "\ntoBin:\t" << Integer::toBinaryString(value) << "\n\n"; }

      int main (int argc, char **argv)

      { testLong(-1LL); testLong(-0xFF00000000LL); testInteger(-1); testInteger(0xDFFF0000); return 0; }

      $

      $ ./a.out
      testLong(-1LL)

      dec: -1
      toB10: -1
      hex: ffffffffffffffff
      toHex: ffffffff
      oct: 1777777777777777777777
      toOct: 77777777777
      oct: 1777777777777777777777
      toB8: -1
      hex: ffffffffffffffff
      toBin: 11111111111111111111111111111111

      testLong(-1095216660480LL)

      dec: -1095216660480
      toB10: -1095216660480
      hex: ffffff0100000000
      toHex: 00000000
      oct: 1777777760040000000000
      toOct: 40000000000
      oct: 1777777760040000000000
      toB8: -17740000000000
      hex: ffffff0100000000
      toBin: 00000000000000000000000000000000

      testInteger(-1)

      dec: -1
      toB10: -1
      hex: ffffffff
      toHex: ffffffff
      oct: 37777777777
      toOct: 77777777777
      oct: 37777777777
      toB8: -1
      hex: ffffffff
      toBin: 11111111111111111111111111111111

      testInteger(-536936448)

      dec: -536936448
      toB10: -536936448
      hex: dfff0000
      toHex: dfff0000
      oct: 33777600000
      toOct: 73777600000
      oct: 33777600000
      toB8: -4000200000
      hex: dfff0000
      toBin: 11011111111111110000000000000000

      $

        Activity

        Hide
        Timothy Bish added a comment -

        It would be great if you could add some new unit tests to go along with this to validate that this stays fixed long into the future.

        Show
        Timothy Bish added a comment - It would be great if you could add some new unit tests to go along with this to validate that this stays fixed long into the future.
        Hide
        Timothy Bish added a comment -

        Patch applied, no test provided so YMMV.

        Show
        Timothy Bish added a comment - Patch applied, no test provided so YMMV.

          People

          • Assignee:
            Timothy Bish
            Reporter:
            Bob Wiegand
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 1h
              1h
              Remaining:
              Remaining Estimate - 1h
              1h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development