3v4l.org

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

End of function convertfloat

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.64 ms | 1411 KiB | 26 Q