encoding a NSDecimalNumber as IEEE-754 on an intel mac

  • Hello.

    I am trying to encode a NSDecimalNumber with objCType 'd' as IEEE-754
    on a intel mac. It is working on a powerpc mac, but not on an intel
    mac. This is done as part of the HessianObjC framework to communicate
    between a cocoa client and a java server.

    double aDouble = [.... doubleValue];
    aDouble = EndianS64_NtoB(aDouble);
    [callData appendBytes:&aDouble length:sizeof(aDouble)];

    Perhaps double on intel macs are not encoded as IEEE-754 doubles? How
    can this be "fixed"? (I have googled a lot for this....)

      - Tore.
  • hello Tore,

    it works on ppc only because EndianS64_NtoB() is a no-op on ppc.

      #define EndianS64_NtoB(value)              (value)

    it's assigning a signed 64-bit integer value to aDouble (unwanted
    implicit type conversion) on i386 while it's assigning a double value
    to aDouble (no type conversion) on ppc.

    do this instead:

    double aDouble = [.... doubleValue];
    CFSwappedFloat64 bigEndian = CFConvertFloat64HostToSwapped(aDouble);
    [callData appendBytes:&bigEndian length:sizeof(bigEndian)];

    // note: CFConvertFloat64HostToSwapped() is actually HostToBig().

    regards,
    katsura

    On Oct 8, 2006, at 5:03 PM, Tore Halset wrote:

    > Hello.
    >
    > I am trying to encode a NSDecimalNumber with objCType 'd' as
    > IEEE-754 on a intel mac. It is working on a powerpc mac, but not on
    > an intel mac. This is done as part of the HessianObjC framework to
    > communicate between a cocoa client and a java server.
    >
    > double aDouble = [.... doubleValue];
    > aDouble = EndianS64_NtoB(aDouble);
    > [callData appendBytes:&aDouble length:sizeof(aDouble)];
    >
    > Perhaps double on intel macs are not encoded as IEEE-754 doubles?
    > How can this be "fixed"? (I have googled a lot for this....)
    >
    > - Tore.
  • On Oct 9, 2006, at 09:26, Hidetomo Katsura wrote:

    > do this instead:
    >
    > double aDouble = [.... doubleValue];
    > CFSwappedFloat64 bigEndian = CFConvertFloat64HostToSwapped(aDouble);
    > [callData appendBytes:&bigEndian length:sizeof(bigEndian)];
    >
    > // note: CFConvertFloat64HostToSwapped() is actually HostToBig().

    Thanks. This seem to fix the endian problem, but it still does not
    work on an intel mac. "12.25" on the intel client are decoded as
    8.6469112845513523E17 on the server. Perhaps intel does not use
    IEEE-754 to store their doubles?

      - Tore.
  • On Oct 9, 2006, at 19:59, Tore Halset wrote:

    > On Oct 9, 2006, at 09:26, Hidetomo Katsura wrote:
    >
    >> do this instead:
    >>
    >> double aDouble = [.... doubleValue];
    >> CFSwappedFloat64 bigEndian = CFConvertFloat64HostToSwapped(aDouble);
    >> [callData appendBytes:&bigEndian length:sizeof(bigEndian)];
    >>
    >> // note: CFConvertFloat64HostToSwapped() is actually HostToBig().
    >
    > Thanks. This seem to fix the endian problem, but it still does not
    > work on an intel mac. "12.25" on the intel client are decoded as
    > 8.6469112845513523E17 on the server. Perhaps intel does not use
    > IEEE-754 to store their doubles?

    Sorry, my mistake. I added the new line, but did not remove
    EndianS64_NtoB. Errrr.

    Thanks Hidetomo for very good help!

      - Tore.
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today