Migrate language_2/double to NNBD.

Change-Id: I72b95b7d84847c1b7c4e89ba607dfca6d9069854
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142212
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
This commit is contained in:
Robert Nystrom 2020-04-04 00:25:17 +00:00 committed by commit-bot@chromium.org
parent 8cb5ba4adc
commit 9be92b28f1
20 changed files with 566 additions and 0 deletions

View file

@ -0,0 +1,16 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Tests VM optimizing compiler negate condition for doubles (bug 5376516).
loop() {
for (double d = 0.0; d < 1100.0; d++) {}
for (double d = 0.0; d <= 1100.0; d++) {}
for (double d = 1000.0; d > 0.0; d--) {}
for (double d = 1000.0; d >= 0.0; d--) {}
}
main() {
loop();
loop();
}

View file

@ -0,0 +1,14 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
main() {
Expect.isTrue(identical(42.0, 42.0));
Expect.isTrue(identical(-0.0, -0.0));
Expect.isTrue(identical(0.0, 0.0));
Expect.isTrue(identical(1.234E9, 1.234E9));
Expect.isFalse(identical(0.0, -0.0));
Expect.isTrue(identical(double.nan, double.nan));
}

View file

@ -0,0 +1,20 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr
import "package:expect/expect.dart";
// Test that optimized code does not silently convert integers to doubles.
main() {
// Optimize add-op
for (int i = 0; i < 20; i++) {
addOp(1.1, 2.1);
}
Expect.isTrue(addOp(1.1, 2.1) is double);
Expect.isTrue(addOp(1, 2) is int);
}
addOp(a, b) => a + b;

View file

@ -0,0 +1,20 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test basic integer operations.
import "package:expect/expect.dart";
main() {
Expect.equals("0.0", (0.0).toString());
Expect.equals("9.0", (9.0).toString());
Expect.equals("90.0", (90.0).toString());
Expect.equals(
"111111111111111110000.0", (111111111111111111111.0).toString());
Expect.equals("-9.0", (-9.0).toString());
Expect.equals("-90.0", (-90.0).toString());
Expect.equals(
"-111111111111111110000.0", (-111111111111111111111.0).toString());
Expect.equals("1000.0", (1000.0).toString());
Expect.equals("1000000000000000100.0", (1000000000000000128.0).toString());
}

View file

@ -0,0 +1,13 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test an invalid double format
main() {
;
}

View file

@ -0,0 +1,14 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test an invalid double format
main() {
3457e
//^
// [cfe] Numbers in exponential notation should always contain an exponent (an integer number with an optional sign).
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_DIGIT
;
}

View file

@ -0,0 +1,19 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Dart test optimization of modulo operator on Double.
// VMOptions=--optimization-counter-threshold=10
import "package:expect/expect.dart";
main() {
double k = -0.33333;
double firstResPos = doMod(k, 1.0);
double firstResNeg = doMod(k, -1.0);
for (int i = 0; i < 20; i++) {
Expect.equals(firstResPos, doMod(k, 1.0));
Expect.equals(firstResNeg, doMod(k, -1.0));
}
}
doMod(a, b) => a % b;

View file

@ -0,0 +1,32 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Tests double comparisons with NaN in different contexts.
// VMOptions=--optimization-counter-threshold=10
import "package:expect/expect.dart";
test_expr(a, b) => a != b;
test_conditional(a, b) => a != b ? true : false;
test_branch(a, b) {
if (a != b) {
return true;
}
return false;
}
main() {
Expect.equals(true, test_expr(0.5, double.nan));
for (var i = 0; i < 20; i++) test_expr(0.5, double.nan);
Expect.equals(true, test_expr(0.5, double.nan));
Expect.equals(true, test_conditional(0.5, double.nan));
for (var i = 0; i < 20; i++) test_conditional(0.5, double.nan);
Expect.equals(true, test_conditional(0.5, double.nan));
Expect.equals(true, test_branch(0.5, double.nan));
for (var i = 0; i < 20; i++) test_branch(0.5, double.nan);
Expect.equals(true, test_branch(0.5, double.nan));
}

View file

@ -0,0 +1,18 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test basic integer operations.
import "package:expect/expect.dart";
main() {
var v = 1.0;
Expect.throwsRangeError(() => v.toStringAsExponential(-1));
Expect.throwsRangeError(() => v.toStringAsExponential(21));
}

View file

@ -0,0 +1,24 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test basic integer operations.
import "package:expect/expect.dart";
main() {
var v = 1.0;
Expect.throwsRangeError(() => v.toStringAsExponential(-1));
Expect.throwsRangeError(() => v.toStringAsExponential(21));
v.toStringAsExponential(1.5);
// ^^^
// [analyzer] STATIC_WARNING.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] The argument type 'double' can't be assigned to the parameter type 'int?'.
v.toStringAsExponential("string");
// ^^^^^^^^
// [analyzer] STATIC_WARNING.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] The argument type 'String' can't be assigned to the parameter type 'int?'.
v.toStringAsExponential("3");
// ^^^
// [analyzer] STATIC_WARNING.ARGUMENT_TYPE_NOT_ASSIGNABLE
// [cfe] The argument type 'String' can't be assigned to the parameter type 'int?'.
}

View file

@ -0,0 +1,12 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test basic integer operations.
import "package:expect/expect.dart";
main() {
Expect.equals("1.00000000000000000000e+0", (1.0).toStringAsExponential(20));
Expect.equals("1.00000000000000005551e-1", (0.1).toStringAsExponential(20));
Expect.equals(1.00000000000000005551e-1, 0.1);
}

View file

@ -0,0 +1,100 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test basic integer operations.
import "package:expect/expect.dart";
main() {
Expect.equals("1e+0", (1.0).toStringAsExponential());
Expect.equals("1.1e+1", (11.0).toStringAsExponential());
Expect.equals("1.12e+2", (112.0).toStringAsExponential());
Expect.equals("1e+0", (1.0).toStringAsExponential(null));
Expect.equals("1.1e+1", (11.0).toStringAsExponential(null));
Expect.equals("1.12e+2", (112.0).toStringAsExponential(null));
Expect.equals("1e+0", (1.0).toStringAsExponential(0));
Expect.equals("1e+1", (11.0).toStringAsExponential(0));
Expect.equals("1e+2", (112.0).toStringAsExponential(0));
Expect.equals("1.0e+0", (1.0).toStringAsExponential(1));
Expect.equals("1.1e+1", (11.0).toStringAsExponential(1));
Expect.equals("1.1e+2", (112.0).toStringAsExponential(1));
Expect.equals("1.00e+0", (1.0).toStringAsExponential(2));
Expect.equals("1.10e+1", (11.0).toStringAsExponential(2));
Expect.equals("1.12e+2", (112.0).toStringAsExponential(2));
Expect.equals("1.000e+0", (1.0).toStringAsExponential(3));
Expect.equals("1.100e+1", (11.0).toStringAsExponential(3));
Expect.equals("1.120e+2", (112.0).toStringAsExponential(3));
Expect.equals("1e-1", (0.1).toStringAsExponential());
Expect.equals("1.1e-1", (0.11).toStringAsExponential());
Expect.equals("1.12e-1", (0.112).toStringAsExponential());
Expect.equals("1e-1", (0.1).toStringAsExponential(null));
Expect.equals("1.1e-1", (0.11).toStringAsExponential(null));
Expect.equals("1.12e-1", (0.112).toStringAsExponential(null));
Expect.equals("1e-1", (0.1).toStringAsExponential(0));
Expect.equals("1e-1", (0.11).toStringAsExponential(0));
Expect.equals("1e-1", (0.112).toStringAsExponential(0));
Expect.equals("1.0e-1", (0.1).toStringAsExponential(1));
Expect.equals("1.1e-1", (0.11).toStringAsExponential(1));
Expect.equals("1.1e-1", (0.112).toStringAsExponential(1));
Expect.equals("1.00e-1", (0.1).toStringAsExponential(2));
Expect.equals("1.10e-1", (0.11).toStringAsExponential(2));
Expect.equals("1.12e-1", (0.112).toStringAsExponential(2));
Expect.equals("1.000e-1", (0.1).toStringAsExponential(3));
Expect.equals("1.100e-1", (0.11).toStringAsExponential(3));
Expect.equals("1.120e-1", (0.112).toStringAsExponential(3));
Expect.equals("-0e+0", (-0.0).toStringAsExponential());
Expect.equals("-1e+0", (-1.0).toStringAsExponential());
Expect.equals("-1.1e+1", (-11.0).toStringAsExponential());
Expect.equals("-1.12e+2", (-112.0).toStringAsExponential());
Expect.equals("-0e+0", (-0.0).toStringAsExponential(null));
Expect.equals("-1e+0", (-1.0).toStringAsExponential(null));
Expect.equals("-1.1e+1", (-11.0).toStringAsExponential(null));
Expect.equals("-1.12e+2", (-112.0).toStringAsExponential(null));
Expect.equals("-1e+0", (-1.0).toStringAsExponential(0));
Expect.equals("-1e+1", (-11.0).toStringAsExponential(0));
Expect.equals("-1e+2", (-112.0).toStringAsExponential(0));
Expect.equals("-1.0e+0", (-1.0).toStringAsExponential(1));
Expect.equals("-1.1e+1", (-11.0).toStringAsExponential(1));
Expect.equals("-1.1e+2", (-112.0).toStringAsExponential(1));
Expect.equals("-1.00e+0", (-1.0).toStringAsExponential(2));
Expect.equals("-1.10e+1", (-11.0).toStringAsExponential(2));
Expect.equals("-1.12e+2", (-112.0).toStringAsExponential(2));
Expect.equals("-1.000e+0", (-1.0).toStringAsExponential(3));
Expect.equals("-1.100e+1", (-11.0).toStringAsExponential(3));
Expect.equals("-1.120e+2", (-112.0).toStringAsExponential(3));
Expect.equals("-1e-1", (-0.1).toStringAsExponential());
Expect.equals("-1.1e-1", (-0.11).toStringAsExponential());
Expect.equals("-1.12e-1", (-0.112).toStringAsExponential());
Expect.equals("-1e-1", (-0.1).toStringAsExponential(null));
Expect.equals("-1.1e-1", (-0.11).toStringAsExponential(null));
Expect.equals("-1.12e-1", (-0.112).toStringAsExponential(null));
Expect.equals("-1e-1", (-0.1).toStringAsExponential(0));
Expect.equals("-1e-1", (-0.11).toStringAsExponential(0));
Expect.equals("-1e-1", (-0.112).toStringAsExponential(0));
Expect.equals("-1.0e-1", (-0.1).toStringAsExponential(1));
Expect.equals("-1.1e-1", (-0.11).toStringAsExponential(1));
Expect.equals("-1.1e-1", (-0.112).toStringAsExponential(1));
Expect.equals("-1.00e-1", (-0.1).toStringAsExponential(2));
Expect.equals("-1.10e-1", (-0.11).toStringAsExponential(2));
Expect.equals("-1.12e-1", (-0.112).toStringAsExponential(2));
Expect.equals("-1.000e-1", (-0.1).toStringAsExponential(3));
Expect.equals("-1.100e-1", (-0.11).toStringAsExponential(3));
Expect.equals("-1.120e-1", (-0.112).toStringAsExponential(3));
Expect.equals("NaN", (double.nan).toStringAsExponential(2));
Expect.equals("Infinity", (double.infinity).toStringAsExponential(2));
Expect.equals("-Infinity", (-double.infinity).toStringAsExponential(2));
Expect.equals("1e+0", (1.0).toStringAsExponential(0));
Expect.equals("0e+0", (0.0).toStringAsExponential());
Expect.equals("0e+0", (0.0).toStringAsExponential(null));
Expect.equals("0.00e+0", (0.0).toStringAsExponential(2));
Expect.equals("1e+1", (11.2356).toStringAsExponential(0));
Expect.equals("1.1236e+1", (11.2356).toStringAsExponential(4));
Expect.equals("1.1236e-4", (0.000112356).toStringAsExponential(4));
Expect.equals("-1.1236e-4", (-0.000112356).toStringAsExponential(4));
Expect.equals("1.12356e-4", (0.000112356).toStringAsExponential());
Expect.equals("-1.12356e-4", (-0.000112356).toStringAsExponential());
Expect.equals("1.12356e-4", (0.000112356).toStringAsExponential(null));
Expect.equals("-1.12356e-4", (-0.000112356).toStringAsExponential(null));
}

View file

@ -0,0 +1,18 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test basic integer operations.
import "package:expect/expect.dart";
main() {
var v = 0.0;
Expect.throwsRangeError(() => v.toStringAsFixed(-1));
Expect.throwsRangeError(() => v.toStringAsFixed(21));
}

View file

@ -0,0 +1,104 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test basic integer operations.
import "package:expect/expect.dart";
class ToStringAsFixedTest {
static void testMain() {
Expect.equals("2.000", 2.0.toStringAsFixed(3));
Expect.equals("2.100", 2.1.toStringAsFixed(3));
Expect.equals("2.120", 2.12.toStringAsFixed(3));
Expect.equals("2.123", 2.123.toStringAsFixed(3));
Expect.equals("2.124", 2.1239.toStringAsFixed(3));
Expect.equals("NaN", (0.0 / 0.0).toStringAsFixed(3));
Expect.equals("Infinity", (1.0 / 0.0).toStringAsFixed(3));
Expect.equals("-Infinity", (-1.0 / 0.0).toStringAsFixed(3));
Expect.equals(
"1.1111111111111111e+21", 1111111111111111111111.0.toStringAsFixed(8));
Expect.equals("0.1", 0.1.toStringAsFixed(1));
Expect.equals("0.10", 0.1.toStringAsFixed(2));
Expect.equals("0.100", 0.1.toStringAsFixed(3));
Expect.equals("0.01", 0.01.toStringAsFixed(2));
Expect.equals("0.010", 0.01.toStringAsFixed(3));
Expect.equals("0.0100", 0.01.toStringAsFixed(4));
Expect.equals("0.00", 0.001.toStringAsFixed(2));
Expect.equals("0.001", 0.001.toStringAsFixed(3));
Expect.equals("0.0010", 0.001.toStringAsFixed(4));
Expect.equals("1.0000", 1.0.toStringAsFixed(4));
Expect.equals("1.0", 1.0.toStringAsFixed(1));
Expect.equals("1", 1.0.toStringAsFixed(0));
Expect.equals("12", 12.0.toStringAsFixed(0));
Expect.equals("1", 1.1.toStringAsFixed(0));
Expect.equals("12", 12.1.toStringAsFixed(0));
Expect.equals("1", 1.12.toStringAsFixed(0));
Expect.equals("12", 12.12.toStringAsFixed(0));
Expect.equals("0.0000006", 0.0000006.toStringAsFixed(7));
Expect.equals("0.00000006", 0.00000006.toStringAsFixed(8));
Expect.equals("0.000000060", 0.00000006.toStringAsFixed(9));
Expect.equals("0.0000000600", 0.00000006.toStringAsFixed(10));
Expect.equals("0", 0.0.toStringAsFixed(0));
Expect.equals("0.0", 0.0.toStringAsFixed(1));
Expect.equals("0.00", 0.0.toStringAsFixed(2));
Expect.equals("-0.1", (-0.1).toStringAsFixed(1));
Expect.equals("-0.10", (-0.1).toStringAsFixed(2));
Expect.equals("-0.100", (-0.1).toStringAsFixed(3));
Expect.equals("-0.01", (-0.01).toStringAsFixed(2));
Expect.equals("-0.010", (-0.01).toStringAsFixed(3));
Expect.equals("-0.0100", (-0.01).toStringAsFixed(4));
Expect.equals("-0.00", (-0.001).toStringAsFixed(2));
Expect.equals("-0.001", (-0.001).toStringAsFixed(3));
Expect.equals("-0.0010", (-0.001).toStringAsFixed(4));
Expect.equals("-1.0000", (-1.0).toStringAsFixed(4));
Expect.equals("-1.0", (-1.0).toStringAsFixed(1));
Expect.equals("-1", (-1.0).toStringAsFixed(0));
Expect.equals("-1", (-1.1).toStringAsFixed(0));
Expect.equals("-12", (-12.1).toStringAsFixed(0));
Expect.equals("-1", (-1.12).toStringAsFixed(0));
Expect.equals("-12", (-12.12).toStringAsFixed(0));
Expect.equals("-0.0000006", (-0.0000006).toStringAsFixed(7));
Expect.equals("-0.00000006", (-0.00000006).toStringAsFixed(8));
Expect.equals("-0.000000060", (-0.00000006).toStringAsFixed(9));
Expect.equals("-0.0000000600", (-0.00000006).toStringAsFixed(10));
Expect.equals("-0", (-0.0).toStringAsFixed(0));
Expect.equals("-0.0", (-0.0).toStringAsFixed(1));
Expect.equals("-0.00", (-0.0).toStringAsFixed(2));
Expect.equals("1000", 1000.0.toStringAsFixed(0));
Expect.equals("0", 0.00001.toStringAsFixed(0));
Expect.equals("0.00001", 0.00001.toStringAsFixed(5));
Expect.equals(
"0.00000000000000000010", 0.0000000000000000001.toStringAsFixed(20));
Expect.equals("0.00001000000000000", 0.00001.toStringAsFixed(17));
Expect.equals("1.00000000000000000", 1.0.toStringAsFixed(17));
Expect.equals(
"1000000000000000128", 1000000000000000128.0.toStringAsFixed(0));
Expect.equals(
"100000000000000128.0", 100000000000000128.0.toStringAsFixed(1));
Expect.equals(
"10000000000000128.00", 10000000000000128.0.toStringAsFixed(2));
Expect.equals("10000000000000128.00000000000000000000",
10000000000000128.0.toStringAsFixed(20));
Expect.equals("0", 0.0.toStringAsFixed(0));
Expect.equals("-42.000", (-42.0).toStringAsFixed(3));
Expect.equals(
"-1000000000000000128", (-1000000000000000128.0).toStringAsFixed(0));
Expect.equals("-0.00000000000000000010",
(-0.0000000000000000001).toStringAsFixed(20));
Expect.equals(
"0.12312312312312299889", 0.123123123123123.toStringAsFixed(20));
// Test that we round up even when the last digit generated is even.
// dtoa does not do this in its original form.
Expect.equals("1", 0.5.toStringAsFixed(0));
Expect.equals("-1", (-0.5).toStringAsFixed(0));
Expect.equals("1.3", 1.25.toStringAsFixed(1));
Expect.equals("234.2040", 234.20405.toStringAsFixed(4));
Expect.equals("234.2041", 234.2040506.toStringAsFixed(4));
}
}
main() {
ToStringAsFixedTest.testMain();
}

View file

@ -0,0 +1,18 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test basic integer operations.
import "package:expect/expect.dart";
main() {
var v = 0.0;
Expect.throwsRangeError(() => v.toStringAsPrecision(0));
Expect.throwsRangeError(() => v.toStringAsPrecision(22));
}

View file

@ -0,0 +1,18 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test basic integer operations.
import "package:expect/expect.dart";
main() {
Expect.equals(
"0.000555000000000000046248", (0.000555).toStringAsPrecision(21));
Expect.equals(0.000555000000000000046248, 0.000555);
Expect.equals(
"5.54999999999999980179e-7", (0.000000555).toStringAsPrecision(21));
Expect.equals(5.54999999999999980179e-7, 0.000000555);
Expect.equals(
"-5.54999999999999980179e-7", (-0.000000555).toStringAsPrecision(21));
Expect.equals(-5.54999999999999980179e-7, -0.000000555);
}

View file

@ -0,0 +1,42 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test basic integer operations.
import "package:expect/expect.dart";
main() {
Expect.equals("NaN", (double.nan).toStringAsPrecision(1));
Expect.equals("Infinity", (double.infinity).toStringAsPrecision(2));
Expect.equals("-Infinity", (-double.infinity).toStringAsPrecision(2));
Expect.equals("0.000555000000000000", (0.000555).toStringAsPrecision(15));
Expect.equals("5.55000000000000e-7", (0.000000555).toStringAsPrecision(15));
Expect.equals("-5.55000000000000e-7", (-0.000000555).toStringAsPrecision(15));
Expect.equals("1e+8", (123456789.0).toStringAsPrecision(1));
Expect.equals("123456789", (123456789.0).toStringAsPrecision(9));
Expect.equals("1.2345679e+8", (123456789.0).toStringAsPrecision(8));
Expect.equals("1.234568e+8", (123456789.0).toStringAsPrecision(7));
Expect.equals("-1.234568e+8", (-123456789.0).toStringAsPrecision(7));
Expect.equals("-1.2e-9", (-.0000000012345).toStringAsPrecision(2));
Expect.equals("-1.2e-8", (-.000000012345).toStringAsPrecision(2));
Expect.equals("-1.2e-7", (-.00000012345).toStringAsPrecision(2));
Expect.equals("-0.0000012", (-.0000012345).toStringAsPrecision(2));
Expect.equals("-0.000012", (-.000012345).toStringAsPrecision(2));
Expect.equals("-0.00012", (-.00012345).toStringAsPrecision(2));
Expect.equals("-0.0012", (-.0012345).toStringAsPrecision(2));
Expect.equals("-0.012", (-.012345).toStringAsPrecision(2));
Expect.equals("-0.12", (-.12345).toStringAsPrecision(2));
Expect.equals("-1.2", (-1.2345).toStringAsPrecision(2));
Expect.equals("-12", (-12.345).toStringAsPrecision(2));
Expect.equals("-1.2e+2", (-123.45).toStringAsPrecision(2));
Expect.equals("-1.2e+3", (-1234.5).toStringAsPrecision(2));
Expect.equals("-1.2e+4", (-12345.0).toStringAsPrecision(2));
Expect.equals("-1.235e+4", (-12345.67).toStringAsPrecision(4));
Expect.equals("-1.234e+4", (-12344.67).toStringAsPrecision(4));
Expect.equals("-0.0", (-0.0).toStringAsPrecision(2));
Expect.equals("-0", (-0.0).toStringAsPrecision(1));
// Test that we round up even when the last digit generated is even.
// dtoa does not do this in its original form.
Expect.equals("1.3", 1.25.toStringAsPrecision(2));
Expect.equals("1.4", 1.35.toStringAsPrecision(2));
}

View file

@ -0,0 +1,56 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test basic integer operations.
import "package:expect/expect.dart";
main() {
Expect.equals("NaN", (double.nan).toString());
Expect.equals("Infinity", (1 / 0).toString());
Expect.equals("-Infinity", (-1 / 0).toString());
Expect.equals("90.12", (90.12).toString());
Expect.equals("0.1", (0.1).toString());
Expect.equals("0.01", (0.01).toString());
Expect.equals("0.0123", (0.0123).toString());
Expect.equals(
"1.1111111111111111e+21", (1111111111111111111111.0).toString());
Expect.equals(
"1.1111111111111111e+22", (11111111111111111111111.0).toString());
Expect.equals("0.00001", (0.00001).toString());
Expect.equals("0.000001", (0.000001).toString());
Expect.equals("1e-7", (0.0000001).toString());
Expect.equals("1.2e-7", (0.00000012).toString());
Expect.equals("1.23e-7", (0.000000123).toString());
Expect.equals("1e-8", (0.00000001).toString());
Expect.equals("1.2e-8", (0.000000012).toString());
Expect.equals("1.23e-8", (0.0000000123).toString());
Expect.equals("-0.0", (-0.0).toString());
Expect.equals("-90.12", (-90.12).toString());
Expect.equals("-0.1", (-0.1).toString());
Expect.equals("-0.01", (-0.01).toString());
Expect.equals("-0.0123", (-0.0123).toString());
Expect.equals(
"-1.1111111111111111e+21", (-1111111111111111111111.0).toString());
Expect.equals(
"-1.1111111111111111e+22", (-11111111111111111111111.0).toString());
Expect.equals("-0.00001", (-0.00001).toString());
Expect.equals("-0.000001", (-0.000001).toString());
Expect.equals("-1e-7", (-0.0000001).toString());
Expect.equals("-1.2e-7", (-0.00000012).toString());
Expect.equals("-1.23e-7", (-0.000000123).toString());
Expect.equals("-1e-8", (-0.00000001).toString());
Expect.equals("-1.2e-8", (-0.000000012).toString());
Expect.equals("-1.23e-8", (-0.0000000123).toString());
Expect.equals("0.00001", (0.00001).toString());
Expect.equals("1e+21", (1000000000000000012800.0).toString());
Expect.equals("-1e+21", (-1000000000000000012800.0).toString());
Expect.equals("1e-7", (0.0000001).toString());
Expect.equals("-1e-7", (-0.0000001).toString());
Expect.equals(
"1.0000000000000001e+21", (1000000000000000128000.0).toString());
Expect.equals("0.000001", (0.000001).toString());
Expect.equals("1e-7", (0.0000001).toString());
}

View file

@ -3,6 +3,10 @@
// BSD-style license that can be found in the LICENSE file.
// Test basic integer operations.
// [NNBD non-migrated]: This test has no language/ counterpart. The static
// errors are just redundant tests of the static type system, and the runtime
// errors are redundant with to_string_as_fixed2_runtime_test.dart.
import "package:expect/expect.dart";
main() {

View file

@ -3,6 +3,10 @@
// BSD-style license that can be found in the LICENSE file.
// Test basic integer operations.
// [NNBD non-migrated]: This test has no language/ counterpart. The static
// errors are just redundant tests of the static type system, and the runtime
// errors are redundant with to_string_as_precision2_runtime_test.dart.
import "package:expect/expect.dart";
main() {