3v4l.org

run code in 300+ PHP versions simultaneously
<?php function roundUp(float $num, int $precision): float { assert($precision > 0); $mul = [pow(10.0, $precision), 1.0 / (2 * pow(10.0, $precision - 1))]; return ($num * $mul[0] + $mul[1]) / $mul; } $as = [8.784512605042, 8.781512605042, 10.44445]; foreach ($as as $a) { //echo '#1: ' . number_format(number_format($a, 3), 2) . PHP_EOL; //echo '#2: ' . round(($a * 100 + 0.5) / 100.0, 2) . PHP_EOL; echo roundUp($a, 2) . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 10
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/PHA4N
function name:  (null)
number of ops:  12
compiled vars:  !0 = $as, !1 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                   !0, <array>
   13     1      > FE_RESET_R                                       $3      !0, ->10
          2    > > FE_FETCH_R                                               $3, !1, ->10
   16     3    >   INIT_FCALL                                               'roundup'
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 2
          6        DO_FCALL                                      0  $4      
          7        CONCAT                                           ~5      $4, '%0A'
          8        ECHO                                                     ~5
   13     9      > JMP                                                      ->2
         10    >   FE_FREE                                                  $3
   17    11      > RETURN                                                   1

Function roundup:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PHA4N
function name:  roundUp
number of ops:  31
compiled vars:  !0 = $num, !1 = $precision, !2 = $mul
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        ASSERT_CHECK                                             
          3        INIT_FCALL                                               'assert'
          4        IS_SMALLER                                       ~3      0, !1
          5        SEND_VAL                                                 ~3
          6        SEND_VAL                                                 'assert%28%24precision+%3E+0%29'
          7        DO_ICALL                                                 
    7     8        INIT_FCALL                                               'pow'
          9        SEND_VAL                                                 10
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $5      
         12        INIT_ARRAY                                       ~6      $5
         13        INIT_FCALL                                               'pow'
         14        SEND_VAL                                                 10
         15        SUB                                              ~7      !1, 1
         16        SEND_VAL                                                 ~7
         17        DO_ICALL                                         $8      
         18        MUL                                              ~9      $8, 2
         19        DIV                                              ~10     1, ~9
         20        ADD_ARRAY_ELEMENT                                ~6      ~10
         21        ASSIGN                                                   !2, ~6
    9    22        FETCH_DIM_R                                      ~12     !2, 0
         23        MUL                                              ~13     !0, ~12
         24        FETCH_DIM_R                                      ~14     !2, 1
         25        ADD                                              ~15     ~13, ~14
         26        DIV                                              ~16     ~15, !2
         27        VERIFY_RETURN_TYPE                                       ~16
         28      > RETURN                                                   ~16
   10    29*       VERIFY_RETURN_TYPE                                       
         30*     > RETURN                                                   null

End of function roundup

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.8 ms | 1019 KiB | 16 Q