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 ".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 = 26, Position 2 = 28
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
Branch analysis from position: 28
filename:       /in/DVv0P
function name:  (null)
number of ops:  47
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
   17    13        INIT_FCALL                                               'abs'
         14        SUB                                              ~13     !0, !3
         15        SEND_VAL                                                 ~13
         16        DO_ICALL                                         $14     
         17        CONCAT                                           ~15     'Test+', $14
         18        CONCAT                                           ~16     ~15, '%0A'
         19        ECHO                                                     ~16
   19    20        INIT_FCALL                                               'abs'
         21        SUB                                              ~17     !0, !3
         22        SEND_VAL                                                 ~17
         23        DO_ICALL                                         $18     
         24        IS_SMALLER                                               $18, !2
         25      > JMPZ                                                     ~19, ->28
   20    26    >   CAST                                          4  ~20     !0
         27        ASSIGN                                                   !4, ~20
   23    28    >   ASSIGN                                                   !5, !0
   25    29        CAST                                          4  ~23     !0
         30        IS_EQUAL                                                 !0, ~23
         31      > JMPZ                                                     ~24, ->34
   26    32    >   CAST                                          4  ~25     !0
         33        ASSIGN                                                   !5, ~25
   30    34    >   CONCAT                                           ~27     'Delta+is+%3A+', !2
         35        CONCAT                                           ~28     ~27, '%0A'
         36        ECHO                                                     ~28
   32    37        CONCAT                                           ~29     'Source+number%3A+', !0
         38        CONCAT                                           ~30     ~29, '%0A'
         39        ECHO                                                     ~30
   33    40        CONCAT                                           ~31     'Rounded+result%3A+', !4
         41        CONCAT                                           ~32     ~31, '%0A'
         42        ECHO                                                     ~32
   34    43        CONCAT                                           ~33     'Inted+result%3A+', !5
         44        CONCAT                                           ~34     ~33, '%0A'
         45        ECHO                                                     ~34
         46      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.23 ms | 1405 KiB | 19 Q