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; ?>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.110.0080.00016.48
8.3.100.0060.00324.06
8.3.90.0120.00926.77
8.3.80.0060.00318.55
8.3.70.0300.00617.81
8.3.60.0250.00617.81
8.3.50.0060.00618.41
8.3.40.0250.00017.81
8.3.30.0160.00917.81
8.3.20.0150.00817.81
8.3.10.0180.00517.81
8.3.00.0140.00917.81
8.2.230.0080.00020.94
8.2.220.0090.00037.54
8.2.210.0080.00026.77
8.2.200.0110.00016.35
8.2.190.0130.01317.81
8.2.180.0190.00417.81
8.2.170.0250.00317.81
8.2.160.0220.00617.81
8.2.150.0260.00417.81
8.2.140.0240.00917.81
8.2.130.0220.00617.81
8.2.120.0190.01117.81
8.2.110.0210.00917.81
8.2.100.0200.00317.81
8.2.90.0220.00417.81
8.2.80.0120.01217.81
8.2.70.0220.00017.81
8.2.60.0160.00817.81
8.2.50.0290.00017.81
8.2.40.0190.00817.81
8.2.30.0180.01117.81
8.2.20.0210.00617.81
8.2.10.0360.00617.81
8.2.00.0340.00817.81
8.1.290.0090.00030.84
8.1.280.0380.00417.81
8.1.270.0490.00617.81
8.1.260.0330.00017.81
8.1.250.0290.00017.81
8.1.240.0170.00317.81
8.1.230.0200.00017.81
8.1.220.0180.00717.81
8.1.210.0220.00617.81
8.1.200.0140.01117.81
8.1.190.0210.00317.81
8.1.180.0260.00317.81
8.1.170.0280.00317.81
8.1.160.0240.00317.81
8.1.150.0220.00317.81
8.1.140.0190.00317.81
8.1.130.0170.00417.81
8.1.120.0170.00617.81
8.1.110.0080.01617.81
8.1.100.0210.00517.81
8.1.90.0210.00617.81
8.1.80.0230.00317.81
8.1.70.0300.00717.81
8.1.60.0300.01017.81
8.1.50.0280.00817.81
8.1.40.0190.00817.81
8.1.30.0240.00317.81
8.1.20.0300.00617.81
8.1.10.0210.00717.81
8.1.00.0180.00717.81

preferences:
37.35 ms | 403 KiB | 5 Q