OLD | NEW |
| (Empty) |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | |
2 | |
3 #include <stdlib.h> | |
4 | |
5 #include "v8.h" | |
6 | |
7 #include "platform.h" | |
8 #include "cctest.h" | |
9 #include "diy_fp.h" | |
10 | |
11 using namespace v8::internal; | |
12 | |
13 | |
14 TEST(Subtract) { | |
15 DiyFp diy_fp1 = DiyFp(3, 0); | |
16 DiyFp diy_fp2 = DiyFp(1, 0); | |
17 DiyFp diff = DiyFp::Minus(diy_fp1, diy_fp2); | |
18 | |
19 CHECK(2 == diff.f()); | |
20 CHECK_EQ(0, diff.e()); | |
21 diy_fp1.Subtract(diy_fp2); | |
22 CHECK(2 == diy_fp1.f()); | |
23 CHECK_EQ(0, diy_fp1.e()); | |
24 } | |
25 | |
26 | |
27 TEST(Multiply) { | |
28 DiyFp diy_fp1 = DiyFp(3, 0); | |
29 DiyFp diy_fp2 = DiyFp(2, 0); | |
30 DiyFp product = DiyFp::Times(diy_fp1, diy_fp2); | |
31 | |
32 CHECK(0 == product.f()); | |
33 CHECK_EQ(64, product.e()); | |
34 diy_fp1.Multiply(diy_fp2); | |
35 CHECK(0 == diy_fp1.f()); | |
36 CHECK_EQ(64, diy_fp1.e()); | |
37 | |
38 diy_fp1 = DiyFp(V8_2PART_UINT64_C(0x80000000, 00000000), 11); | |
39 diy_fp2 = DiyFp(2, 13); | |
40 product = DiyFp::Times(diy_fp1, diy_fp2); | |
41 CHECK(1 == product.f()); | |
42 CHECK_EQ(11 + 13 + 64, product.e()); | |
43 | |
44 // Test rounding. | |
45 diy_fp1 = DiyFp(V8_2PART_UINT64_C(0x80000000, 00000001), 11); | |
46 diy_fp2 = DiyFp(1, 13); | |
47 product = DiyFp::Times(diy_fp1, diy_fp2); | |
48 CHECK(1 == product.f()); | |
49 CHECK_EQ(11 + 13 + 64, product.e()); | |
50 | |
51 diy_fp1 = DiyFp(V8_2PART_UINT64_C(0x7fffffff, ffffffff), 11); | |
52 diy_fp2 = DiyFp(1, 13); | |
53 product = DiyFp::Times(diy_fp1, diy_fp2); | |
54 CHECK(0 == product.f()); | |
55 CHECK_EQ(11 + 13 + 64, product.e()); | |
56 | |
57 // Halfway cases are allowed to round either way. So don't check for it. | |
58 | |
59 // Big numbers. | |
60 diy_fp1 = DiyFp(V8_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF), 11); | |
61 diy_fp2 = DiyFp(V8_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFF), 13); | |
62 // 128bit result: 0xfffffffffffffffe0000000000000001 | |
63 product = DiyFp::Times(diy_fp1, diy_fp2); | |
64 CHECK(V8_2PART_UINT64_C(0xFFFFFFFF, FFFFFFFe) == product.f()); | |
65 CHECK_EQ(11 + 13 + 64, product.e()); | |
66 } | |
OLD | NEW |