Chromium Code Reviews| 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 | 4 |
| 5 #include "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/bigint_operations.h" | 6 #include "vm/bigint_operations.h" |
| 7 #include "vm/object.h" | 7 #include "vm/object.h" |
| 8 #include "vm/object_store.h" | 8 #include "vm/object_store.h" |
| 9 #include "vm/unit_test.h" | 9 #include "vm/unit_test.h" |
| 10 | 10 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 "12345678901234567890123456789012345678901234567890" | 157 "12345678901234567890123456789012345678901234567890" |
| 158 "12345678901234567890123456789012345678901234567890" | 158 "12345678901234567890123456789012345678901234567890" |
| 159 "12345678901234567890123456789012345678901234567890" | 159 "12345678901234567890123456789012345678901234567890" |
| 160 "12345678901234567890123456789012345678901234567890" | 160 "12345678901234567890123456789012345678901234567890" |
| 161 "12345678901234567890123456789012345678901234567890" | 161 "12345678901234567890123456789012345678901234567890" |
| 162 "12345678901234567890123456789012345678901234567890" | 162 "12345678901234567890123456789012345678901234567890" |
| 163 "12345678901234567890123456789012345678901234567890"); | 163 "12345678901234567890123456789012345678901234567890"); |
| 164 dbl = BigintOperations::ToDouble(bigint); | 164 dbl = BigintOperations::ToDouble(bigint); |
| 165 EXPECT_EQ(1.0/zero, dbl.value()); | 165 EXPECT_EQ(1.0/zero, dbl.value()); |
| 166 | 166 |
| 167 bigint = BigintOperations::NewFromCString( | |
|
cshapiro
2012/03/07 21:49:18
test mint range values too?
floitsch
2012/03/20 04:06:48
Done.
| |
| 168 "17976931348623157081452742373170435679807056752584" | |
| 169 "49965989174768031572607800285387605895586327668781" | |
| 170 "71540458953514382464234321326889464182768467546703" | |
| 171 "53751698604991057655128207624549009038932894407586" | |
| 172 "85084551339423045832369032229481658085593321233482" | |
| 173 "74797826204144723168738177180919299881250404026184" | |
| 174 "124858368"); | |
| 175 dbl = BigintOperations::ToDouble(bigint); | |
| 176 EXPECT_EQ(1.7976931348623157e308, dbl.value()); | |
| 177 | |
| 178 bigint = BigintOperations::NewFromCString( | |
| 179 "17976931348623159077293051907890247336179769789423" | |
| 180 "06572734300811577326758055009631327084773224075360" | |
| 181 "21120113879871393357658789768814416622492847430639" | |
| 182 "47412437776789342486548527630221960124609411945308" | |
| 183 "29520850057688381506823424628814739131105408272371" | |
| 184 "63350510684586298239947245938479716304835356329624" | |
| 185 "224137216"); | |
| 186 dbl = BigintOperations::ToDouble(bigint); | |
| 187 EXPECT_EQ(1.0/zero, dbl.value()); | |
| 188 | |
| 189 bigint = BigintOperations::NewFromCString( | |
| 190 "17976931348623158079372897140530341507993413271003" | |
| 191 "78269361737789804449682927647509466490179775872070" | |
| 192 "96330286416692887910946555547851940402630657488671" | |
| 193 "50582068190890200070838367627385484581771153176447" | |
| 194 "57302700698555713669596228429148198608349364752927" | |
| 195 "19074168444365510704342711559699508093042880177904" | |
| 196 "174497792"); | |
| 197 dbl = BigintOperations::ToDouble(bigint); | |
| 198 EXPECT_EQ(1.0/zero, dbl.value()); | |
| 199 | |
| 200 bigint = BigintOperations::NewFromCString( | |
| 201 "17976931348623158079372897140530341507993413271003" | |
| 202 "78269361737789804449682927647509466490179775872070" | |
| 203 "96330286416692887910946555547851940402630657488671" | |
| 204 "50582068190890200070838367627385484581771153176447" | |
| 205 "57302700698555713669596228429148198608349364752927" | |
| 206 "19074168444365510704342711559699508093042880177904" | |
| 207 "174497791"); | |
| 208 dbl = BigintOperations::ToDouble(bigint); | |
| 209 EXPECT_EQ(1.7976931348623157e308, dbl.value()); | |
| 210 | |
| 167 bigint = BigintOperations::NewFromCString("100000000000000000000000"); | 211 bigint = BigintOperations::NewFromCString("100000000000000000000000"); |
| 168 dbl = BigintOperations::ToDouble(bigint); | 212 dbl = BigintOperations::ToDouble(bigint); |
| 169 EXPECT_EQ(1e+23, dbl.value()); | 213 EXPECT_EQ(1e+23, dbl.value()); |
| 170 | 214 |
| 171 // TODO(floitsch): Proper rounding if deemed necessary. | |
| 172 #if 0 | |
| 173 bigint = BigintOperations::NewFromCString("100000000000000000000001"); | 215 bigint = BigintOperations::NewFromCString("100000000000000000000001"); |
| 174 dbl = BigintOperations::ToDouble(bigint); | 216 dbl = BigintOperations::ToDouble(bigint); |
| 175 // EXPECT_EQ(1.0000000000000001e+23, dbl.value()); | 217 EXPECT_EQ(1.0000000000000001e+23, dbl.value()); |
| 176 EXPECT_EQ(9.9999999999999992e+22, dbl.value()); | |
| 177 #endif | |
| 178 | 218 |
| 179 // Same but shifted 64 bits to the left. | 219 // Same but shifted 64 bits to the left. |
| 180 bigint = BigintOperations::NewFromCString( | 220 bigint = BigintOperations::NewFromCString( |
| 181 "1844674407370955161600000000000000000000000"); | 221 "1844674407370955161600000000000000000000000"); |
| 182 dbl = BigintOperations::ToDouble(bigint); | 222 dbl = BigintOperations::ToDouble(bigint); |
| 183 EXPECT_EQ(1.844674407370955e+42, dbl.value()); | 223 EXPECT_EQ(1.844674407370955e+42, dbl.value()); |
| 184 | 224 |
| 185 bigint = BigintOperations::NewFromCString( | 225 bigint = BigintOperations::NewFromCString( |
| 186 "1844674407370955161600000000000000000000001"); | 226 "1844674407370955161600000000000000000000001"); |
| 187 dbl = BigintOperations::ToDouble(bigint); | 227 dbl = BigintOperations::ToDouble(bigint); |
| 188 // TODO(floitsch): Proper rounding if deemed necessary. | 228 EXPECT_EQ(1.8446744073709553e+42, dbl.value()); |
| 189 // EXPECT_EQ(1.8446744073709553e+42, dbl.value()); | |
| 190 EXPECT_EQ(1.844674407370955e+42, dbl.value()); | |
| 191 } | 229 } |
| 192 | 230 |
| 193 | 231 |
| 194 TEST_CASE(BigintHexStrings) { | 232 TEST_CASE(BigintHexStrings) { |
| 195 { | 233 { |
| 196 const Bigint& bigint = Bigint::Handle( | 234 const Bigint& bigint = Bigint::Handle( |
| 197 BigintOperations::NewFromCString("0x0")); | 235 BigintOperations::NewFromCString("0x0")); |
| 198 EXPECT(BigintOperations::FitsIntoSmi(bigint)); | 236 EXPECT(BigintOperations::FitsIntoSmi(bigint)); |
| 199 const Smi& smi = Smi::Handle(BigintOperations::ToSmi(bigint)); | 237 const Smi& smi = Smi::Handle(BigintOperations::ToSmi(bigint)); |
| 200 EXPECT_EQ(0, smi.Value()); | 238 EXPECT_EQ(0, smi.Value()); |
| (...skipping 1892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2093 "123456789012345678901234567890123456789012345678901234567890123456789012" | 2131 "123456789012345678901234567890123456789012345678901234567890123456789012" |
| 2094 "345678901234567890123456789012345678901234567890123456789012345678901234" | 2132 "345678901234567890123456789012345678901234567890123456789012345678901234" |
| 2095 "567890123456789012345678901234567890123456789012345678901234567890123456" | 2133 "567890123456789012345678901234567890123456789012345678901234567890123456" |
| 2096 "789012345678901234567890123456789012345678901234567890123456789012345678" | 2134 "789012345678901234567890123456789012345678901234567890123456789012345678" |
| 2097 "90123456789012345678901234567890", | 2135 "90123456789012345678901234567890", |
| 2098 "0x1234567890ABCDEF01234567890ABCDEF01234567890ABCDEF01234567890ABCDEF" | 2136 "0x1234567890ABCDEF01234567890ABCDEF01234567890ABCDEF01234567890ABCDEF" |
| 2099 "01234567890ABCDEE"); | 2137 "01234567890ABCDEE"); |
| 2100 } | 2138 } |
| 2101 | 2139 |
| 2102 } // namespace dart | 2140 } // namespace dart |
| OLD | NEW |