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

End of function convertfloat

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.48 ms | 1402 KiB | 28 Q