3v4l.org

run code in 300+ PHP versions simultaneously
<?php function bround($dVal,$iDec) { // banker's style rounding or round-half-even // (round down when even number is left of 5, otherwise round up) // $dVal is value to round // $iDec specifies number of decimal places to retain static $dFuzz=0.00001; // to deal with floating-point precision loss $iRoundup=0; // amount to round up by $iSign=($dVal!=0.0) ? intval($dVal/abs($dVal)) : 1; $dVal=abs($dVal); // get decimal digit in question and amount to right of it as a fraction $dWorking=$dVal*pow(10.0,$iDec+1)-floor($dVal*pow(10.0,$iDec))*10.0; $iEvenOddDigit=floor($dVal*pow(10.0,$iDec))-floor($dVal*pow(10.0,$iDec-1))*10.0; if (abs($dWorking-5.0)<$dFuzz) $iRoundup=($iEvenOddDigit & 1) ? 1 : 0; else $iRoundup=($dWorking>5.0) ? 1 : 0; return $iSign*((floor($dVal*pow(10.0,$iDec))+$iRoundup)/pow(10.0,$iDec)); } echo bround(10.005); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F40HV
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                               'bround'
          1        SEND_VAL                                                 10.005
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
   22     4      > RETURN                                                   1

Function bround:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 13
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 69
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 66
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
Branch analysis from position: 69
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 73
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 74
Branch analysis from position: 74
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 69
Branch analysis from position: 62
Branch analysis from position: 69
filename:       /in/F40HV
function name:  bround
number of ops:  92
compiled vars:  !0 = $dVal, !1 = $iDec, !2 = $dFuzz, !3 = $iRoundup, !4 = $iSign, !5 = $dWorking, !6 = $iEvenOddDigit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        BIND_STATIC                                              !2
    9     3        ASSIGN                                                   !3, 0
   11     4        IS_NOT_EQUAL                                             !0, 0
          5      > JMPZ                                                     ~8, ->13
          6    >   INIT_FCALL                                               'abs'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $9      
          9        DIV                                              ~10     !0, $9
         10        CAST                                          4  ~11     ~10
         11        QM_ASSIGN                                        ~12     ~11
         12      > JMP                                                      ->14
         13    >   QM_ASSIGN                                        ~12     1
         14    >   ASSIGN                                                   !4, ~12
   12    15        INIT_FCALL                                               'abs'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $14     
         18        ASSIGN                                                   !0, $14
   14    19        INIT_FCALL                                               'pow'
         20        SEND_VAL                                                 10
         21        ADD                                              ~16     !1, 1
         22        SEND_VAL                                                 ~16
         23        DO_ICALL                                         $17     
         24        MUL                                              ~18     !0, $17
         25        INIT_FCALL                                               'floor'
         26        INIT_FCALL                                               'pow'
         27        SEND_VAL                                                 10
         28        SEND_VAR                                                 !1
         29        DO_ICALL                                         $19     
         30        MUL                                              ~20     !0, $19
         31        SEND_VAL                                                 ~20
         32        DO_ICALL                                         $21     
         33        MUL                                              ~22     $21, 10
         34        SUB                                              ~23     ~18, ~22
         35        ASSIGN                                                   !5, ~23
   15    36        INIT_FCALL                                               'floor'
         37        INIT_FCALL                                               'pow'
         38        SEND_VAL                                                 10
         39        SEND_VAR                                                 !1
         40        DO_ICALL                                         $25     
         41        MUL                                              ~26     !0, $25
         42        SEND_VAL                                                 ~26
         43        DO_ICALL                                         $27     
         44        INIT_FCALL                                               'floor'
         45        INIT_FCALL                                               'pow'
         46        SEND_VAL                                                 10
         47        SUB                                              ~28     !1, 1
         48        SEND_VAL                                                 ~28
         49        DO_ICALL                                         $29     
         50        MUL                                              ~30     !0, $29
         51        SEND_VAL                                                 ~30
         52        DO_ICALL                                         $31     
         53        MUL                                              ~32     $31, 10
         54        SUB                                              ~33     $27, ~32
         55        ASSIGN                                                   !6, ~33
   16    56        INIT_FCALL                                               'abs'
         57        SUB                                              ~35     !5, 5
         58        SEND_VAL                                                 ~35
         59        DO_ICALL                                         $36     
         60        IS_SMALLER                                               $36, !2
         61      > JMPZ                                                     ~37, ->69
         62    >   BW_AND                                           ~38     !6, 1
         63      > JMPZ                                                     ~38, ->66
         64    >   QM_ASSIGN                                        ~39     1
         65      > JMP                                                      ->67
         66    >   QM_ASSIGN                                        ~39     0
         67    >   ASSIGN                                                   !3, ~39
         68      > JMP                                                      ->75
   17    69    >   IS_SMALLER                                               5, !5
         70      > JMPZ                                                     ~41, ->73
         71    >   QM_ASSIGN                                        ~42     1
         72      > JMP                                                      ->74
         73    >   QM_ASSIGN                                        ~42     0
         74    >   ASSIGN                                                   !3, ~42
   18    75    >   INIT_FCALL                                               'floor'
         76        INIT_FCALL                                               'pow'
         77        SEND_VAL                                                 10
         78        SEND_VAR                                                 !1
         79        DO_ICALL                                         $44     
         80        MUL                                              ~45     !0, $44
         81        SEND_VAL                                                 ~45
         82        DO_ICALL                                         $46     
         83        ADD                                              ~47     $46, !3
         84        INIT_FCALL                                               'pow'
         85        SEND_VAL                                                 10
         86        SEND_VAR                                                 !1
         87        DO_ICALL                                         $48     
         88        DIV                                              ~49     ~47, $48
         89        MUL                                              ~50     !4, ~49
         90      > RETURN                                                   ~50
   19    91*     > RETURN                                                   null

End of function bround

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.22 ms | 1411 KiB | 20 Q