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, '.', ''); } print roundDownToHalf(4.9) . "\n"; print roundDownToHalf(4.8) . "\n"; print roundDownToHalf(4.5) . "\n"; print roundDownToHalf(3.8) . "\n"; print roundDownToHalf(2.3) . "\n"; print roundDownToHalf(1.0) . "\n"; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OEgbQ
function name:  (null)
number of ops:  31
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   INIT_FCALL                                               'rounddowntohalf'
          1        SEND_VAL                                                 4.9
          2        DO_FCALL                                      0  $0      
          3        CONCAT                                           ~1      $0, '%0A'
          4        ECHO                                                     ~1
   10     5        INIT_FCALL                                               'rounddowntohalf'
          6        SEND_VAL                                                 4.8
          7        DO_FCALL                                      0  $2      
          8        CONCAT                                           ~3      $2, '%0A'
          9        ECHO                                                     ~3
   11    10        INIT_FCALL                                               'rounddowntohalf'
         11        SEND_VAL                                                 4.5
         12        DO_FCALL                                      0  $4      
         13        CONCAT                                           ~5      $4, '%0A'
         14        ECHO                                                     ~5
   12    15        INIT_FCALL                                               'rounddowntohalf'
         16        SEND_VAL                                                 3.8
         17        DO_FCALL                                      0  $6      
         18        CONCAT                                           ~7      $6, '%0A'
         19        ECHO                                                     ~7
   13    20        INIT_FCALL                                               'rounddowntohalf'
         21        SEND_VAL                                                 2.3
         22        DO_FCALL                                      0  $8      
         23        CONCAT                                           ~9      $8, '%0A'
         24        ECHO                                                     ~9
   14    25        INIT_FCALL                                               'rounddowntohalf'
         26        SEND_VAL                                                 1
         27        DO_FCALL                                      0  $10     
         28        CONCAT                                           ~11     $10, '%0A'
         29        ECHO                                                     ~11
   15    30      > 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/OEgbQ
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:
178.03 ms | 1403 KiB | 21 Q