Lines Matching refs:buffer
56 // Input: * buffer containing the digits of too_high / 10^kappa
57 // * the buffer's length
60 // * rest = (too_high - buffer * 10^kappa).f() * unit
63 // Output: returns true if the buffer is guaranteed to contain the closest
65 // Modifies the generated digits in the buffer to approach (round towards) w.
66 static bool RoundWeed(Vector<char> buffer,
82 // Basically the buffer currently contains a number in the unsafe interval
101 // buffer --------------------------------------------------+-------+--------
112 // Note that the value of buffer could lie anywhere inside the range too_low
123 // If the number inside the buffer lies inside the unsafe interval but not
133 // too_high) buffer that is still in the unsafe interval. In the case where
134 // w_high < buffer < too_high we try to decrement the buffer.
135 // This way the buffer approaches (rounds towards) w.
137 // 1) the buffer is already below w_high
138 // 2) decrementing the buffer would make it leave the unsafe interval
139 // 3) decrementing the buffer would yield a number below w_high and farther
141 // (buffer{-1} < w_high) && w_high - buffer{-1} > buffer - w_high
142 // Instead of using the buffer directly we use its distance to too_high.
143 // Conceptually rest ~= too_high - buffer
149 (rest + ten_kappa < small_distance || // buffer{-1} > w_high
151 buffer[length - 1]--;
156 // would require changing the buffer. If yes, then we have two possible
169 // Conceptually we have: rest ~= too_high - buffer
174 // Rounds the buffer upwards if the result is closer to v by possibly adding
175 // 1 to the buffer. If the precision of the calculation is not sufficient to
177 // The rounding might shift the whole buffer in which case the kappa is
180 // If 2*rest > ten_kappa then the buffer needs to be round up.
186 static bool RoundWeedCounted(Vector<char> buffer,
211 buffer[length - 1]++;
213 if (buffer[i] != '0' + 10) break;
214 buffer[i] = '0';
215 buffer[i - 1]++;
217 // If the first digit is now '0'+ 10 we had a buffer with all '9's. With the
221 if (buffer[0] == '0' + 10) {
222 buffer[0] = '1';
349 // Returns false if it fails, in which case the generated digits in the buffer
359 // * buffer is not null-terminated, but len contains the number of digits.
360 // * buffer contains the shortest possible decimal digit-sequence
361 // such that LOW < buffer * 10^kappa < HIGH, where LOW and HIGH are the
381 // once we have enough digits. That is, once the digits inside the buffer
388 Vector<char> buffer,
414 // Reminder: we are currently computing the digits (stored inside the buffer)
415 // such that: too_low < buffer * 10^kappa < too_high
429 // Loop invariant: buffer = too_high / 10^kappa (integer division)
435 buffer[*length] = '0' + digit;
443 // Invariant: too_high = buffer * 10^kappa + DiyFp(rest, one.e())
448 return RoundWeed(buffer, *length, DiyFp::Minus(too_high, w).f(),
470 buffer[*length] = '0' + digit;
475 return RoundWeed(buffer, *length, DiyFp::Minus(too_high, w).f() * unit,
489 // Returns false if it fails, in which case the generated digits in the buffer
498 // * buffer is not null-terminated, but length contains the number of
500 // * the representation in buffer is the most precise representation of
502 // * buffer contains at most requested_digits digits of w. If there are less
505 // w = buffer * 10^kappa + eps with |eps| < 10^kappa / 2.
513 Vector<char> buffer,
524 // instead. Example: instead of writing "1.2" we put "12" into the buffer and
538 // Loop invariant: buffer = w / 10^kappa (integer division)
544 buffer[*length] = '0' + digit;
558 return RoundWeedCounted(buffer, *length, rest,
577 buffer[*length] = '0' + digit;
584 return RoundWeedCounted(buffer, *length, fractionals, one.f(), w_error,
591 // There will be *length digits inside the buffer (not null-terminated).
593 // v == (double) (buffer * 10^decimal_exponent).
594 // The digits in the buffer are the shortest representation possible: no
601 Vector<char> buffer,
650 // the buffer will be filled with "123" und the decimal_exponent will be
654 buffer, length, &kappa);
667 Vector<char> buffer,
698 // return together with a kappa such that scaled_w ~= buffer * 10^kappa. (It
703 buffer, length, &kappa);
712 Vector<char> buffer,
722 result = Grisu3(v, buffer, length, &decimal_exponent);
726 buffer, length, &decimal_exponent);
733 buffer[*length] = '\0';