3v4l.org

run code in 300+ PHP versions simultaneously
<?php $number = 3.0000000000001; $precision = 13; $epsilon = 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) < $epsilon) { $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 = 19, Position 2 = 21
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
Branch analysis from position: 21
filename:       /in/BbBeQ
function name:  (null)
number of ops:  37
compiled vars:  !0 = $number, !1 = $precision, !2 = $epsilon, !3 = $rounded, !4 = $roundedResult, !5 = $intedResult
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, 3
    6     1        ASSIGN                                                   !1, 13
    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
   19    13        INIT_FCALL                                               'abs'
         14        SUB                                              ~13     !0, !3
         15        SEND_VAL                                                 ~13
         16        DO_ICALL                                         $14     
         17        IS_SMALLER                                               $14, !2
         18      > JMPZ                                                     ~15, ->21
   20    19    >   CAST                                          4  ~16     !0
         20        ASSIGN                                                   !4, ~16
   23    21    >   ASSIGN                                                   !5, !0
   25    22        CAST                                          4  ~19     !0
         23        IS_EQUAL                                                 !0, ~19
         24      > JMPZ                                                     ~20, ->27
   26    25    >   CAST                                          4  ~21     !0
         26        ASSIGN                                                   !5, ~21
   32    27    >   CONCAT                                           ~23     'Source+number%3A+', !0
         28        CONCAT                                           ~24     ~23, '%0A'
         29        ECHO                                                     ~24
   33    30        CONCAT                                           ~25     'Rounded+result%3A+', !4
         31        CONCAT                                           ~26     ~25, '%0A'
         32        ECHO                                                     ~26
   34    33        CONCAT                                           ~27     'Inted+result%3A+', !5
         34        CONCAT                                           ~28     ~27, '%0A'
         35        ECHO                                                     ~28
         36      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.5 ms | 1396 KiB | 19 Q