Lines Matching defs:buffer

32 // Input: * buffer containing the digits of too_high / 10^kappa
33 // * the buffer's length
36 // * rest = (too_high - buffer * 10^kappa).f() * unit
39 // Output: returns true if the buffer is guaranteed to contain the closest
41 // Modifies the generated digits in the buffer to approach (round towards) w.
42 static bool RoundWeed(Vector<char> buffer, int length,
54 // Basically the buffer currently contains a number in the unsafe interval
73 // buffer --------------------------------------------------+-------+--------
84 // Note that the value of buffer could lie anywhere inside the range too_low
95 // If the number inside the buffer lies inside the unsafe interval but not
105 // too_high) buffer that is still in the unsafe interval. In the case where
106 // w_high < buffer < too_high we try to decrement the buffer.
107 // This way the buffer approaches (rounds towards) w.
109 // 1) the buffer is already below w_high
110 // 2) decrementing the buffer would make it leave the unsafe interval
111 // 3) decrementing the buffer would yield a number below w_high and farther
113 // (buffer{-1} < w_high) && w_high - buffer{-1} > buffer - w_high
114 // Instead of using the buffer directly we use its distance to too_high.
115 // Conceptually rest ~= too_high - buffer
121 (rest + ten_kappa < small_distance || // buffer{-1} > w_high
123 buffer[length - 1]--;
128 // would require changing the buffer. If yes, then we have two possible
140 // Conceptually we have: rest ~= too_high - buffer
144 // Rounds the buffer upwards if the result is closer to v by possibly adding
145 // 1 to the buffer. If the precision of the calculation is not sufficient to
147 // The rounding might shift the whole buffer in which case the kappa is
150 // If 2*rest > ten_kappa then the buffer needs to be round up.
156 static bool RoundWeedCounted(Vector<char> buffer, int length, uint64_t rest,
177 buffer[length - 1]++;
179 if (buffer[i] != '0' + 10) break;
180 buffer[i] = '0';
181 buffer[i - 1]++;
183 // If the first digit is now '0'+ 10 we had a buffer with all '9's. With the
187 if (buffer[0] == '0' + 10) {
188 buffer[0] = '1';
321 // Returns false if it fails, in which case the generated digits in the buffer
331 // * buffer is not null-terminated, but len contains the number of digits.
332 // * buffer contains the shortest possible decimal digit-sequence
333 // such that LOW < buffer * 10^kappa < HIGH, where LOW and HIGH are the
353 // once we have enough digits. That is, once the digits inside the buffer
357 static bool DigitGen(DiyFp low, DiyFp w, DiyFp high, Vector<char> buffer,
382 // Reminder: we are currently computing the digits (stored inside the buffer)
383 // such that: too_low < buffer * 10^kappa < too_high
397 // Loop invariant: buffer = too_high / 10^kappa (integer division)
403 buffer[*length] = '0' + digit;
411 // Invariant: too_high = buffer * 10^kappa + DiyFp(rest, one.e())
416 return RoundWeed(buffer, *length, DiyFp::Minus(too_high, w).f(),
438 buffer[*length] = '0' + digit;
443 return RoundWeed(buffer, *length, DiyFp::Minus(too_high, w).f() * unit,
455 // Returns false if it fails, in which case the generated digits in the buffer
464 // * buffer is not null-terminated, but length contains the number of
466 // * the representation in buffer is the most precise representation of
468 // * buffer contains at most requested_digits digits of w. If there are less
471 // w = buffer * 10^kappa + eps with |eps| < 10^kappa / 2.
477 static bool DigitGenCounted(DiyFp w, int requested_digits, Vector<char> buffer,
487 // instead. Example: instead of writing "1.2" we put "12" into the buffer and
501 // Loop invariant: buffer = w / 10^kappa (integer division)
507 buffer[*length] = '0' + digit;
521 return RoundWeedCounted(buffer, *length, rest,
540 buffer[*length] = '0' + digit;
547 return RoundWeedCounted(buffer, *length, fractionals, one.f(), w_error,
553 // There will be *length digits inside the buffer (not null-terminated).
555 // v == (double) (buffer * 10^decimal_exponent).
556 // The digits in the buffer are the shortest representation possible: no
562 static bool Grisu3(double v, Vector<char> buffer, int* length,
609 // the buffer will be filled with "123" und the decimal_exponent will be
613 buffer, length, &kappa);
623 static bool Grisu3Counted(double v, int requested_digits, Vector<char> buffer,
652 // return together with a kappa such that scaled_w ~= buffer * 10^kappa. (It
657 DigitGenCounted(scaled_w, requested_digits, buffer, length, &kappa);
663 Vector<char> buffer, int* length, int* decimal_point) {
671 result = Grisu3(v, buffer, length, &decimal_exponent);
675 Grisu3Counted(v, requested_digits, buffer, length, &decimal_exponent);
682 buffer[*length] = '\0';