3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo whole_fraction(23.54); function whole_fraction($decimal){ $big_fraction = float2rat($decimal); $num_array = explode('/', $big_fraction); echo $big_fraction; $numerator = $num_array[0]; $denominator = $num_array[1]; echo "\n"; echo $numerator; echo "\n"; echo $denomenator; $whole_number = floor( $numerator / $denominator ); $numerator = $numerator % $denomenator; $fraction = $whole_number . ' ' . $numerator . '/' . $denomenator; } function float2rat($n, $tolerance = 1.e-6) { $h1=1; $h2=0; $k1=0; $k2=1; $b = 1/$n; do { $b = 1/$b; $a = floor($b); $aux = $h1; $h1 = $a*$h1+$h2; $h2 = $aux; $aux = $k1; $k1 = $a*$k1+$k2; $k2 = $aux; $b = $b-$a; } while (abs($n-$h1/$k1) > $n*$tolerance); return "$h1/$k1"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aUZh5
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL_BY_NAME                                       'whole_fraction'
          1        SEND_VAL_EX                                              23.54
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
   34     4      > RETURN                                                   1

Function whole_fraction:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aUZh5
function name:  whole_fraction
number of ops:  32
compiled vars:  !0 = $decimal, !1 = $big_fraction, !2 = $num_array, !3 = $numerator, !4 = $denominator, !5 = $denomenator, !6 = $whole_number, !7 = $fraction
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1        INIT_FCALL_BY_NAME                                       'float2rat'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $8      
          4        ASSIGN                                                   !1, $8
    8     5        INIT_FCALL                                               'explode'
          6        SEND_VAL                                                 '%2F'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $10     
          9        ASSIGN                                                   !2, $10
    9    10        ECHO                                                     !1
   10    11        FETCH_DIM_R                                      ~12     !2, 0
         12        ASSIGN                                                   !3, ~12
   11    13        FETCH_DIM_R                                      ~14     !2, 1
         14        ASSIGN                                                   !4, ~14
   12    15        ECHO                                                     '%0A'
   13    16        ECHO                                                     !3
   14    17        ECHO                                                     '%0A'
   15    18        ECHO                                                     !5
   16    19        INIT_FCALL                                               'floor'
         20        DIV                                              ~16     !3, !4
         21        SEND_VAL                                                 ~16
         22        DO_ICALL                                         $17     
         23        ASSIGN                                                   !6, $17
   17    24        MOD                                              ~19     !3, !5
         25        ASSIGN                                                   !3, ~19
   18    26        CONCAT                                           ~21     !6, '+'
         27        CONCAT                                           ~22     ~21, !3
         28        CONCAT                                           ~23     ~22, '%2F'
         29        CONCAT                                           ~24     ~23, !5
         30        ASSIGN                                                   !7, ~24
   19    31      > RETURN                                                   null

End of function whole_fraction

Function float2rat:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 34, Position 2 = 8
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/aUZh5
function name:  float2rat
number of ops:  39
compiled vars:  !0 = $n, !1 = $tolerance, !2 = $h1, !3 = $h2, !4 = $k1, !5 = $k2, !6 = $b, !7 = $a, !8 = $aux
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      1.0e-6
   22     2        ASSIGN                                                   !2, 1
          3        ASSIGN                                                   !3, 0
   23     4        ASSIGN                                                   !4, 0
          5        ASSIGN                                                   !5, 1
   24     6        DIV                                              ~13     1, !0
          7        ASSIGN                                                   !6, ~13
   26     8    >   DIV                                              ~15     1, !6
          9        ASSIGN                                                   !6, ~15
   27    10        INIT_FCALL                                               'floor'
         11        SEND_VAR                                                 !6
         12        DO_ICALL                                         $17     
         13        ASSIGN                                                   !7, $17
   28    14        ASSIGN                                                   !8, !2
         15        MUL                                              ~20     !7, !2
         16        ADD                                              ~21     ~20, !3
         17        ASSIGN                                                   !2, ~21
         18        ASSIGN                                                   !3, !8
   29    19        ASSIGN                                                   !8, !4
         20        MUL                                              ~25     !7, !4
         21        ADD                                              ~26     ~25, !5
         22        ASSIGN                                                   !4, ~26
         23        ASSIGN                                                   !5, !8
   30    24        SUB                                              ~29     !6, !7
         25        ASSIGN                                                   !6, ~29
   31    26        INIT_FCALL                                               'abs'
         27        DIV                                              ~31     !2, !4
         28        SUB                                              ~32     !0, ~31
         29        SEND_VAL                                                 ~32
         30        DO_ICALL                                         $33     
         31        MUL                                              ~34     !0, !1
         32        IS_SMALLER                                               ~34, $33
         33      > JMPNZ                                                    ~35, ->8
   33    34    >   ROPE_INIT                                     3  ~37     !2
         35        ROPE_ADD                                      1  ~37     ~37, '%2F'
         36        ROPE_END                                      2  ~36     ~37, !4
         37      > RETURN                                                   ~36
   34    38*     > RETURN                                                   null

End of function float2rat

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.52 ms | 1400 KiB | 19 Q