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]; // Handle cases where the exponent is zero if ($exponent == 0) { return $mantissa; } // 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] : ''; // Calculate the effective length of the mantissa $mantissaLength = strlen($integerPart) + strlen($fractionalPart); // Normalize the mantissa by removing the decimal point $mantissaNormalized = $integerPart . $fractionalPart; // Calculate the shift based on the exponent $shift = $exponent + strlen($fractionalPart); // Handle positive and negative exponent cases if ($shift >= 0) { $number = $mantissaNormalized . str_repeat('0', $shift - strlen($mantissaNormalized)); } else { $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"; // 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/mTOS1
function name:  (null)
number of ops:  7
compiled vars:  !0 = $scientificString, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   ASSIGN                                                   !0, '1.23e308'
   66     1        INIT_FCALL                                               'parsescientificnotation'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   68     5        ECHO                                                     !1
   69     6      > 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 = 20, Position 2 = 21
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 32
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 52
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 74
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 100
Branch analysis from position: 100
2 jumps found. (Code = 43) Position 1 = 101, Position 2 = 103
Branch analysis from position: 101
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 103
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 79, Position 2 = 92
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 100
Branch analysis from position: 100
Branch analysis from position: 92
2 jumps found. (Code = 43) Position 1 = 101, Position 2 = 103
Branch analysis from position: 101
Branch analysis from position: 103
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 74
Branch analysis from position: 65
Branch analysis from position: 74
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 40
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 52
Branch analysis from position: 49
Branch analysis from position: 52
Branch analysis from position: 40
filename:       /in/mTOS1
function name:  parseScientificNotation
number of ops:  105
compiled vars:  !0 = $scientificString, !1 = $parts, !2 = $mantissa, !3 = $exponent, !4 = $isNegative, !5 = $mantissaParts, !6 = $integerPart, !7 = $fractionalPart, !8 = $mantissaLength, !9 = $mantissaNormalized, !10 = $shift, !11 = $number, !12 = $decimalPointPosition
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 'e'
          3        INIT_FCALL                                               'strtolower'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $13     
          6        SEND_VAR                                                 $13
          7        DO_ICALL                                         $14     
          8        ASSIGN                                                   !1, $14
    7     9        COUNT                                            ~16     !1
         10        IS_NOT_EQUAL                                             ~16, 2
         11      > JMPZ                                                     ~17, ->13
    8    12    > > RETURN                                                   'Invalid+scientific+notation'
   11    13    >   FETCH_DIM_R                                      ~18     !1, 0
         14        ASSIGN                                                   !2, ~18
   12    15        FETCH_DIM_R                                      ~20     !1, 1
         16        CAST                                          4  ~21     ~20
         17        ASSIGN                                                   !3, ~21
   15    18        IS_EQUAL                                                 !3, 0
         19      > JMPZ                                                     ~23, ->21
   16    20    > > RETURN                                                   !2
   20    21    >   ASSIGN                                                   !4, <false>
   21    22        FETCH_DIM_R                                      ~25     !2, 0
         23        IS_EQUAL                                                 ~25, '-'
         24      > JMPZ                                                     ~26, ->32
   22    25    >   ASSIGN                                                   !4, <true>
   23    26        INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !2
         28        SEND_VAL                                                 1
         29        DO_ICALL                                         $28     
         30        ASSIGN                                                   !2, $28
   21    31      > JMP                                                      ->40
   24    32    >   FETCH_DIM_R                                      ~30     !2, 0
         33        IS_EQUAL                                                 ~30, '%2B'
         34      > JMPZ                                                     ~31, ->40
   25    35    >   INIT_FCALL                                               'substr'
         36        SEND_VAR                                                 !2
         37        SEND_VAL                                                 1
         38        DO_ICALL                                         $32     
         39        ASSIGN                                                   !2, $32
   29    40    >   INIT_FCALL                                               'explode'
         41        SEND_VAL                                                 '.'
         42        SEND_VAR                                                 !2
         43        DO_ICALL                                         $34     
         44        ASSIGN                                                   !5, $34
   30    45        FETCH_DIM_R                                      ~36     !5, 0
         46        ASSIGN                                                   !6, ~36
   31    47        ISSET_ISEMPTY_DIM_OBJ                         0          !5, 1
         48      > JMPZ                                                     ~38, ->52
         49    >   FETCH_DIM_R                                      ~39     !5, 1
         50        QM_ASSIGN                                        ~40     ~39
         51      > JMP                                                      ->53
         52    >   QM_ASSIGN                                        ~40     ''
         53    >   ASSIGN                                                   !7, ~40
   34    54        STRLEN                                           ~42     !6
         55        STRLEN                                           ~43     !7
         56        ADD                                              ~44     ~42, ~43
         57        ASSIGN                                                   !8, ~44
   37    58        CONCAT                                           ~46     !6, !7
         59        ASSIGN                                                   !9, ~46
   40    60        STRLEN                                           ~48     !7
         61        ADD                                              ~49     !3, ~48
         62        ASSIGN                                                   !10, ~49
   43    63        IS_SMALLER_OR_EQUAL                                      0, !10
         64      > JMPZ                                                     ~51, ->74
   44    65    >   INIT_FCALL                                               'str_repeat'
         66        SEND_VAL                                                 '0'
         67        STRLEN                                           ~52     !9
         68        SUB                                              ~53     !10, ~52
         69        SEND_VAL                                                 ~53
         70        DO_ICALL                                         $54     
         71        CONCAT                                           ~55     !9, $54
         72        ASSIGN                                                   !11, ~55
   43    73      > JMP                                                      ->100
   46    74    >   STRLEN                                           ~57     !6
         75        ADD                                              ~58     ~57, !10
         76        ASSIGN                                                   !12, ~58
   47    77        IS_SMALLER                                               0, !12
         78      > JMPZ                                                     ~60, ->92
   48    79    >   INIT_FCALL                                               'substr'
         80        SEND_VAR                                                 !9
         81        SEND_VAL                                                 0
         82        SEND_VAR                                                 !12
         83        DO_ICALL                                         $61     
         84        CONCAT                                           ~62     $61, '.'
         85        INIT_FCALL                                               'substr'
         86        SEND_VAR                                                 !9
         87        SEND_VAR                                                 !12
         88        DO_ICALL                                         $63     
         89        CONCAT                                           ~64     ~62, $63
         90        ASSIGN                                                   !11, ~64
   47    91      > JMP                                                      ->100
   50    92    >   INIT_FCALL                                               'str_repeat'
         93        SEND_VAL                                                 '0'
         94        MUL                                              ~66     !12, -1
         95        SEND_VAL                                                 ~66
         96        DO_ICALL                                         $67     
         97        CONCAT                                           ~68     '0.', $67
         98        CONCAT                                           ~69     ~68, !9
         99        ASSIGN                                                   !11, ~69
   55   100    > > JMPZ                                                     !4, ->103
   56   101    >   CONCAT                                           ~71     '-', !11
        102        ASSIGN                                                   !11, ~71
   59   103    > > RETURN                                                   !11
   60   104*     > RETURN                                                   null

End of function parsescientificnotation

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.49 ms | 1447 KiB | 18 Q