Home | History | Annotate | Download | only in src

Lines Matching refs:buffer

33 // Input: * buffer containing the digits of too_high / 10^kappa
34 // * the buffer's length
37 // * rest = (too_high - buffer * 10^kappa).f() * unit
40 // Output: returns true if the buffer is guaranteed to contain the closest
42 // Modifies the generated digits in the buffer to approach (round towards) w.
43 static bool RoundWeed(Vector<char> buffer,
59 // Basically the buffer currently contains a number in the unsafe interval
78 // buffer --------------------------------------------------+-------+--------
89 // Note that the value of buffer could lie anywhere inside the range too_low
100 // If the number inside the buffer lies inside the unsafe interval but not
110 // too_high) buffer that is still in the unsafe interval. In the case where
111 // w_high < buffer < too_high we try to decrement the buffer.
112 // This way the buffer approaches (rounds towards) w.
114 // 1) the buffer is already below w_high
115 // 2) decrementing the buffer would make it leave the unsafe interval
116 // 3) decrementing the buffer would yield a number below w_high and farther
118 // (buffer{-1} < w_high) && w_high - buffer{-1} > buffer - w_high
119 // Instead of using the buffer directly we use its distance to too_high.
120 // Conceptually rest ~= too_high - buffer
126 (rest + ten_kappa < small_distance || // buffer{-1} > w_high
128 buffer[length - 1]--;
133 // would require changing the buffer. If yes, then we have two possible
146 // Conceptually we have: rest ~= too_high - buffer
151 // Rounds the buffer upwards if the result is closer to v by possibly adding
152 // 1 to the buffer. If the precision of the calculation is not sufficient to
154 // The rounding might shift the whole buffer in which case the kappa is
157 // If 2*rest > ten_kappa then the buffer needs to be round up.
163 static bool RoundWeedCounted(Vector<char> buffer,
188 buffer[length - 1]++;
190 if (buffer[i] != '0' + 10) break;
191 buffer[i] = '0';
192 buffer[i - 1]++;
194 // If the first digit is now '0'+ 10 we had a buffer with all '9's. With the
198 if (buffer[0] == '0' + 10) {
199 buffer[0] = '1';
326 // Returns false if it fails, in which case the generated digits in the buffer
336 // * buffer is not null-terminated, but len contains the number of digits.
337 // * buffer contains the shortest possible decimal digit-sequence
338 // such that LOW < buffer * 10^kappa < HIGH, where LOW and HIGH are the
358 // once we have enough digits. That is, once the digits inside the buffer
365 Vector<char> buffer,
391 // Reminder: we are currently computing the digits (stored inside the buffer)
392 buffer * 10^kappa < too_high
406 // Loop invariant: buffer = too_high / 10^kappa (integer division)
412 buffer[*length] = '0' + digit;
420 // Invariant: too_high = buffer * 10^kappa + DiyFp(rest, one.e())
425 return RoundWeed(buffer, *length, DiyFp::Minus(too_high, w).f(),
447 buffer[*length] = '0' + digit;
452 return RoundWeed(buffer, *length, DiyFp::Minus(too_high, w).f() * unit,
466 // Returns false if it fails, in which case the generated digits in the buffer
475 // * buffer is not null-terminated, but length contains the number of
477 // * the representation in buffer is the most precise representation of
479 // * buffer contains at most requested_digits digits of w. If there are less
482 // w = buffer * 10^kappa + eps with |eps| < 10^kappa / 2.
490 Vector<char> buffer,
501 // instead. Example: instead of writing "1.2" we put "12" into the buffer and
515 // Loop invariant: buffer = w / 10^kappa (integer division)
521 buffer[*length] = '0' + digit;
535 return RoundWeedCounted(buffer, *length, rest,
554 buffer[*length] = '0' + digit;
561 return RoundWeedCounted(buffer, *length, fractionals, one.f(), w_error,
568 // There will be *length digits inside the buffer (not null-terminated).
570 // v == (double) (buffer * 10^decimal_exponent).
571 // The digits in the buffer are the shortest representation possible: no
578 Vector<char> buffer,
627 // the buffer will be filled with "123" und the decimal_exponent will be
631 buffer, length, &kappa);
644 Vector<char> buffer,
675 // return together with a kappa such that scaled_w ~= buffer * 10^kappa. (It
680 buffer, length, &kappa);
689 Vector<char> buffer,
699 result = Grisu3(v, buffer, length, &decimal_exponent);
703 buffer, length, &decimal_exponent);
710 buffer[*length] = '\0';