Why is the number 16 converted to float (6.1026988574311E_320) using PHP using Zend_Amf

The Zend_Amf specification states that the Number type returned from flash will be displayed in float in PHP. Good. But why is the number 16 returned as 6.1026988574311E_320? The PHP version is 5.2.9, running on OS X.

I tried forced conversion to integer in PHP (the value above is rounded to 0), as well as from ActionScript using int (16) - the latter happens via NULL. How to make sure that Flash returns an integer through AMF and that PHP can handle it?

+3
source share
2 answers

endian. , Zend, flash . , ( ). .

#include <stdio.h>
#include <stdint.h>

int main(void)
{
  double d = 16;
  uint32_t *i = (uint32_t *)(&d);
  uint8_t *c = (uint8_t *)(&d);
  size_t j;

  printf("%08x %08x %lg\n", i[1], i[0], d);

  for(j = 0; j < sizeof(double) / 2; j++)
  {
        uint8_t tmp;

        tmp = c[j];
        c[j] = c[sizeof(double) - j - 1];
        c[sizeof(double) - j - 1] = tmp;
    }

  printf("%08x %08x %lg\n", i[1], i[0], d);

  return 0;
}

Intel ( )

40300000 00000000 16
00000000 00003040 6.1027e-320

, PPC Mac ( )? , . .

, , .

+6

, , , , . , :

void hexdump_double(double dbl)
{
    assert(8 == sizeof(dbl));
    printf("double: %02X %02X %02X %02X %02X %02X %02X %02X (%lg)\n",  
           ((char *)&(dbl))[0],
           ((char *)&(dbl))[1],
           ((char *)&(dbl))[2],
           ((char *)&(dbl))[3],
           ((char *)&(dbl))[4],
           ((char *)&(dbl))[5],
           ((char *)&(dbl))[6],
           ((char *)&(dbl))[7],
           dbl);
}

int main()
{
    hexdump_double(6.1026988574311E-320);
}

:

double: 40 30 00 00 00 00 00 00 (6.1027e-320)

, . "16".

Zend_Amf , ActionScript PHP, class Number, Adobe: Adobe.com Flex . , "" .

int 2 ^ 29 AMF , , Zend_Amf .

AMF ActionScript? ?

+1

Source: https://habr.com/ru/post/1719001/


All Articles