Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/built-ins/Number/parseFloat.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ describe("Number.parseFloat", () => {
test("returns NaN for non-parseable strings", () => {
expect(Number.isNaN(Number.parseFloat("abc"))).toBe(true);
});

test("parses Infinity", () => {
expect(Number.parseFloat("Infinity")).toBe(Infinity);
expect(Number.parseFloat("+Infinity")).toBe(Infinity);
expect(Number.parseFloat("-Infinity")).toBe(-Infinity);
expect(Number.parseFloat(" Infinity ")).toBe(Infinity);
});
});
6 changes: 6 additions & 0 deletions tests/built-ins/Number/parseInt.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ describe("Number.parseInt", () => {
test("leading plus sign", () => {
expect(Number.parseInt("+42")).toBe(42);
});

test("Infinity returns NaN", () => {
expect(Number.isNaN(Number.parseInt("Infinity"))).toBe(true);
expect(Number.isNaN(Number.parseInt("-Infinity"))).toBe(true);
expect(Number.isNaN(Number.parseInt("+Infinity"))).toBe(true);
});
});
14 changes: 12 additions & 2 deletions units/Goccia.Builtins.GlobalNumber.pas
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,19 @@ function TGocciaGlobalNumber.NumberParseFloat(const AArgs: TGocciaArgumentsColle
Inc(I);
end;

// Step 3b: Check for "Infinity" literal (StrDecimalLiteral :: Infinity)
if Copy(InputStr, I, 8) = 'Infinity' then
begin
if Sign = -1 then
Result := TGocciaNumberLiteralValue.NegativeInfinityValue
else
Result := TGocciaNumberLiteralValue.InfinityValue;
Exit;
end;

IntegerPart := 0;

// Step 3b: Parse DecimalDigits (integer part)
// Step 3c: Parse DecimalDigits (integer part)
while I <= Length(InputStr) do
begin
C := InputStr[I];
Expand All @@ -241,7 +251,7 @@ function TGocciaGlobalNumber.NumberParseFloat(const AArgs: TGocciaArgumentsColle
FractionalPart := 0;
FractionDivisor := 1;

// Step 3c: Parse optional '.' DecimalDigits (fractional part)
// Step 3d: Parse optional '.' DecimalDigits (fractional part)
if (I <= Length(InputStr)) and (InputStr[I] = '.') then
begin
Inc(I);
Expand Down
Loading