| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // Dart test program to test arithmetic operations. | 4 // Dart test program to test arithmetic operations. |
| 5 // VMOptions=--optimization-counter-threshold=10 --no-use-osr | 5 // VMOptions=--optimization-counter-threshold=10 --no-use-osr --no-background-co
mpilation |
| 6 | 6 |
| 7 library arithmetic_test; | 7 library arithmetic_test; |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import 'dart:math'; | 9 import 'dart:math'; |
| 10 | 10 |
| 11 class ArithmeticTest { | 11 class ArithmeticTest { |
| 12 | 12 |
| 13 static bool exceptionCaughtParseInt(String s) { | 13 static bool exceptionCaughtParseInt(String s) { |
| 14 try { | 14 try { |
| 15 int.parse(s); | 15 int.parse(s); |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 Expect.equals(true, (10).hashCode == (10).hashCode); | 416 Expect.equals(true, (10).hashCode == (10).hashCode); |
| 417 } | 417 } |
| 418 | 418 |
| 419 static int div(a, b) => a ~/ b; | 419 static int div(a, b) => a ~/ b; |
| 420 | 420 |
| 421 static void testSmiDivDeopt() { | 421 static void testSmiDivDeopt() { |
| 422 var a = -0x40000000; | 422 var a = -0x40000000; |
| 423 var b = -1; | 423 var b = -1; |
| 424 for (var i = 0; i < 10; i++) Expect.equals(0x40000000, div(a, b)); | 424 for (var i = 0; i < 10; i++) Expect.equals(0x40000000, div(a, b)); |
| 425 } | 425 } |
| 426 | 426 |
| 427 | 427 |
| 428 static int divMod(a, b) => a ~/ b + a % b; | 428 static int divMod(a, b) => a ~/ b + a % b; |
| 429 | 429 |
| 430 static void testSmiDivModDeopt() { | 430 static void testSmiDivModDeopt() { |
| 431 var a = -0x40000000; | 431 var a = -0x40000000; |
| 432 var b = -1; | 432 var b = -1; |
| 433 for (var i = 0; i < 10; i++) Expect.equals(0x40000000, divMod(a, b)); | 433 for (var i = 0; i < 10; i++) Expect.equals(0x40000000, divMod(a, b)); |
| 434 } | 434 } |
| 435 | 435 |
| 436 static double sinCosSub(double a) => sin(a) - cos(a); | 436 static double sinCosSub(double a) => sin(a) - cos(a); |
| 437 | 437 |
| 438 static double sinCosAddCos(double a) => sin(a) * cos(a) + cos(a); | 438 static double sinCosAddCos(double a) => sin(a) * cos(a) + cos(a); |
| 439 | 439 |
| 440 static void testSinCos() { | 440 static void testSinCos() { |
| 441 var e = sin(1.234) - cos(1.234); | 441 var e = sin(1.234) - cos(1.234); |
| 442 var f = sin(1.234) * cos(1.234) + cos(1.234); | 442 var f = sin(1.234) * cos(1.234) + cos(1.234); |
| 443 | 443 |
| 444 for (var i = 0; i < 20; i++) { | 444 for (var i = 0; i < 20; i++) { |
| 445 Expect.approxEquals(e, sinCosSub(1.234)); | 445 Expect.approxEquals(e, sinCosSub(1.234)); |
| 446 Expect.approxEquals(f, sinCosAddCos(1.234)); | 446 Expect.approxEquals(f, sinCosAddCos(1.234)); |
| 447 } | 447 } |
| 448 Expect.approxEquals(1.0, sinCosSub(3.14159265)); | 448 Expect.approxEquals(1.0, sinCosSub(3.14159265)); |
| 449 Expect.approxEquals(1.0, sinCosSub(3.14159265 / 2.0)); | 449 Expect.approxEquals(1.0, sinCosSub(3.14159265 / 2.0)); |
| 450 } | 450 } |
| 451 | 451 |
| 452 // Test fix for issue 16592. | 452 // Test fix for issue 16592. |
| 453 static void testSinCosNoUse() { | 453 static void testSinCosNoUse() { |
| 454 for (var i = 0; i < 20; i++) { | 454 for (var i = 0; i < 20; i++) { |
| 455 sin(i); | 455 sin(i); |
| 456 cos(i); | 456 cos(i); |
| 457 } | 457 } |
| 458 } | 458 } |
| 459 | 459 |
| 460 static mySqrt(var x) => sqrt(x); | 460 static mySqrt(var x) => sqrt(x); |
| 461 | 461 |
| 462 static testSqrtDeopt() { | 462 static testSqrtDeopt() { |
| 463 for (var i = 0; i < 10; i++) mySqrt(4.0); | 463 for (var i = 0; i < 10; i++) mySqrt(4.0); |
| 464 Expect.equals(2.0, mySqrt(4.0)); | 464 Expect.equals(2.0, mySqrt(4.0)); |
| 465 Expect.throws(() => mySqrt("abc")); | 465 Expect.throws(() => mySqrt("abc")); |
| 466 } | 466 } |
| 467 | 467 |
| 468 static self_equality(x) { | 468 static self_equality(x) { |
| 469 return x == x; | 469 return x == x; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 486 testDoubleEquality(); | 486 testDoubleEquality(); |
| 487 testSinCos(); | 487 testSinCos(); |
| 488 testSinCosNoUse(); | 488 testSinCosNoUse(); |
| 489 } | 489 } |
| 490 } | 490 } |
| 491 } | 491 } |
| 492 | 492 |
| 493 main() { | 493 main() { |
| 494 ArithmeticTest.testMain(); | 494 ArithmeticTest.testMain(); |
| 495 } | 495 } |
| OLD | NEW |