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

Side by Side Diff: Source/wtf/dtoa/cached-powers.cc

Issue 20652002: Fix trailing whitespace in scripts and misc. files (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Don't change literal diff. Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/wtf/dtoa/bignum-dtoa.cc ('k') | Source/wtf/dtoa/diy-fp.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 20 matching lines...) Expand all
31 #include <limits.h> 31 #include <limits.h>
32 #include <math.h> 32 #include <math.h>
33 33
34 #include "cached-powers.h" 34 #include "cached-powers.h"
35 #include "utils.h" 35 #include "utils.h"
36 #include "wtf/UnusedParam.h" 36 #include "wtf/UnusedParam.h"
37 37
38 namespace WTF { 38 namespace WTF {
39 39
40 namespace double_conversion { 40 namespace double_conversion {
41 41
42 struct CachedPower { 42 struct CachedPower {
43 uint64_t significand; 43 uint64_t significand;
44 int16_t binary_exponent; 44 int16_t binary_exponent;
45 int16_t decimal_exponent; 45 int16_t decimal_exponent;
46 }; 46 };
47 47
48 static int kCachedPowersLength = 1; 48 static int kCachedPowersLength = 1;
49 static int kCachedPowersOffset = 1; 49 static int kCachedPowersOffset = 1;
50 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10) 50 static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10)
51 static CachedPower* kCachedPowers = 0; 51 static CachedPower* kCachedPowers = 0;
52 52
53 int PowersOfTenCache::kDecimalExponentDistance = 1; 53 int PowersOfTenCache::kDecimalExponentDistance = 1;
54 int PowersOfTenCache::kMinDecimalExponent = 1; 54 int PowersOfTenCache::kMinDecimalExponent = 1;
55 int PowersOfTenCache::kMaxDecimalExponent = 1; 55 int PowersOfTenCache::kMaxDecimalExponent = 1;
56 56
57 void initialize() { 57 void initialize() {
58 if (kCachedPowers) 58 if (kCachedPowers)
59 return; 59 return;
60 static CachedPower cachedPowers[] = { 60 static CachedPower cachedPowers[] = {
61 {UINT64_2PART_C(0xfa8fd5a0, 081c0288), -1220, -348}, 61 {UINT64_2PART_C(0xfa8fd5a0, 081c0288), -1220, -348},
62 {UINT64_2PART_C(0xbaaee17f, a23ebf76), -1193, -340}, 62 {UINT64_2PART_C(0xbaaee17f, a23ebf76), -1193, -340},
63 {UINT64_2PART_C(0x8b16fb20, 3055ac76), -1166, -332}, 63 {UINT64_2PART_C(0x8b16fb20, 3055ac76), -1166, -332},
64 {UINT64_2PART_C(0xcf42894a, 5dce35ea), -1140, -324}, 64 {UINT64_2PART_C(0xcf42894a, 5dce35ea), -1140, -324},
65 {UINT64_2PART_C(0x9a6bb0aa, 55653b2d), -1113, -316}, 65 {UINT64_2PART_C(0x9a6bb0aa, 55653b2d), -1113, -316},
66 {UINT64_2PART_C(0xe61acf03, 3d1a45df), -1087, -308}, 66 {UINT64_2PART_C(0xe61acf03, 3d1a45df), -1087, -308},
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 {UINT64_2PART_C(0xeb96bf6e, badf77d9), 1039, 332}, 146 {UINT64_2PART_C(0xeb96bf6e, badf77d9), 1039, 332},
147 {UINT64_2PART_C(0xaf87023b, 9bf0ee6b), 1066, 340}, 147 {UINT64_2PART_C(0xaf87023b, 9bf0ee6b), 1066, 340},
148 }; 148 };
149 kCachedPowers = cachedPowers; 149 kCachedPowers = cachedPowers;
150 kCachedPowersLength = ARRAY_SIZE(cachedPowers); 150 kCachedPowersLength = ARRAY_SIZE(cachedPowers);
151 kCachedPowersOffset = -cachedPowers[0].decimal_exponent; 151 kCachedPowersOffset = -cachedPowers[0].decimal_exponent;
152 PowersOfTenCache::kDecimalExponentDistance = kCachedPowers[1].decimal_ex ponent - kCachedPowers[0].decimal_exponent; 152 PowersOfTenCache::kDecimalExponentDistance = kCachedPowers[1].decimal_ex ponent - kCachedPowers[0].decimal_exponent;
153 PowersOfTenCache::kMinDecimalExponent = kCachedPowers[0].decimal_exponen t; 153 PowersOfTenCache::kMinDecimalExponent = kCachedPowers[0].decimal_exponen t;
154 PowersOfTenCache::kMaxDecimalExponent = kCachedPowers[kCachedPowersLengt h - 1].decimal_exponent; 154 PowersOfTenCache::kMaxDecimalExponent = kCachedPowers[kCachedPowersLengt h - 1].decimal_exponent;
155 } 155 }
156 156
157 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange( 157 void PowersOfTenCache::GetCachedPowerForBinaryExponentRange(
158 int min_exponent , 158 int min_exponent ,
159 int max_exponent , 159 int max_exponent ,
160 DiyFp* power, 160 DiyFp* power,
161 int* decimal_exp onent) { 161 int* decimal_exp onent) {
162 UNUSED_PARAM(max_exponent); 162 UNUSED_PARAM(max_exponent);
163 int kQ = DiyFp::kSignificandSize; 163 int kQ = DiyFp::kSignificandSize;
164 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10); 164 double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10);
165 int foo = kCachedPowersOffset; 165 int foo = kCachedPowersOffset;
166 int index = 166 int index =
167 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1; 167 (foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1;
168 ASSERT(0 <= index && index < kCachedPowersLength); 168 ASSERT(0 <= index && index < kCachedPowersLength);
169 CachedPower cached_power = kCachedPowers[index]; 169 CachedPower cached_power = kCachedPowers[index];
170 ASSERT(min_exponent <= cached_power.binary_exponent); 170 ASSERT(min_exponent <= cached_power.binary_exponent);
171 ASSERT(cached_power.binary_exponent <= max_exponent); 171 ASSERT(cached_power.binary_exponent <= max_exponent);
172 *decimal_exponent = cached_power.decimal_exponent; 172 *decimal_exponent = cached_power.decimal_exponent;
173 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); 173 *power = DiyFp(cached_power.significand, cached_power.binary_exponent);
174 } 174 }
175 175
176 176
177 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_expone nt, 177 void PowersOfTenCache::GetCachedPowerForDecimalExponent(int requested_expone nt,
178 DiyFp* power, 178 DiyFp* power,
179 int* found_exponent) { 179 int* found_exponent) {
180 ASSERT(kMinDecimalExponent <= requested_exponent); 180 ASSERT(kMinDecimalExponent <= requested_exponent);
181 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistan ce); 181 ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistan ce);
182 int index = 182 int index =
183 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance; 183 (requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance;
184 CachedPower cached_power = kCachedPowers[index]; 184 CachedPower cached_power = kCachedPowers[index];
185 *power = DiyFp(cached_power.significand, cached_power.binary_exponent); 185 *power = DiyFp(cached_power.significand, cached_power.binary_exponent);
186 *found_exponent = cached_power.decimal_exponent; 186 *found_exponent = cached_power.decimal_exponent;
187 ASSERT(*found_exponent <= requested_exponent); 187 ASSERT(*found_exponent <= requested_exponent);
188 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance); 188 ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance);
189 } 189 }
190 190
191 } // namespace double_conversion 191 } // namespace double_conversion
192 192
193 } // namespace WTF 193 } // namespace WTF
OLDNEW
« no previous file with comments | « Source/wtf/dtoa/bignum-dtoa.cc ('k') | Source/wtf/dtoa/diy-fp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698