mirror of
https://github.com/IvarK/AntimatterDimensionsSourceCode.git
synced 2024-11-10 06:02:13 +00:00
Fix bug with mixed sci/log notation in autobuyers
This commit is contained in:
parent
7668541221
commit
a98ed69a81
@ -99,11 +99,17 @@ export const AutobuyerInputFunctions = {
|
||||
if (/^e\d*[.]?\d+$/u.test(input.replaceAll(",", ""))) {
|
||||
// Logarithm Notation
|
||||
decimal = Decimal.pow10(parseFloat(input.replaceAll(",", "").slice(1)));
|
||||
} else if (/^\d*[.]?\d+(e\d*[.]?\d+)?$/u.test(input.replaceAll(",", ""))) {
|
||||
} else if (/^\d*[.]?\d+(e\d+)?$/u.test(input.replaceAll(",", ""))) {
|
||||
// Scientific notation; internals of break-infinity will gladly strip extraneous letters before parsing, but
|
||||
// since this is largely uncommunicated to the user, we instead explicitly check for formatting and reject
|
||||
// anything that doesn't fit as invalid
|
||||
decimal = Decimal.fromString(input.replaceAll(",", ""));
|
||||
} else if (/^\d*[.]?\d+(e\d*[.]?\d+)?$/u.test(input.replaceAll(",", ""))) {
|
||||
// "Mixed scientific notation" - inputs such as "2.33e41.2" cause buggy behavior when fed directly into
|
||||
// Decimal.fromString, so we parse out the mantissa and exponent separately before combining them
|
||||
const regex = /(?<mantissa>\d*[.]?\d+)e(?<exponent>\d*[.]?\d+)/u;
|
||||
const match = input.replaceAll(",", "").match(regex);
|
||||
decimal = Decimal.pow10(Math.log10(Number(match.groups.mantissa)) + Number(match.groups.exponent));
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user