3v4l.org

run code in 300+ PHP versions simultaneously
<?php $whole = floor ( $float ); $decimal = $float - $whole; $leastCommonDenom = 48; // 16 * 3; $denominators = array (2, 3, 4, 8, 16, 24, 48 ); $roundedDecimal = round ( $decimal * $leastCommonDenom ) / $leastCommonDenom; if ($roundedDecimal == 0) return $whole; if ($roundedDecimal == 1) return $whole + 1; foreach ( $denominators as $d ) { if ($roundedDecimal * $d == floor ( $roundedDecimal * $d )) { $denom = $d; break; } } return ($whole == 0 ? '' : $whole) . " " . ($roundedDecimal * $denom) . "/" . $denom; //echo toFraction( -0.5) . "\n" . toFraction( 1.5);
Finding entry points
Branch analysis from position: 0
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
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 33
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 33
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 38
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 33
Branch analysis from position: 33
filename:       /in/pnsXd
function name:  (null)
number of ops:  46
compiled vars:  !0 = $whole, !1 = $float, !2 = $decimal, !3 = $leastCommonDenom, !4 = $denominators, !5 = $roundedDecimal, !6 = $d, !7 = $denom
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'floor'
          1        SEND_VAR                                                 !1
          2        DO_ICALL                                         $8      
          3        ASSIGN                                                   !0, $8
    3     4        SUB                                              ~10     !1, !0
          5        ASSIGN                                                   !2, ~10
    4     6        ASSIGN                                                   !3, 48
    5     7        ASSIGN                                                   !4, <array>
    6     8        INIT_FCALL                                               'round'
          9        MUL                                              ~14     !2, !3
         10        SEND_VAL                                                 ~14
         11        DO_ICALL                                         $15     
         12        DIV                                              ~16     $15, !3
         13        ASSIGN                                                   !5, ~16
    7    14        IS_EQUAL                                                 !5, 0
         15      > JMPZ                                                     ~18, ->17
    8    16    > > RETURN                                                   !0
    9    17    >   IS_EQUAL                                                 !5, 1
         18      > JMPZ                                                     ~19, ->21
   10    19    >   ADD                                              ~20     !0, 1
         20      > RETURN                                                   ~20
   11    21    > > FE_RESET_R                                       $21     !4, ->33
         22    > > FE_FETCH_R                                               $21, !6, ->33
   12    23    >   MUL                                              ~22     !5, !6
         24        INIT_FCALL                                               'floor'
         25        MUL                                              ~23     !5, !6
         26        SEND_VAL                                                 ~23
         27        DO_ICALL                                         $24     
         28        IS_EQUAL                                                 $24, ~22
         29      > JMPZ                                                     ~25, ->32
   13    30    >   ASSIGN                                                   !7, !6
   14    31      > JMP                                                      ->33
   11    32    > > JMP                                                      ->22
         33    >   FE_FREE                                                  $21
   17    34        IS_EQUAL                                                 !0, 0
         35      > JMPZ                                                     ~27, ->38
         36    >   QM_ASSIGN                                        ~28     ''
         37      > JMP                                                      ->39
         38    >   QM_ASSIGN                                        ~28     !0
         39    >   CONCAT                                           ~29     ~28, '+'
         40        MUL                                              ~30     !5, !7
         41        CONCAT                                           ~31     ~29, ~30
         42        CONCAT                                           ~32     ~31, '%2F'
         43        CONCAT                                           ~33     ~32, !7
         44      > RETURN                                                   ~33
   20    45*     > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.23 ms | 1400 KiB | 17 Q