module Float::Printer::CachedPowers

Defined in:

float/printer/cached_powers.cr

Constant Summary

CACHED_EXP_STEP = 8

Not all powers of ten are cached. The decimal exponent of two neighboring cached numbers will differ by CACHED_EXP_STEP

CACHED_POWER_OFFSET = 348
D_1_LOG2_10 = 0.30102999566398114
MAX_CACHED_EXP = 340
MAX_TARGET_EXP = -32
MIN_CACHED_EXP = -348
MIN_TARGET_EXP = -60

The minimal and maximal target exponent define the range of w's binary exponent, where 'w' is the result of multiplying the input by a cached power of ten.

A different range might be chosen on a different platform, to optimize digit generation, but a smaller range requires more powers of ten to be cached.

Pow10Cache = {0, 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}
PowCache = [{18054884314459144840_u64, -1220_i16, -348_i16}, {13451937075301367670_u64, -1193_i16, -340_i16}, {10022474136428063862_u64, -1166_i16, -332_i16}, {14934650266808366570_u64, -1140_i16, -324_i16}, {11127181549972568877_u64, -1113_i16, -316_i16}, {16580792590934885855_u64, -1087_i16, -308_i16}, {12353653155963782858_u64, -1060_i16, -300_i16}, {18408377700990114895_u64, -1034_i16, -292_i16}, {13715310171984221708_u64, -1007_i16, -284_i16}, {10218702384817765436_u64, -980_i16, -276_i16}, {15227053142812498563_u64, -954_i16, -268_i16}, {11345038669416679861_u64, -927_i16, -260_i16}, {16905424996341287883_u64, -901_i16, -252_i16}, {12595523146049147757_u64, -874_i16, -244_i16}, {9384396036005875287_u64, -847_i16, -236_i16}, {13983839803942852151_u64, -821_i16, -228_i16}, {10418772551374772303_u64, -794_i16, -220_i16}, {15525180923007089351_u64, -768_i16, -212_i16}, {11567161174868858868_u64, -741_i16, -204_i16}, {17236413322193710309_u64, -715_i16, -196_i16}, {12842128665889583758_u64, -688_i16, -188_i16}, {9568131466127621947_u64, -661_i16, -180_i16}, {14257626930069360058_u64, -635_i16, -172_i16}, {10622759856335341974_u64, -608_i16, -164_i16}, {15829145694278690180_u64, -582_i16, -156_i16}, {11793632577567316726_u64, -555_i16, -148_i16}, {17573882009934360870_u64, -529_i16, -140_i16}, {13093562431584567480_u64, -502_i16, -132_i16}, {9755464219737475723_u64, -475_i16, -124_i16}, {14536774485912137811_u64, -449_i16, -116_i16}, {10830740992659433045_u64, -422_i16, -108_i16}, {16139061738043178685_u64, -396_i16, -100_i16}, {12024538023802026127_u64, -369_i16, -92_i16}, {17917957937422433684_u64, -343_i16, -84_i16}, {13349918974505688015_u64, -316_i16, -76_i16}, {9946464728195732843_u64, -289_i16, -68_i16}, {14821387422376473014_u64, -263_i16, -60_i16}, {11042794154864902060_u64, -236_i16, -52_i16}, {16455045573212060422_u64, -210_i16, -44_i16}, {12259964326927110867_u64, -183_i16, -36_i16}, {18268770466636286478_u64, -157_i16, -28_i16}, {13611294676837538539_u64, -130_i16, -20_i16}, {10141204801825835212_u64, -103_i16, -12_i16}, {15111572745182864684_u64, -77_i16, -4_i16}, {11258999068426240000_u64, -50_i16, 4_i16}, {16777216000000000000_u64, -24_i16, 12_i16}, {12500000000000000000_u64, 3_i16, 20_i16}, {9313225746154785156_u64, 30_i16, 28_i16}, {13877787807814456755_u64, 56_i16, 36_i16}, {10339757656912845936_u64, 83_i16, 44_i16}, {15407439555097886824_u64, 109_i16, 52_i16}, {11479437019748901445_u64, 136_i16, 60_i16}, {17105694144590052135_u64, 162_i16, 68_i16}, {12744735289059618216_u64, 189_i16, 76_i16}, {9495567745759798747_u64, 216_i16, 84_i16}, {14149498560666738074_u64, 242_i16, 92_i16}, {10542197943230523224_u64, 269_i16, 100_i16}, {15709099088952724970_u64, 295_i16, 108_i16}, {11704190886730495818_u64, 322_i16, 116_i16}, {17440603504673385349_u64, 348_i16, 124_i16}, {12994262207056124023_u64, 375_i16, 132_i16}, {9681479787123295682_u64, 402_i16, 140_i16}, {14426529090290212157_u64, 428_i16, 148_i16}, {10748601772107342003_u64, 455_i16, 156_i16}, {16016664761464807395_u64, 481_i16, 164_i16}, {11933345169920330789_u64, 508_i16, 172_i16}, {17782069995880619868_u64, 534_i16, 180_i16}, {13248674568444952270_u64, 561_i16, 188_i16}, {9871031767461413346_u64, 588_i16, 196_i16}, {14708983551653345445_u64, 614_i16, 204_i16}, {10959046745042015199_u64, 641_i16, 212_i16}, {16330252207878254650_u64, 667_i16, 220_i16}, {12166986024289022870_u64, 694_i16, 228_i16}, {18130221999122236476_u64, 720_i16, 236_i16}, {13508068024458167312_u64, 747_i16, 244_i16}, {10064294952495520794_u64, 774_i16, 252_i16}, {14996968138956309548_u64, 800_i16, 260_i16}, {11173611982879273257_u64, 827_i16, 268_i16}, {16649979327439178909_u64, 853_i16, 276_i16}, {12405201291620119593_u64, 880_i16, 284_i16}, {9242595204427927429_u64, 907_i16, 292_i16}, {13772540099066387757_u64, 933_i16, 300_i16}, {10261342003245940623_u64, 960_i16, 308_i16}, {15290591125556738113_u64, 986_i16, 316_i16}, {11392378155556871081_u64, 1013_i16, 324_i16}, {16975966327722178521_u64, 1039_i16, 332_i16}, {12648080533535911531_u64, 1066_i16, 340_i16}].map do |t| Power.new(t[0], t[1], t[2]) end

Class Method Summary

Class Method Detail

def self.get_cached_power_for_binary_exponent(exp) : Tuple(DiyFP, Int32) #

Returns a cached power-of-ten with a binary exponent in the range around exp (boundaries included).


View source
def self.largest_pow10(n, n_bits) #

View source