3v4l.org

run code in 300+ PHP versions simultaneously
<?php function roundDownToHalf($number) { $remainder = ($number * 10) % 10; $half = $remainder >= 5 ? 0.5 : 0; $value = floatval(intval($number) + $half); return number_format($value, 1, '.', ''); } define("ENDL", "\n"); print roundDownToHalf(4.9) . ENDL; print roundDownToHalf(4.8) . ENDL; print roundDownToHalf(4.5) . ENDL; print roundDownToHalf(3.8) . ENDL; print roundDownToHalf(2.3) . ENDL; print roundDownToHalf(1.0) . ENDL; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tYBqG
function name:  (null)
number of ops:  41
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'ENDL'
          2        SEND_VAL                                                 '%0A'
          3        DO_ICALL                                                 
   11     4        INIT_FCALL                                               'rounddowntohalf'
          5        SEND_VAL                                                 4.9
          6        DO_FCALL                                      0  $1      
          7        FETCH_CONSTANT                                   ~2      'ENDL'
          8        CONCAT                                           ~3      $1, ~2
          9        ECHO                                                     ~3
   12    10        INIT_FCALL                                               'rounddowntohalf'
         11        SEND_VAL                                                 4.8
         12        DO_FCALL                                      0  $4      
         13        FETCH_CONSTANT                                   ~5      'ENDL'
         14        CONCAT                                           ~6      $4, ~5
         15        ECHO                                                     ~6
   13    16        INIT_FCALL                                               'rounddowntohalf'
         17        SEND_VAL                                                 4.5
         18        DO_FCALL                                      0  $7      
         19        FETCH_CONSTANT                                   ~8      'ENDL'
         20        CONCAT                                           ~9      $7, ~8
         21        ECHO                                                     ~9
   14    22        INIT_FCALL                                               'rounddowntohalf'
         23        SEND_VAL                                                 3.8
         24        DO_FCALL                                      0  $10     
         25        FETCH_CONSTANT                                   ~11     'ENDL'
         26        CONCAT                                           ~12     $10, ~11
         27        ECHO                                                     ~12
   15    28        INIT_FCALL                                               'rounddowntohalf'
         29        SEND_VAL                                                 2.3
         30        DO_FCALL                                      0  $13     
         31        FETCH_CONSTANT                                   ~14     'ENDL'
         32        CONCAT                                           ~15     $13, ~14
         33        ECHO                                                     ~15
   16    34        INIT_FCALL                                               'rounddowntohalf'
         35        SEND_VAL                                                 1
         36        DO_FCALL                                      0  $16     
         37        FETCH_CONSTANT                                   ~17     'ENDL'
         38        CONCAT                                           ~18     $16, ~17
         39        ECHO                                                     ~18
   17    40      > RETURN                                                   1

Function rounddowntohalf:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tYBqG
function name:  roundDownToHalf
number of ops:  22
compiled vars:  !0 = $number, !1 = $remainder, !2 = $half, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        MUL                                              ~4      !0, 10
          2        MOD                                              ~5      ~4, 10
          3        ASSIGN                                                   !1, ~5
    4     4        IS_SMALLER_OR_EQUAL                                      5, !1
          5      > JMPZ                                                     ~7, ->8
          6    >   QM_ASSIGN                                        ~8      0.5
          7      > JMP                                                      ->9
          8    >   QM_ASSIGN                                        ~8      0
          9    >   ASSIGN                                                   !2, ~8
    5    10        CAST                                          4  ~10     !0
         11        ADD                                              ~11     ~10, !2
         12        CAST                                          5  ~12     ~11
         13        ASSIGN                                                   !3, ~12
    6    14        INIT_FCALL                                               'number_format'
         15        SEND_VAR                                                 !3
         16        SEND_VAL                                                 1
         17        SEND_VAL                                                 '.'
         18        SEND_VAL                                                 ''
         19        DO_ICALL                                         $14     
         20      > RETURN                                                   $14
    7    21*     > RETURN                                                   null

End of function rounddowntohalf

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.9 ms | 1402 KiB | 23 Q