3v4l.org

run code in 300+ PHP versions simultaneously
<?php function encode($int) { $int = round($int); $left = 0xffffffff00000000; $right = 0x00000000ffffffff; $l = ($int & $left) >>32; $r = $int & $right; return unpack('d', pack('NN', $l, $r))[1]; } function decode($float) { $set = unpack('N2', pack('d', $float)); return $set[1] << 32 | $set[2]; } echo decode(encode(10000000000000)).'<br><br>'; $float = encode(10000000000000); echo $float.'<br>'; echo decode($float).'<br>'; echo decode(1.1710299640683E-305).'<br>'; echo 1.1710299640683E-305;echo "<br>"; var_dump(1.1710299640683E-305 == $float);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bFoFG
function name:  (null)
number of ops:  31
compiled vars:  !0 = $float
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_FCALL                                               'decode'
          1        INIT_FCALL                                               'encode'
          2        SEND_VAL                                                 10000000000000
          3        DO_FCALL                                      0  $1      
          4        SEND_VAR                                                 $1
          5        DO_FCALL                                      0  $2      
          6        CONCAT                                           ~3      $2, '%3Cbr%3E%3Cbr%3E'
          7        ECHO                                                     ~3
   20     8        INIT_FCALL                                               'encode'
          9        SEND_VAL                                                 10000000000000
         10        DO_FCALL                                      0  $4      
         11        ASSIGN                                                   !0, $4
   21    12        CONCAT                                           ~6      !0, '%3Cbr%3E'
         13        ECHO                                                     ~6
   22    14        INIT_FCALL                                               'decode'
         15        SEND_VAR                                                 !0
         16        DO_FCALL                                      0  $7      
         17        CONCAT                                           ~8      $7, '%3Cbr%3E'
         18        ECHO                                                     ~8
   23    19        INIT_FCALL                                               'decode'
         20        SEND_VAL                                                 1.17103e-305
         21        DO_FCALL                                      0  $9      
         22        CONCAT                                           ~10     $9, '%3Cbr%3E'
         23        ECHO                                                     ~10
   24    24        ECHO                                                     1.17103e-305
         25        ECHO                                                     '%3Cbr%3E'
   25    26        INIT_FCALL                                               'var_dump'
         27        IS_EQUAL                                         ~11     !0, 1.17103e-305
         28        SEND_VAL                                                 ~11
         29        DO_ICALL                                                 
         30      > RETURN                                                   1

Function encode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bFoFG
function name:  encode
number of ops:  24
compiled vars:  !0 = $int, !1 = $left, !2 = $right, !3 = $l, !4 = $r
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        INIT_FCALL                                               'round'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !0, $5
    5     5        ASSIGN                                                   !1, 1.84467e+19
    6     6        ASSIGN                                                   !2, 4294967295
    8     7        BW_AND                                           ~9      !0, !1
          8        SR                                               ~10     ~9, 32
          9        ASSIGN                                                   !3, ~10
    9    10        BW_AND                                           ~12     !0, !2
         11        ASSIGN                                                   !4, ~12
   11    12        INIT_FCALL                                               'unpack'
         13        SEND_VAL                                                 'd'
         14        INIT_FCALL                                               'pack'
         15        SEND_VAL                                                 'NN'
         16        SEND_VAR                                                 !3
         17        SEND_VAR                                                 !4
         18        DO_ICALL                                         $14     
         19        SEND_VAR                                                 $14
         20        DO_ICALL                                         $15     
         21        FETCH_DIM_R                                      ~16     $15, 1
         22      > RETURN                                                   ~16
   12    23*     > RETURN                                                   null

End of function encode

Function decode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bFoFG
function name:  decode
number of ops:  16
compiled vars:  !0 = $float, !1 = $set
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        INIT_FCALL                                               'unpack'
          2        SEND_VAL                                                 'N2'
          3        INIT_FCALL                                               'pack'
          4        SEND_VAL                                                 'd'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7        SEND_VAR                                                 $2
          8        DO_ICALL                                         $3      
          9        ASSIGN                                                   !1, $3
   15    10        FETCH_DIM_R                                      ~5      !1, 1
         11        SL                                               ~6      ~5, 32
         12        FETCH_DIM_R                                      ~7      !1, 2
         13        BW_OR                                            ~8      ~6, ~7
         14      > RETURN                                                   ~8
   16    15*     > RETURN                                                   null

End of function decode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.65 ms | 1403 KiB | 26 Q