51 int ndigits_for(std::uint32_t x) {
99 constexpr std::uint64_t one = 1;
100 constexpr std::uint64_t p = 53;
102 std::memcpy(&pun, &v,
sizeof(v));
103 auto sign = pun >> 63;
105 auto be = pun >> (p - 1);
106 pun -= be << (p - 1);
111 if (sign) buffer[bp++] =
'-';
121 if (sign) buffer[bp++] =
'-';
126 f = m + (one << (p - 1));
128 auto e = std::int64_t(be) - 1075;
131 if (f != (one << (p - 1))) {
149 if ((be == 0) || (f != (one << (p - 1)))) {
167 auto r_p_mp = r + mp;
168 auto r_p_mp_comp = comp(r_p_mp, s);
169 if (r_p_mp_comp == 0) {
170 }
else if (r_p_mp_comp == 1) {
171 while (r_p_mp > (s * B_k)) {
175 while ((r_p_mp * B_k) < s) {
190 for (n = 0;
true; ++n) {
193 auto d_np1 = r_x_10 / s;
195 auto cond2 = (r + mp) > s;
196 if (cond1 && cond2) {
199 buffer[bp++] = last_d;
201 buffer[bp++] = last_d + 1;
205 buffer[bp++] = last_d;
208 buffer[bp++] = last_d + 1;
211 if (n) buffer[bp++] = last_d;
216 last_d = char(d_np1[0]) +
'0';
224 bool do_scientific =
false;
225 if (0 <= k && k <= n) {
229 auto nchars_sci = ndigits_for(-k + 1) + 2;
230 if (n > 1) nchars_sci += 1;
231 if (nchars_sci < (-k + 1)) {
233 if (n > 1) dot_pos = 1;
234 do_scientific =
true;
237 for (
int i = 0; i < n; ++i) {
238 buffer[bp + (-k) - i - 1] = buffer[bp - i - 1];
240 for (
int i = 0; i < -k; ++i) {
241 buffer[bp - n + i] =
'0';
248 auto nchars_sci = ndigits_for(k - 1) + 1;
249 if (n > 1) nchars_sci += 1;
250 if (nchars_sci < ((k-n)+1)) {
252 if (n > 1) dot_pos = 1;
253 do_scientific =
true;
256 for (; n < k; ++n) buffer[bp++] =
'0';
261 for (
int i = 0; i < (n - dot_pos) && i < bp; ++i) buffer[bp - i] = buffer[bp - i - 1];
262 buffer[bp - n + dot_pos] =
'.';
267 auto decimal_exponent = (k - 1);
268 if (decimal_exponent < 0) {
270 decimal_exponent = -decimal_exponent;
273 for (ne = 0; decimal_exponent; ++ne) {
274 buffer[bp++] = char(decimal_exponent % 10) +
'0';
275 decimal_exponent /= 10;
277 for (
int i = 0; i < ne / 2; ++i) {
278 auto tmp = buffer[bp - ne + i];
279 buffer[bp - ne + i] = buffer[bp - i - 1];
280 buffer[bp - i - 1] = tmp;
void print_double(std::ostream &os, double v)
Prints a double-precision floating-point number exactly using minimal characters. ...
Arbitrary-precision unsigned integer class.
Arbitrary-precision unsigned integer definition.
Declares Teuchos::print_double.