Chromium Code Reviews| Index: tests/standalone/fixed_precision_double_test.dart |
| diff --git a/tests/standalone/fixed_precision_double_test.dart b/tests/standalone/fixed_precision_double_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..34d4576706f1d1a66614672b60ca06fdc11477ec |
| --- /dev/null |
| +++ b/tests/standalone/fixed_precision_double_test.dart |
| @@ -0,0 +1,40 @@ |
| +// Copyright (c) 2016, 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"; |
| + |
| +bool TestAssociativity(bool chop) { |
|
Florian Schneider
2016/08/03 23:35:58
For testing here maybe pass in a function chop (or
regis
2016/08/04 18:22:31
Done.
|
| + // Example from https://en.wikipedia.org/wiki/Floating_point |
| + // Test that (a + b) + c == a + (b + c). |
| + double a = chop ? 1234.567.p : 1234.567; // Chop literals. |
| + double b = chop ? 45.67834.p : 45.67834; |
| + double c = chop ? 0.0004.p : 0.0004; |
| + double x = (a + b) + c; // Chop result of multiplication or division only. |
| + double y = a + (b + c); |
| + print("x: $x"); |
| + print("y: $y"); |
| + return x == y; |
| +} |
| + |
| +bool TestDistributivity(bool chop) { |
| + // Example from https://en.wikipedia.org/wiki/Floating_point |
| + // Test that (a + b)*c == a*c + b*c. |
| + double a = chop ? 1234.567.p : 1234.567; // Chop literals. |
| + double b = chop ? 1.234567.p : 1.234567; |
| + double c = chop ? 3.333333.p : 3.333333; |
| + double x = chop ? ((a + b)*c).p : (a + b)*c; // Chop result of multiplication. |
| + double y = (chop ? (a*c).p : (a*c)) + (chop ? (b*c).p : (b*c)); |
| + print("x: $x"); |
| + print("y: $y"); |
| + return x == y; |
| +} |
| + |
| +main() { |
| + print("without chopping fractional bits:"); |
| + Expect.isFalse(TestAssociativity(false)); |
|
Florian Schneider
2016/08/03 23:35:58
e.g. Expect.isFalse(TestAssociativity((x) => x));
regis
2016/08/04 18:22:31
Done.
|
| + Expect.isFalse(TestDistributivity(false)); |
| + print("with chopping fractional bits:"); |
| + Expect.isTrue(TestAssociativity(true)); |
|
Florian Schneider
2016/08/03 23:35:58
e.g. Expect.isTrue(TestAssociativity((x) => x.p));
regis
2016/08/04 18:22:31
Done.
|
| + Expect.isTrue(TestDistributivity(true)); |
| +} |