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

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.0060.00320.94
8.3.100.0000.00924.06
8.3.90.0140.00026.77
8.3.80.0030.00618.55
8.3.70.0360.01417.81
8.3.60.0420.01017.81
8.3.50.0130.00718.36
8.3.40.0370.00417.81
8.3.30.0280.01317.81
8.3.20.0310.00017.81
8.3.10.0190.00317.81
8.3.00.0160.00617.81
8.2.230.0090.00022.58
8.2.220.0000.01537.54
8.2.210.0030.00526.77
8.2.200.0060.00318.42
8.2.190.0200.00417.81
8.2.180.0200.00617.81
8.2.170.0150.00918.00
8.2.160.0190.00819.48
8.2.150.0210.00617.81
8.2.140.0340.00017.81
8.2.130.0160.00917.81
8.2.120.0230.00017.81
8.2.110.0190.00617.81
8.2.100.0160.00617.81
8.2.90.0160.00617.81
8.2.80.0210.00417.81
8.2.70.0290.00317.81
8.2.60.0280.01417.81
8.2.50.0380.00717.81
8.2.40.0310.01217.81
8.2.30.0290.01417.81
8.2.20.0280.00917.81
8.2.10.0260.00617.81
8.2.00.0260.00617.81
8.1.290.0000.01030.84
8.1.280.0290.00617.81
8.1.270.0240.00017.81
8.1.260.0270.00717.81
8.1.250.0210.01017.81
8.1.240.0180.00717.81
8.1.230.0180.00417.81
8.1.220.0170.00817.81
8.1.210.0210.00617.81
8.1.200.0140.01017.81
8.1.190.0210.00317.81
8.1.180.0180.00617.81
8.1.170.0200.00717.81
8.1.160.0230.00517.81
8.1.150.0170.01017.81
8.1.140.0100.01317.81
8.1.130.0240.00317.81
8.1.120.0250.00017.81
8.1.110.0160.00817.81
8.1.100.0190.00817.81
8.1.90.0330.01117.81
8.1.80.0300.01217.81
8.1.70.0290.01017.81
8.1.60.0370.00617.81
8.1.50.0370.00717.81
8.1.40.0410.00317.81
8.1.30.0360.01017.81
8.1.20.0360.00817.81
8.1.10.0330.00317.81
8.1.00.0210.00317.81

preferences:
33.54 ms | 403 KiB | 5 Q