3v4l.org

run code in 300+ PHP versions simultaneously
<?php $number = 3.0000000002; $precision = 12; $delta = pow(0.1, $precision); $rounded = round($number, $precision); $roundedResult = $number; echo "Test 1".$rounded.PHP_EOL; echo "Test 2".abs($number - $rounded).PHP_EOL; if (abs($number - $rounded) < $delta) { $roundedResult = intval($number); } $intedResult = $number; if ((int) $number == $number){ $intedResult = (int) $number; } echo "Delta is : ".$delta.PHP_EOL; echo "Source number: ".$number.PHP_EOL; echo "Rounded result: ".$roundedResult.PHP_EOL; echo "Inted result: ".$intedResult.PHP_EOL;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
Branch analysis from position: 31
filename:       /in/R8H4i
function name:  (null)
number of ops:  50
compiled vars:  !0 = $number, !1 = $precision, !2 = $delta, !3 = $rounded, !4 = $roundedResult, !5 = $intedResult
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 3
    6     1        ASSIGN                                                   !1, 12
    8     2        INIT_FCALL                                               'pow'
          3        SEND_VAL                                                 0.1
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $8      
          6        ASSIGN                                                   !2, $8
   11     7        INIT_FCALL                                               'round'
          8        SEND_VAR                                                 !0
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $10     
         11        ASSIGN                                                   !3, $10
   14    12        ASSIGN                                                   !4, !0
   16    13        CONCAT                                           ~13     'Test+1', !3
         14        CONCAT                                           ~14     ~13, '%0A'
         15        ECHO                                                     ~14
   17    16        INIT_FCALL                                               'abs'
         17        SUB                                              ~15     !0, !3
         18        SEND_VAL                                                 ~15
         19        DO_ICALL                                         $16     
         20        CONCAT                                           ~17     'Test+2', $16
         21        CONCAT                                           ~18     ~17, '%0A'
         22        ECHO                                                     ~18
   19    23        INIT_FCALL                                               'abs'
         24        SUB                                              ~19     !0, !3
         25        SEND_VAL                                                 ~19
         26        DO_ICALL                                         $20     
         27        IS_SMALLER                                               $20, !2
         28      > JMPZ                                                     ~21, ->31
   20    29    >   CAST                                          4  ~22     !0
         30        ASSIGN                                                   !4, ~22
   23    31    >   ASSIGN                                                   !5, !0
   25    32        CAST                                          4  ~25     !0
         33        IS_EQUAL                                                 !0, ~25
         34      > JMPZ                                                     ~26, ->37
   26    35    >   CAST                                          4  ~27     !0
         36        ASSIGN                                                   !5, ~27
   30    37    >   CONCAT                                           ~29     'Delta+is+%3A+', !2
         38        CONCAT                                           ~30     ~29, '%0A'
         39        ECHO                                                     ~30
   32    40        CONCAT                                           ~31     'Source+number%3A+', !0
         41        CONCAT                                           ~32     ~31, '%0A'
         42        ECHO                                                     ~32
   33    43        CONCAT                                           ~33     'Rounded+result%3A+', !4
         44        CONCAT                                           ~34     ~33, '%0A'
         45        ECHO                                                     ~34
   34    46        CONCAT                                           ~35     'Inted+result%3A+', !5
         47        CONCAT                                           ~36     ~35, '%0A'
         48        ECHO                                                     ~36
         49      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.65 ms | 1400 KiB | 19 Q