3v4l.org

run code in 300+ PHP versions simultaneously
<?php function parseScientificNotation($scientificString) { // Explode the string into mantissa and exponent parts $parts = explode('e', strtolower($scientificString)); if (count($parts) != 2) { return "Invalid scientific notation"; } $mantissa = $parts[0]; $exponent = (int) $parts[1]; // Determine if the number is negative $isNegative = false; if ($mantissa[0] == '-') { $isNegative = true; $mantissa = substr($mantissa, 1); } elseif ($mantissa[0] == '+') { $mantissa = substr($mantissa, 1); } // Split the mantissa into integer and fractional parts $mantissaParts = explode('.', $mantissa); $integerPart = $mantissaParts[0]; $fractionalPart = isset($mantissaParts[1]) ? $mantissaParts[1] : ''; // Normalize the mantissa by removing the decimal point $mantissaNormalized = $integerPart . $fractionalPart; // Calculate the shift based on the exponent $shift = $exponent - strlen($fractionalPart); if ($shift >= 0) { // Positive exponent: add zeros to the right $number = $mantissaNormalized . str_repeat('0', $shift); } else { // Negative exponent: add zeros to the left and insert the decimal point $decimalPointPosition = strlen($integerPart) + $shift; if ($decimalPointPosition > 0) { $number = substr($mantissaNormalized, 0, $decimalPointPosition) . '.' . substr($mantissaNormalized, $decimalPointPosition); } else { $number = '0.' . str_repeat('0', -$decimalPointPosition) . $mantissaNormalized; } } // Restore the sign if the number was negative if ($isNegative) { $number = '-' . $number; } return $number; } // Example large scientific notation string //$scientificString = "1.23e308"; $scientificString = (string) 1 / 1000000; // Parse and convert the string $result = parseScientificNotation($scientificString); echo $result; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v2boJ
function name:  (null)
number of ops:  9
compiled vars:  !0 = $scientificString, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   CAST                                          6  ~2      1
          1        DIV                                              ~3      ~2, 1000000
          2        ASSIGN                                                   !0, ~3
   59     3        INIT_FCALL                                               'parsescientificnotation'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !1, $5
   61     7        ECHO                                                     !1
   62     8      > RETURN                                                   1

Function parsescientificnotation:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 29
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 49
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 65
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
2 jumps found. (Code = 43) Position 1 = 92, Position 2 = 94
Branch analysis from position: 92
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 94
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 70, Position 2 = 83
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
Branch analysis from position: 83
2 jumps found. (Code = 43) Position 1 = 92, Position 2 = 94
Branch analysis from position: 92
Branch analysis from position: 94
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 65
Branch analysis from position: 58
Branch analysis from position: 65
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 37
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 49
Branch analysis from position: 46
Branch analysis from position: 49
Branch analysis from position: 37
filename:       /in/v2boJ
function name:  parseScientificNotation
number of ops:  96
compiled vars:  !0 = $scientificString, !1 = $parts, !2 = $mantissa, !3 = $exponent, !4 = $isNegative, !5 = $mantissaParts, !6 = $integerPart, !7 = $fractionalPart, !8 = $mantissaNormalized, !9 = $shift, !10 = $number, !11 = $decimalPointPosition
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 'e'
          3        INIT_FCALL                                               'strtolower'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $12     
          6        SEND_VAR                                                 $12
          7        DO_ICALL                                         $13     
          8        ASSIGN                                                   !1, $13
    6     9        COUNT                                            ~15     !1
         10        IS_NOT_EQUAL                                             ~15, 2
         11      > JMPZ                                                     ~16, ->13
    7    12    > > RETURN                                                   'Invalid+scientific+notation'
   10    13    >   FETCH_DIM_R                                      ~17     !1, 0
         14        ASSIGN                                                   !2, ~17
   11    15        FETCH_DIM_R                                      ~19     !1, 1
         16        CAST                                          4  ~20     ~19
         17        ASSIGN                                                   !3, ~20
   14    18        ASSIGN                                                   !4, <false>
   15    19        FETCH_DIM_R                                      ~23     !2, 0
         20        IS_EQUAL                                                 ~23, '-'
         21      > JMPZ                                                     ~24, ->29
   16    22    >   ASSIGN                                                   !4, <true>
   17    23        INIT_FCALL                                               'substr'
         24        SEND_VAR                                                 !2
         25        SEND_VAL                                                 1
         26        DO_ICALL                                         $26     
         27        ASSIGN                                                   !2, $26
   15    28      > JMP                                                      ->37
   18    29    >   FETCH_DIM_R                                      ~28     !2, 0
         30        IS_EQUAL                                                 ~28, '%2B'
         31      > JMPZ                                                     ~29, ->37
   19    32    >   INIT_FCALL                                               'substr'
         33        SEND_VAR                                                 !2
         34        SEND_VAL                                                 1
         35        DO_ICALL                                         $30     
         36        ASSIGN                                                   !2, $30
   23    37    >   INIT_FCALL                                               'explode'
         38        SEND_VAL                                                 '.'
         39        SEND_VAR                                                 !2
         40        DO_ICALL                                         $32     
         41        ASSIGN                                                   !5, $32
   24    42        FETCH_DIM_R                                      ~34     !5, 0
         43        ASSIGN                                                   !6, ~34
   25    44        ISSET_ISEMPTY_DIM_OBJ                         0          !5, 1
         45      > JMPZ                                                     ~36, ->49
         46    >   FETCH_DIM_R                                      ~37     !5, 1
         47        QM_ASSIGN                                        ~38     ~37
         48      > JMP                                                      ->50
         49    >   QM_ASSIGN                                        ~38     ''
         50    >   ASSIGN                                                   !7, ~38
   28    51        CONCAT                                           ~40     !6, !7
         52        ASSIGN                                                   !8, ~40
   31    53        STRLEN                                           ~42     !7
         54        SUB                                              ~43     !3, ~42
         55        ASSIGN                                                   !9, ~43
   33    56        IS_SMALLER_OR_EQUAL                                      0, !9
         57      > JMPZ                                                     ~45, ->65
   35    58    >   INIT_FCALL                                               'str_repeat'
         59        SEND_VAL                                                 '0'
         60        SEND_VAR                                                 !9
         61        DO_ICALL                                         $46     
         62        CONCAT                                           ~47     !8, $46
         63        ASSIGN                                                   !10, ~47
   33    64      > JMP                                                      ->91
   38    65    >   STRLEN                                           ~49     !6
         66        ADD                                              ~50     ~49, !9
         67        ASSIGN                                                   !11, ~50
   39    68        IS_SMALLER                                               0, !11
         69      > JMPZ                                                     ~52, ->83
   40    70    >   INIT_FCALL                                               'substr'
         71        SEND_VAR                                                 !8
         72        SEND_VAL                                                 0
         73        SEND_VAR                                                 !11
         74        DO_ICALL                                         $53     
         75        CONCAT                                           ~54     $53, '.'
         76        INIT_FCALL                                               'substr'
         77        SEND_VAR                                                 !8
         78        SEND_VAR                                                 !11
         79        DO_ICALL                                         $55     
         80        CONCAT                                           ~56     ~54, $55
         81        ASSIGN                                                   !10, ~56
   39    82      > JMP                                                      ->91
   42    83    >   INIT_FCALL                                               'str_repeat'
         84        SEND_VAL                                                 '0'
         85        MUL                                              ~58     !11, -1
         86        SEND_VAL                                                 ~58
         87        DO_ICALL                                         $59     
         88        CONCAT                                           ~60     '0.', $59
         89        CONCAT                                           ~61     ~60, !8
         90        ASSIGN                                                   !10, ~61
   47    91    > > JMPZ                                                     !4, ->94
   48    92    >   CONCAT                                           ~63     '-', !10
         93        ASSIGN                                                   !10, ~63
   51    94    > > RETURN                                                   !10
   52    95*     > RETURN                                                   null

End of function parsescientificnotation

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.73 ms | 1441 KiB | 18 Q