Merge pull request #2582 from deathly809/bug/helper_number_should_handle_nan

Ensure INetscriptHelper number function handles NaN
This commit is contained in:
hydroflame 2022-01-12 11:14:51 -05:00 committed by GitHub
commit d2fadfe600
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

@ -13,7 +13,6 @@ import { SourceFileFlags } from "../SourceFile/SourceFileFlags";
import { dialogBoxCreate } from "../ui/React/DialogBox";
import { clearObject } from "../utils/helpers/clearObject";
import { Router } from "../ui/GameRoot";
import { WHRNG } from "../Casino/RNG";

@ -432,8 +432,11 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
throw makeRuntimeErrorMsg(funcName, `${argName} should be a string`);
},
number: (funcName: string, argName: string, v: any): number => {
if (!isNaN(v))
{
if (typeof v === "number") return v;
if (!isNaN(v) && !isNaN(parseFloat(v))) return parseFloat(v);
if (!isNaN(parseFloat(v))) return parseFloat(v);
}
throw makeRuntimeErrorMsg(funcName, `${argName} should be a number`);
},
boolean: (v: any): boolean => {