Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Unified Diff: runtime/vm/bigint_operations_test.cc

Issue 9540015: Implement correct bigint to double conversion. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« runtime/vm/bigint_operations.cc ('K') | « runtime/vm/bigint_operations.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/bigint_operations_test.cc
diff --git a/runtime/vm/bigint_operations_test.cc b/runtime/vm/bigint_operations_test.cc
index 9c499dac147a44d690b74d16d5426cb58642a714..3c92ab18b783c3dd6ab21345294b6bf8481a6187 100644
--- a/runtime/vm/bigint_operations_test.cc
+++ b/runtime/vm/bigint_operations_test.cc
@@ -164,17 +164,57 @@ TEST_CASE(BigintDouble) {
dbl = BigintOperations::ToDouble(bigint);
EXPECT_EQ(1.0/zero, dbl.value());
+ bigint = BigintOperations::NewFromCString(
cshapiro 2012/03/07 21:49:18 test mint range values too?
floitsch 2012/03/20 04:06:48 Done.
+ "17976931348623157081452742373170435679807056752584"
+ "49965989174768031572607800285387605895586327668781"
+ "71540458953514382464234321326889464182768467546703"
+ "53751698604991057655128207624549009038932894407586"
+ "85084551339423045832369032229481658085593321233482"
+ "74797826204144723168738177180919299881250404026184"
+ "124858368");
+ dbl = BigintOperations::ToDouble(bigint);
+ EXPECT_EQ(1.7976931348623157e308, dbl.value());
+
+ bigint = BigintOperations::NewFromCString(
+ "17976931348623159077293051907890247336179769789423"
+ "06572734300811577326758055009631327084773224075360"
+ "21120113879871393357658789768814416622492847430639"
+ "47412437776789342486548527630221960124609411945308"
+ "29520850057688381506823424628814739131105408272371"
+ "63350510684586298239947245938479716304835356329624"
+ "224137216");
+ dbl = BigintOperations::ToDouble(bigint);
+ EXPECT_EQ(1.0/zero, dbl.value());
+
+ bigint = BigintOperations::NewFromCString(
+ "17976931348623158079372897140530341507993413271003"
+ "78269361737789804449682927647509466490179775872070"
+ "96330286416692887910946555547851940402630657488671"
+ "50582068190890200070838367627385484581771153176447"
+ "57302700698555713669596228429148198608349364752927"
+ "19074168444365510704342711559699508093042880177904"
+ "174497792");
+ dbl = BigintOperations::ToDouble(bigint);
+ EXPECT_EQ(1.0/zero, dbl.value());
+
+ bigint = BigintOperations::NewFromCString(
+ "17976931348623158079372897140530341507993413271003"
+ "78269361737789804449682927647509466490179775872070"
+ "96330286416692887910946555547851940402630657488671"
+ "50582068190890200070838367627385484581771153176447"
+ "57302700698555713669596228429148198608349364752927"
+ "19074168444365510704342711559699508093042880177904"
+ "174497791");
+ dbl = BigintOperations::ToDouble(bigint);
+ EXPECT_EQ(1.7976931348623157e308, dbl.value());
+
bigint = BigintOperations::NewFromCString("100000000000000000000000");
dbl = BigintOperations::ToDouble(bigint);
EXPECT_EQ(1e+23, dbl.value());
- // TODO(floitsch): Proper rounding if deemed necessary.
-#if 0
bigint = BigintOperations::NewFromCString("100000000000000000000001");
dbl = BigintOperations::ToDouble(bigint);
- // EXPECT_EQ(1.0000000000000001e+23, dbl.value());
- EXPECT_EQ(9.9999999999999992e+22, dbl.value());
-#endif
+ EXPECT_EQ(1.0000000000000001e+23, dbl.value());
// Same but shifted 64 bits to the left.
bigint = BigintOperations::NewFromCString(
@@ -185,9 +225,7 @@ TEST_CASE(BigintDouble) {
bigint = BigintOperations::NewFromCString(
"1844674407370955161600000000000000000000001");
dbl = BigintOperations::ToDouble(bigint);
- // TODO(floitsch): Proper rounding if deemed necessary.
- // EXPECT_EQ(1.8446744073709553e+42, dbl.value());
- EXPECT_EQ(1.844674407370955e+42, dbl.value());
+ EXPECT_EQ(1.8446744073709553e+42, dbl.value());
}
« runtime/vm/bigint_operations.cc ('K') | « runtime/vm/bigint_operations.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698