| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 | 2 |
| 3 #include <stdlib.h> | 3 #include <stdlib.h> |
| 4 | 4 |
| 5 #include "v8.h" | 5 #include "v8.h" |
| 6 | 6 |
| 7 #include "platform.h" | 7 #include "platform.h" |
| 8 #include "cctest.h" | 8 #include "cctest.h" |
| 9 #include "diy_fp.h" | 9 #include "diy_fp.h" |
| 10 #include "double.h" | 10 #include "double.h" |
| 11 | 11 |
| 12 |
| 12 using namespace v8::internal; | 13 using namespace v8::internal; |
| 13 | 14 |
| 14 | 15 |
| 15 TEST(Uint64Conversions) { | 16 TEST(Uint64Conversions) { |
| 16 // Start by checking the byte-order. | 17 // Start by checking the byte-order. |
| 17 uint64_t ordered = V8_2PART_UINT64_C(0x01234567, 89ABCDEF); | 18 uint64_t ordered = V8_2PART_UINT64_C(0x01234567, 89ABCDEF); |
| 18 CHECK_EQ(3512700564088504e-318, Double(ordered).value()); | 19 CHECK_EQ(3512700564088504e-318, Double(ordered).value()); |
| 19 | 20 |
| 20 uint64_t min_double64 = V8_2PART_UINT64_C(0x00000000, 00000001); | 21 uint64_t min_double64 = V8_2PART_UINT64_C(0x00000000, 00000001); |
| 21 CHECK_EQ(5e-324, Double(min_double64).value()); | 22 CHECK_EQ(5e-324, Double(min_double64).value()); |
| 22 | 23 |
| 23 uint64_t max_double64 = V8_2PART_UINT64_C(0x7fefffff, ffffffff); | 24 uint64_t max_double64 = V8_2PART_UINT64_C(0x7fefffff, ffffffff); |
| 24 CHECK_EQ(1.7976931348623157e308, Double(max_double64).value()); | 25 CHECK_EQ(1.7976931348623157e308, Double(max_double64).value()); |
| 25 } | 26 } |
| 26 | 27 |
| 27 TEST(AsDiyFp) { | 28 TEST(AsDiyFp) { |
| 28 uint64_t ordered = V8_2PART_UINT64_C(0x01234567, 89ABCDEF); | 29 uint64_t ordered = V8_2PART_UINT64_C(0x01234567, 89ABCDEF); |
| 29 DiyFp diy_fp = Double(ordered).AsDiyFp(); | 30 DiyFp diy_fp = Double(ordered).AsDiyFp(); |
| 30 CHECK_EQ(0x12 - 0x3FF - 52, diy_fp.e()); | 31 CHECK_EQ(0x12 - 0x3FF - 52, diy_fp.e()); |
| 31 // The 52 mantissa bits, plus the implicit 1 in bit 52 as a UINT64. | 32 // The 52 mantissa bits, plus the implicit 1 in bit 52 as a UINT64. |
| 32 CHECK(V8_2PART_UINT64_C(0x00134567, 89ABCDEF) == diy_fp.f()); | 33 CHECK(V8_2PART_UINT64_C(0x00134567, 89ABCDEF) == diy_fp.f()); // NOLINT |
| 33 | 34 |
| 34 uint64_t min_double64 = V8_2PART_UINT64_C(0x00000000, 00000001); | 35 uint64_t min_double64 = V8_2PART_UINT64_C(0x00000000, 00000001); |
| 35 diy_fp = Double(min_double64).AsDiyFp(); | 36 diy_fp = Double(min_double64).AsDiyFp(); |
| 36 CHECK_EQ(-0x3FF - 52 + 1, diy_fp.e()); | 37 CHECK_EQ(-0x3FF - 52 + 1, diy_fp.e()); |
| 37 // This is a denormal; so no hidden bit. | 38 // This is a denormal; so no hidden bit. |
| 38 CHECK(1 == diy_fp.f()); | 39 CHECK(1 == diy_fp.f()); // NOLINT |
| 39 | 40 |
| 40 uint64_t max_double64 = V8_2PART_UINT64_C(0x7fefffff, ffffffff); | 41 uint64_t max_double64 = V8_2PART_UINT64_C(0x7fefffff, ffffffff); |
| 41 diy_fp = Double(max_double64).AsDiyFp(); | 42 diy_fp = Double(max_double64).AsDiyFp(); |
| 42 CHECK_EQ(0x7FE - 0x3FF - 52, diy_fp.e()); | 43 CHECK_EQ(0x7FE - 0x3FF - 52, diy_fp.e()); |
| 43 CHECK(V8_2PART_UINT64_C(0x001fffff, ffffffff) == diy_fp.f()); | 44 CHECK(V8_2PART_UINT64_C(0x001fffff, ffffffff) == diy_fp.f()); // NOLINT |
| 44 } | 45 } |
| 45 | 46 |
| 46 | 47 |
| 47 TEST(AsNormalizedDiyFp) { | 48 TEST(AsNormalizedDiyFp) { |
| 48 uint64_t ordered = V8_2PART_UINT64_C(0x01234567, 89ABCDEF); | 49 uint64_t ordered = V8_2PART_UINT64_C(0x01234567, 89ABCDEF); |
| 49 DiyFp diy_fp = Double(ordered).AsNormalizedDiyFp(); | 50 DiyFp diy_fp = Double(ordered).AsNormalizedDiyFp(); |
| 50 CHECK_EQ(0x12 - 0x3FF - 52 - 11, diy_fp.e()); | 51 CHECK_EQ(0x12 - 0x3FF - 52 - 11, diy_fp.e()); |
| 51 CHECK((V8_2PART_UINT64_C(0x00134567, 89ABCDEF) << 11) == diy_fp.f()); | 52 CHECK((V8_2PART_UINT64_C(0x00134567, 89ABCDEF) << 11) == |
| 53 diy_fp.f()); // NOLINT |
| 52 | 54 |
| 53 uint64_t min_double64 = V8_2PART_UINT64_C(0x00000000, 00000001); | 55 uint64_t min_double64 = V8_2PART_UINT64_C(0x00000000, 00000001); |
| 54 diy_fp = Double(min_double64).AsNormalizedDiyFp(); | 56 diy_fp = Double(min_double64).AsNormalizedDiyFp(); |
| 55 CHECK_EQ(-0x3FF - 52 + 1 - 63, diy_fp.e()); | 57 CHECK_EQ(-0x3FF - 52 + 1 - 63, diy_fp.e()); |
| 56 // This is a denormal; so no hidden bit. | 58 // This is a denormal; so no hidden bit. |
| 57 CHECK(V8_2PART_UINT64_C(0x80000000, 00000000) == diy_fp.f()); | 59 CHECK(V8_2PART_UINT64_C(0x80000000, 00000000) == diy_fp.f()); // NOLINT |
| 58 | 60 |
| 59 uint64_t max_double64 = V8_2PART_UINT64_C(0x7fefffff, ffffffff); | 61 uint64_t max_double64 = V8_2PART_UINT64_C(0x7fefffff, ffffffff); |
| 60 diy_fp = Double(max_double64).AsNormalizedDiyFp(); | 62 diy_fp = Double(max_double64).AsNormalizedDiyFp(); |
| 61 CHECK_EQ(0x7FE - 0x3FF - 52 - 11, diy_fp.e()); | 63 CHECK_EQ(0x7FE - 0x3FF - 52 - 11, diy_fp.e()); |
| 62 CHECK((V8_2PART_UINT64_C(0x001fffff, ffffffff) << 11) == diy_fp.f()); | 64 CHECK((V8_2PART_UINT64_C(0x001fffff, ffffffff) << 11) == |
| 65 diy_fp.f()); // NOLINT |
| 63 } | 66 } |
| 64 | 67 |
| 65 | 68 |
| 66 TEST(IsDenormal) { | 69 TEST(IsDenormal) { |
| 67 uint64_t min_double64 = V8_2PART_UINT64_C(0x00000000, 00000001); | 70 uint64_t min_double64 = V8_2PART_UINT64_C(0x00000000, 00000001); |
| 68 CHECK(Double(min_double64).IsDenormal()); | 71 CHECK(Double(min_double64).IsDenormal()); |
| 69 uint64_t bits = V8_2PART_UINT64_C(0x000FFFFF, FFFFFFFF); | 72 uint64_t bits = V8_2PART_UINT64_C(0x000FFFFF, FFFFFFFF); |
| 70 CHECK(Double(bits).IsDenormal()); | 73 CHECK(Double(bits).IsDenormal()); |
| 71 bits = V8_2PART_UINT64_C(0x00100000, 00000000); | 74 bits = V8_2PART_UINT64_C(0x00100000, 00000000); |
| 72 CHECK(!Double(bits).IsDenormal()); | 75 CHECK(!Double(bits).IsDenormal()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 TEST(NormalizedBoundaries) { | 141 TEST(NormalizedBoundaries) { |
| 139 DiyFp boundary_plus; | 142 DiyFp boundary_plus; |
| 140 DiyFp boundary_minus; | 143 DiyFp boundary_minus; |
| 141 DiyFp diy_fp = Double(1.5).AsNormalizedDiyFp(); | 144 DiyFp diy_fp = Double(1.5).AsNormalizedDiyFp(); |
| 142 Double(1.5).NormalizedBoundaries(&boundary_minus, &boundary_plus); | 145 Double(1.5).NormalizedBoundaries(&boundary_minus, &boundary_plus); |
| 143 CHECK_EQ(diy_fp.e(), boundary_minus.e()); | 146 CHECK_EQ(diy_fp.e(), boundary_minus.e()); |
| 144 CHECK_EQ(diy_fp.e(), boundary_plus.e()); | 147 CHECK_EQ(diy_fp.e(), boundary_plus.e()); |
| 145 // 1.5 does not have a significand of the form 2^p (for some p). | 148 // 1.5 does not have a significand of the form 2^p (for some p). |
| 146 // Therefore its boundaries are at the same distance. | 149 // Therefore its boundaries are at the same distance. |
| 147 CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f()); | 150 CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f()); |
| 148 CHECK((1 << 10) == diy_fp.f() - boundary_minus.f()); | 151 CHECK((1 << 10) == diy_fp.f() - boundary_minus.f()); // NOLINT |
| 149 | 152 |
| 150 diy_fp = Double(1.0).AsNormalizedDiyFp(); | 153 diy_fp = Double(1.0).AsNormalizedDiyFp(); |
| 151 Double(1.0).NormalizedBoundaries(&boundary_minus, &boundary_plus); | 154 Double(1.0).NormalizedBoundaries(&boundary_minus, &boundary_plus); |
| 152 CHECK_EQ(diy_fp.e(), boundary_minus.e()); | 155 CHECK_EQ(diy_fp.e(), boundary_minus.e()); |
| 153 CHECK_EQ(diy_fp.e(), boundary_plus.e()); | 156 CHECK_EQ(diy_fp.e(), boundary_plus.e()); |
| 154 // 1.0 does have a significand of the form 2^p (for some p). | 157 // 1.0 does have a significand of the form 2^p (for some p). |
| 155 // Therefore its lower boundary is twice as close as the upper boundary. | 158 // Therefore its lower boundary is twice as close as the upper boundary. |
| 156 CHECK_GT(boundary_plus.f() - diy_fp.f(), diy_fp.f() - boundary_minus.f()); | 159 CHECK_GT(boundary_plus.f() - diy_fp.f(), diy_fp.f() - boundary_minus.f()); |
| 157 CHECK((1 << 9) == diy_fp.f() - boundary_minus.f()); | 160 CHECK((1 << 9) == diy_fp.f() - boundary_minus.f()); // NOLINT |
| 158 CHECK((1 << 10) == boundary_plus.f() - diy_fp.f()); | 161 CHECK((1 << 10) == boundary_plus.f() - diy_fp.f()); // NOLINT |
| 159 | 162 |
| 160 uint64_t min_double64 = V8_2PART_UINT64_C(0x00000000, 00000001); | 163 uint64_t min_double64 = V8_2PART_UINT64_C(0x00000000, 00000001); |
| 161 diy_fp = Double(min_double64).AsNormalizedDiyFp(); | 164 diy_fp = Double(min_double64).AsNormalizedDiyFp(); |
| 162 Double(min_double64).NormalizedBoundaries(&boundary_minus, &boundary_plus); | 165 Double(min_double64).NormalizedBoundaries(&boundary_minus, &boundary_plus); |
| 163 CHECK_EQ(diy_fp.e(), boundary_minus.e()); | 166 CHECK_EQ(diy_fp.e(), boundary_minus.e()); |
| 164 CHECK_EQ(diy_fp.e(), boundary_plus.e()); | 167 CHECK_EQ(diy_fp.e(), boundary_plus.e()); |
| 165 // min-value does not have a significand of the form 2^p (for some p). | 168 // min-value does not have a significand of the form 2^p (for some p). |
| 166 // Therefore its boundaries are at the same distance. | 169 // Therefore its boundaries are at the same distance. |
| 167 CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f()); | 170 CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f()); |
| 168 // Denormals have their boundaries much closer. | 171 // Denormals have their boundaries much closer. |
| 169 CHECK((static_cast<uint64_t>(1) << 62) == diy_fp.f() - boundary_minus.f()); | 172 CHECK((static_cast<uint64_t>(1) << 62) == |
| 173 diy_fp.f() - boundary_minus.f()); // NOLINT |
| 170 | 174 |
| 171 uint64_t smallest_normal64 = V8_2PART_UINT64_C(0x00100000, 00000000); | 175 uint64_t smallest_normal64 = V8_2PART_UINT64_C(0x00100000, 00000000); |
| 172 diy_fp = Double(smallest_normal64).AsNormalizedDiyFp(); | 176 diy_fp = Double(smallest_normal64).AsNormalizedDiyFp(); |
| 173 Double(smallest_normal64).NormalizedBoundaries(&boundary_minus, | 177 Double(smallest_normal64).NormalizedBoundaries(&boundary_minus, |
| 174 &boundary_plus); | 178 &boundary_plus); |
| 175 CHECK_EQ(diy_fp.e(), boundary_minus.e()); | 179 CHECK_EQ(diy_fp.e(), boundary_minus.e()); |
| 176 CHECK_EQ(diy_fp.e(), boundary_plus.e()); | 180 CHECK_EQ(diy_fp.e(), boundary_plus.e()); |
| 177 // Even though the significand is of the form 2^p (for some p), its boundaries | 181 // Even though the significand is of the form 2^p (for some p), its boundaries |
| 178 // are at the same distance. (This is the only exception). | 182 // are at the same distance. (This is the only exception). |
| 179 CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f()); | 183 CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f()); |
| 180 CHECK((1 << 10) == diy_fp.f() - boundary_minus.f()); | 184 CHECK((1 << 10) == diy_fp.f() - boundary_minus.f()); // NOLINT |
| 181 | 185 |
| 182 uint64_t largest_denormal64 = V8_2PART_UINT64_C(0x000FFFFF, FFFFFFFF); | 186 uint64_t largest_denormal64 = V8_2PART_UINT64_C(0x000FFFFF, FFFFFFFF); |
| 183 diy_fp = Double(largest_denormal64).AsNormalizedDiyFp(); | 187 diy_fp = Double(largest_denormal64).AsNormalizedDiyFp(); |
| 184 Double(largest_denormal64).NormalizedBoundaries(&boundary_minus, | 188 Double(largest_denormal64).NormalizedBoundaries(&boundary_minus, |
| 185 &boundary_plus); | 189 &boundary_plus); |
| 186 CHECK_EQ(diy_fp.e(), boundary_minus.e()); | 190 CHECK_EQ(diy_fp.e(), boundary_minus.e()); |
| 187 CHECK_EQ(diy_fp.e(), boundary_plus.e()); | 191 CHECK_EQ(diy_fp.e(), boundary_plus.e()); |
| 188 CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f()); | 192 CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f()); |
| 189 CHECK((1 << 11) == diy_fp.f() - boundary_minus.f()); | 193 CHECK((1 << 11) == diy_fp.f() - boundary_minus.f()); // NOLINT |
| 190 | 194 |
| 191 uint64_t max_double64 = V8_2PART_UINT64_C(0x7fefffff, ffffffff); | 195 uint64_t max_double64 = V8_2PART_UINT64_C(0x7fefffff, ffffffff); |
| 192 diy_fp = Double(max_double64).AsNormalizedDiyFp(); | 196 diy_fp = Double(max_double64).AsNormalizedDiyFp(); |
| 193 Double(max_double64).NormalizedBoundaries(&boundary_minus, &boundary_plus); | 197 Double(max_double64).NormalizedBoundaries(&boundary_minus, &boundary_plus); |
| 194 CHECK_EQ(diy_fp.e(), boundary_minus.e()); | 198 CHECK_EQ(diy_fp.e(), boundary_minus.e()); |
| 195 CHECK_EQ(diy_fp.e(), boundary_plus.e()); | 199 CHECK_EQ(diy_fp.e(), boundary_plus.e()); |
| 196 // max-value does not have a significand of the form 2^p (for some p). | 200 // max-value does not have a significand of the form 2^p (for some p). |
| 197 // Therefore its boundaries are at the same distance. | 201 // Therefore its boundaries are at the same distance. |
| 198 CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f()); | 202 CHECK(diy_fp.f() - boundary_minus.f() == boundary_plus.f() - diy_fp.f()); |
| 199 CHECK((1 << 10) == diy_fp.f() - boundary_minus.f()); | 203 CHECK((1 << 10) == diy_fp.f() - boundary_minus.f()); // NOLINT |
| 200 } | 204 } |
| OLD | NEW |