diff --git a/src/db.ts b/src/db.ts index eb65805..f530aac 100644 --- a/src/db.ts +++ b/src/db.ts @@ -157,7 +157,7 @@ export class DB { value = value ? 1 : 0; // fall through case "number": - if (Math.floor(value) === value) { + if (Number.isSafeInteger(value)) { status = this._wasm.bind_int(stmt, i + 1, value); } else { status = this._wasm.bind_double(stmt, i + 1, value); diff --git a/test.ts b/test.ts index 83f6357..5044562 100644 --- a/test.ts +++ b/test.ts @@ -786,3 +786,26 @@ Deno.test("outputToObjectArrayEmpty", function () { "Result is not an array or does not have the correct length", ); }); + +Deno.test("veryLargeNumbers", function () { + const db = new DB(); + + db.query("CREATE TABLE numbers (id INTEGER PRIMARY KEY, number REAL)"); + + db.query("INSERT INTO numbers (number) VALUES (?)", [+Infinity]); + db.query("INSERT INTO numbers (number) VALUES (?)", [-Infinity]); + db.query("INSERT INTO numbers (number) VALUES (?)", [+20e20]); + db.query("INSERT INTO numbers (number) VALUES (?)", [-20e20]); + + const [ + [positiveInfinity], + [negativeInfinity], + [positiveTwentyTwenty], + [negativeTwentyTwenty], + ] = db.query("SELECT number FROM numbers"); + + assertEquals(negativeInfinity, -Infinity); + assertEquals(positiveInfinity, +Infinity); + assertEquals(positiveTwentyTwenty, +20e20); + assertEquals(negativeTwentyTwenty, -20e20); +});