19 int ndigits_for(std::uint32_t x) {
67 constexpr std::uint64_t one = 1;
68 constexpr std::uint64_t p = 53;
70 std::memcpy(&pun, &v,
sizeof(v));
71 auto sign = pun >> 63;
73 auto be = pun >> (p - 1);
79 if (sign) buffer[bp++] =
'-';
89 if (sign) buffer[bp++] =
'-';
94 f = m + (one << (p - 1));
96 auto e = std::int64_t(be) - 1075;
99 if (f != (one << (p - 1))) {
117 if ((be == 0) || (f != (one << (p - 1)))) {
135 auto r_p_mp = r + mp;
136 auto r_p_mp_comp = comp(r_p_mp, s);
137 if (r_p_mp_comp == 0) {
138 }
else if (r_p_mp_comp == 1) {
139 while (r_p_mp > (s * B_k)) {
143 while ((r_p_mp * B_k) < s) {
158 for (n = 0;
true; ++n) {
161 auto d_np1 = r_x_10 / s;
163 auto cond2 = (r + mp) > s;
164 if (cond1 && cond2) {
167 buffer[bp++] = last_d;
169 buffer[bp++] = last_d + 1;
173 buffer[bp++] = last_d;
176 buffer[bp++] = last_d + 1;
179 if (n) buffer[bp++] = last_d;
184 last_d = char(d_np1[0]) +
'0';
192 bool do_scientific =
false;
193 if (0 <= k && k <= n) {
197 auto nchars_sci = ndigits_for(-k + 1) + 2;
198 if (n > 1) nchars_sci += 1;
199 if (nchars_sci < (-k + 1)) {
201 if (n > 1) dot_pos = 1;
202 do_scientific =
true;
205 for (
int i = 0; i < n; ++i) {
206 buffer[bp + (-k) - i - 1] = buffer[bp - i - 1];
208 for (
int i = 0; i < -k; ++i) {
209 buffer[bp - n + i] =
'0';
216 auto nchars_sci = ndigits_for(k - 1) + 1;
217 if (n > 1) nchars_sci += 1;
218 if (nchars_sci < ((k-n)+1)) {
220 if (n > 1) dot_pos = 1;
221 do_scientific =
true;
224 for (; n < k; ++n) buffer[bp++] =
'0';
229 for (
int i = 0; i < (n - dot_pos) && i < bp; ++i) buffer[bp - i] = buffer[bp - i - 1];
230 buffer[bp - n + dot_pos] =
'.';
235 auto decimal_exponent = (k - 1);
236 if (decimal_exponent < 0) {
238 decimal_exponent = -decimal_exponent;
241 for (ne = 0; decimal_exponent; ++ne) {
242 buffer[bp++] = char(decimal_exponent % 10) +
'0';
243 decimal_exponent /= 10;
245 for (
int i = 0; i < ne / 2; ++i) {
246 auto tmp = buffer[bp - ne + i];
247 buffer[bp - ne + i] = buffer[bp - i - 1];
248 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.