MCPcopy Create free account
hub / github.com/ablab/spades / AdjustToPrecision

Function AdjustToPrecision

ext/src/llvm/APFloat.cpp:3612–3640  ·  view source on GitHub ↗

Removes data from the given significand until it is no more precise than is required for the desired precision.

Source from the content-addressed store, hash-verified

3610 /// Removes data from the given significand until it is no more
3611 /// precise than is required for the desired precision.
3612 void AdjustToPrecision(APInt &significand,
3613 int &exp, unsigned FormatPrecision) {
3614 unsigned bits = significand.getActiveBits();
3615
3616 // 196/59 is a very slight overestimate of lg_2(10).
3617 unsigned bitsRequired = (FormatPrecision * 196 + 58) / 59;
3618
3619 if (bits <= bitsRequired) return;
3620
3621 unsigned tensRemovable = (bits - bitsRequired) * 59 / 196;
3622 if (!tensRemovable) return;
3623
3624 exp += tensRemovable;
3625
3626 APInt divisor(significand.getBitWidth(), 1);
3627 APInt powten(significand.getBitWidth(), 10);
3628 while (true) {
3629 if (tensRemovable & 1)
3630 divisor *= powten;
3631 tensRemovable >>= 1;
3632 if (!tensRemovable) break;
3633 powten *= powten;
3634 }
3635
3636 significand = significand.udiv(divisor);
3637
3638 // Truncate the significand down to its active bit count.
3639 significand = significand.trunc(significand.getActiveBits());
3640 }
3641
3642
3643 void AdjustToPrecision(SmallVectorImpl<char> &buffer,

Callers 1

toStringMethod · 0.85

Calls 6

udivMethod · 0.80
truncMethod · 0.80
sizeMethod · 0.45
eraseMethod · 0.45
clearMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected