3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isMultipleOf(float $number, float $divisor) { $modulus = ($number - round($number / $divisor) * $divisor); $precision = 0.0000000001; if (-$precision < $modulus && $modulus < $precision) { return 0.0; } return $modulus; } function test(float $value, float $multiple, $expected) { if ((isMultipleOf($value, $multiple) == 0.0) !== $expected) { var_dump($value, $multiple, $expected); } } test(400.01, 0.01, true); test(400.01, 3, false); test(9007199254740991.00000000000000, 1, true); test(900719925474099166666.00000000000000, 1, true); test(2.00000000000000, 1, true); test(2, 1, true);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/K5D3k
function name:  (null)
number of ops:  31
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   INIT_FCALL                                               'test'
          1        SEND_VAL                                                 400.01
          2        SEND_VAL                                                 0.01
          3        SEND_VAL                                                 <true>
          4        DO_FCALL                                      0          
   21     5        INIT_FCALL                                               'test'
          6        SEND_VAL                                                 400.01
          7        SEND_VAL                                                 3
          8        SEND_VAL                                                 <false>
          9        DO_FCALL                                      0          
   22    10        INIT_FCALL                                               'test'
         11        SEND_VAL                                                 9.0072e+15
         12        SEND_VAL                                                 1
         13        SEND_VAL                                                 <true>
         14        DO_FCALL                                      0          
   23    15        INIT_FCALL                                               'test'
         16        SEND_VAL                                                 9.0072e+20
         17        SEND_VAL                                                 1
         18        SEND_VAL                                                 <true>
         19        DO_FCALL                                      0          
   24    20        INIT_FCALL                                               'test'
         21        SEND_VAL                                                 2
         22        SEND_VAL                                                 1
         23        SEND_VAL                                                 <true>
         24        DO_FCALL                                      0          
   25    25        INIT_FCALL                                               'test'
         26        SEND_VAL                                                 2
         27        SEND_VAL                                                 1
         28        SEND_VAL                                                 <true>
         29        DO_FCALL                                      0          
         30      > RETURN                                                   1

Function ismultipleof:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/K5D3k
function name:  isMultipleOf
number of ops:  19
compiled vars:  !0 = $number, !1 = $divisor, !2 = $modulus, !3 = $precision
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        INIT_FCALL                                               'round'
          3        DIV                                              ~4      !0, !1
          4        SEND_VAL                                                 ~4
          5        DO_ICALL                                         $5      
          6        MUL                                              ~6      !1, $5
          7        SUB                                              ~7      !0, ~6
          8        ASSIGN                                                   !2, ~7
    5     9        ASSIGN                                                   !3, 1.0e-10
    7    10        MUL                                              ~10     !3, -1
         11        IS_SMALLER                                       ~11     ~10, !2
         12      > JMPZ_EX                                          ~11     ~11, ->15
         13    >   IS_SMALLER                                       ~12     !2, !3
         14        BOOL                                             ~11     ~12
         15    > > JMPZ                                                     ~11, ->17
    8    16    > > RETURN                                                   0
   11    17    > > RETURN                                                   !2
   12    18*     > RETURN                                                   null

End of function ismultipleof

Function test:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/K5D3k
function name:  test
number of ops:  16
compiled vars:  !0 = $value, !1 = $multiple, !2 = $expected
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   15     3        INIT_FCALL                                               'ismultipleof'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $3      
          7        IS_EQUAL                                         ~4      $3, 0
          8        IS_NOT_IDENTICAL                                         !2, ~4
          9      > JMPZ                                                     ~5, ->15
   16    10    >   INIT_FCALL                                               'var_dump'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !1
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                                 
   18    15    > > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.41 ms | 1453 KiB | 22 Q