3v4l.org

run code in 300+ PHP versions simultaneously
<?php function convertFloat($float) { $float = strtolower((string)$float); $expPos = strpos($float, 'e'); if ($expPos === false) { return (string)(float)$float; } $beforeDot = '0'; // Well, fuck you my English. $afterDot = ''; // ^^ $numberWithoutPrecision = substr($float, 0, $expPos); $exp = (int)substr($float, $expPos + 1, strlen($float)); if ($exp === 0) { return '1'; } $dotPos = strpos($numberWithoutPrecision, '.'); if ($dotPos === false) { $beforeDot = $numberWithoutPrecision; } else { $beforeDot = substr($numberWithoutPrecision, 0, $dotPos); $afterDot = substr($numberWithoutPrecision, $dotPos + 1, strlen($numberWithoutPrecision)); $afterDot = rtrim($afterDot, '0'); } $beforeDot = ltrim($beforeDot, '0'); if ($exp < 0) { $exp = -$exp; $len = strlen($beforeDot); if ($len <= $exp) { return '0.'.str_repeat('0', $exp - $len).$beforeDot.$afterDot; } else { return substr($beforeDot, 0, $len - $exp).'.'.substr($beforeDot, $len - $exp, $len).$afterDot; } } else { $len = strlen($afterDot); if ($len <= $exp) { return $beforeDot.$afterDot.str_repeat('0', $exp - $len).'i'; } else { return $beforeDot.substr($afterDot, 0, $exp).'.'.substr($afterDot, $exp, $len); } } } //var_dump(convertFloat('11111111111111111111111111111111111111111111111111111111111112e-60')); var_dump(convertFloat('+1.'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A5rgo
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'convertfloat'
          2        SEND_VAL                                                 '%2B1.'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
          6      > RETURN                                                   1

Function convertfloat:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 36
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 45
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 104
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 87
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 87
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 104
2 jumps found. (Code = 43) Position 1 = 108, Position 2 = 118
Branch analysis from position: 108
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 118
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 104
Branch analysis from position: 71
Branch analysis from position: 104
filename:       /in/A5rgo
function name:  convertFloat
number of ops:  133
compiled vars:  !0 = $float, !1 = $expPos, !2 = $beforeDot, !3 = $afterDot, !4 = $numberWithoutPrecision, !5 = $exp, !6 = $dotPos, !7 = $len
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'strtolower'
          2        CAST                                          6  ~8      !0
          3        SEND_VAL                                                 ~8
          4        DO_ICALL                                         $9      
          5        ASSIGN                                                   !0, $9
    5     6        INIT_FCALL                                               'strpos'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 'e'
          9        DO_ICALL                                         $11     
         10        ASSIGN                                                   !1, $11
    7    11        TYPE_CHECK                                    4          !1
         12      > JMPZ                                                     ~13, ->16
    8    13    >   CAST                                          5  ~14     !0
         14        CAST                                          6  ~15     ~14
         15      > RETURN                                                   ~15
   11    16    >   ASSIGN                                                   !2, '0'
   12    17        ASSIGN                                                   !3, ''
   13    18        INIT_FCALL                                               'substr'
         19        SEND_VAR                                                 !0
         20        SEND_VAL                                                 0
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                         $18     
         23        ASSIGN                                                   !4, $18
   14    24        INIT_FCALL                                               'substr'
         25        SEND_VAR                                                 !0
         26        ADD                                              ~20     !1, 1
         27        SEND_VAL                                                 ~20
         28        STRLEN                                           ~21     !0
         29        SEND_VAL                                                 ~21
         30        DO_ICALL                                         $22     
         31        CAST                                          4  ~23     $22
         32        ASSIGN                                                   !5, ~23
   16    33        IS_IDENTICAL                                             !5, 0
         34      > JMPZ                                                     ~25, ->36
   17    35    > > RETURN                                                   '1'
   20    36    >   INIT_FCALL                                               'strpos'
         37        SEND_VAR                                                 !4
         38        SEND_VAL                                                 '.'
         39        DO_ICALL                                         $26     
         40        ASSIGN                                                   !6, $26
   22    41        TYPE_CHECK                                    4          !6
         42      > JMPZ                                                     ~28, ->45
   23    43    >   ASSIGN                                                   !2, !4
         44      > JMP                                                      ->64
   25    45    >   INIT_FCALL                                               'substr'
         46        SEND_VAR                                                 !4
         47        SEND_VAL                                                 0
         48        SEND_VAR                                                 !6
         49        DO_ICALL                                         $30     
         50        ASSIGN                                                   !2, $30
   26    51        INIT_FCALL                                               'substr'
         52        SEND_VAR                                                 !4
         53        ADD                                              ~32     !6, 1
         54        SEND_VAL                                                 ~32
         55        STRLEN                                           ~33     !4
         56        SEND_VAL                                                 ~33
         57        DO_ICALL                                         $34     
         58        ASSIGN                                                   !3, $34
   27    59        INIT_FCALL                                               'rtrim'
         60        SEND_VAR                                                 !3
         61        SEND_VAL                                                 '0'
         62        DO_ICALL                                         $36     
         63        ASSIGN                                                   !3, $36
   30    64    >   INIT_FCALL                                               'ltrim'
         65        SEND_VAR                                                 !2
         66        SEND_VAL                                                 '0'
         67        DO_ICALL                                         $38     
         68        ASSIGN                                                   !2, $38
   32    69        IS_SMALLER                                               !5, 0
         70      > JMPZ                                                     ~40, ->104
   33    71    >   MUL                                              ~41     !5, -1
         72        ASSIGN                                                   !5, ~41
   34    73        STRLEN                                           ~43     !2
         74        ASSIGN                                                   !7, ~43
   36    75        IS_SMALLER_OR_EQUAL                                      !7, !5
         76      > JMPZ                                                     ~45, ->87
   37    77    >   INIT_FCALL                                               'str_repeat'
         78        SEND_VAL                                                 '0'
         79        SUB                                              ~46     !5, !7
         80        SEND_VAL                                                 ~46
         81        DO_ICALL                                         $47     
         82        CONCAT                                           ~48     '0.', $47
         83        CONCAT                                           ~49     ~48, !2
         84        CONCAT                                           ~50     ~49, !3
         85      > RETURN                                                   ~50
         86*       JMP                                                      ->103
   39    87    >   INIT_FCALL                                               'substr'
         88        SEND_VAR                                                 !2
         89        SEND_VAL                                                 0
         90        SUB                                              ~51     !7, !5
         91        SEND_VAL                                                 ~51
         92        DO_ICALL                                         $52     
         93        CONCAT                                           ~53     $52, '.'
         94        INIT_FCALL                                               'substr'
         95        SEND_VAR                                                 !2
         96        SUB                                              ~54     !7, !5
         97        SEND_VAL                                                 ~54
         98        SEND_VAR                                                 !7
         99        DO_ICALL                                         $55     
        100        CONCAT                                           ~56     ~53, $55
        101        CONCAT                                           ~57     ~56, !3
        102      > RETURN                                                   ~57
        103*       JMP                                                      ->132
   42   104    >   STRLEN                                           ~58     !3
        105        ASSIGN                                                   !7, ~58
   44   106        IS_SMALLER_OR_EQUAL                                      !7, !5
        107      > JMPZ                                                     ~60, ->118
   45   108    >   CONCAT                                           ~61     !2, !3
        109        INIT_FCALL                                               'str_repeat'
        110        SEND_VAL                                                 '0'
        111        SUB                                              ~62     !5, !7
        112        SEND_VAL                                                 ~62
        113        DO_ICALL                                         $63     
        114        CONCAT                                           ~64     ~61, $63
        115        CONCAT                                           ~65     ~64, 'i'
        116      > RETURN                                                   ~65
        117*       JMP                                                      ->132
   47   118    >   INIT_FCALL                                               'substr'
        119        SEND_VAR                                                 !3
        120        SEND_VAL                                                 0
        121        SEND_VAR                                                 !5
        122        DO_ICALL                                         $66     
        123        CONCAT                                           ~67     !2, $66
        124        CONCAT                                           ~68     ~67, '.'
        125        INIT_FCALL                                               'substr'
        126        SEND_VAR                                                 !3
        127        SEND_VAR                                                 !5
        128        SEND_VAR                                                 !7
        129        DO_ICALL                                         $69     
        130        CONCAT                                           ~70     ~68, $69
        131      > RETURN                                                   ~70
   50   132*     > RETURN                                                   null

End of function convertfloat

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.57 ms | 1410 KiB | 28 Q