[tests] Make corelib/compare_to2_test work for web numbers

Change-Id: I98d13d92c486851630aa00f42ed981c1acf0ba53
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333043
Reviewed-by: Mayank Patke <fishythefish@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
This commit is contained in:
Stephen Adams 2023-10-31 22:52:40 +00:00 committed by Commit Queue
parent 182b7e753c
commit 718f9076bd

View file

@ -19,7 +19,8 @@ main() {
var maxNonIntFloorAsDouble = maxNonIntFloorAsInt.toDouble();
var maxExactIntAsDouble = 9007199254740992.0;
var maxExactIntAsInt = 9007199254740992;
var two53 = 1 << 53; // Same as maxExactIntAsInt.
// Can't use 1 << 53 with web numbers. 2^53 = (2^10)^5 * 2^3.
int two53 = 1024 * 1024 * 1024 * 1024 * 1024 * 8; // Same as maxExactIntAsInt.
var two53p1 = two53 + 1;
var maxFiniteAsDouble = 1.7976931348623157e+308;
var maxFiniteAsInt = maxFiniteAsDouble.truncate();
@ -28,14 +29,16 @@ main() {
var mnan = negate(nan);
var minInt64 = -0x8000000000000000;
var minInt64AsDouble = minInt64.toDouble();
var maxInt64 = 0x7fffffffffffffff;
// Split 0x7fffffffffffffff into sum of two web numbers. When compiled to
// JavaScript the sum will round up.
var maxInt64 = 0x7ffffffffffff000 + 0xfff;
var maxInt64AsDouble = maxInt64.toDouble(); // 1 << 63
var matrix = [
-inf,
-maxFiniteAsDouble,
[minInt64, minInt64AsDouble],
[-maxInt64, -maxFiniteAsInt],
-two53p1,
[minInt64, if (!webNumbers) minInt64AsDouble],
if (!webNumbers) [-maxInt64, -maxFiniteAsInt],
if (!webNumbers) -two53p1,
[-two53, -maxExactIntAsInt, -maxExactIntAsDouble],
-maxNonInt,
[-maxNonIntFloorAsDouble, -maxNonIntFloorAsInt],
@ -58,9 +61,9 @@ main() {
[maxNonIntFloorAsDouble, maxNonIntFloorAsInt],
maxNonInt,
[two53, maxExactIntAsInt, maxExactIntAsDouble],
two53p1,
[maxInt64, maxFiniteAsInt],
maxInt64AsDouble,
if (!webNumbers) two53p1,
[maxInt64, if (!webNumbers) maxFiniteAsInt],
if (!webNumbers) maxInt64AsDouble,
maxFiniteAsDouble,
inf,
[nan, mnan],