Skip to content

Commit c58785d

Browse files
committed
core: fixed typos and misleading comments in flt2dec.
1 parent e908595 commit c58785d

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/libcore/num/flt2dec/bignum.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl_full_ops! {
8888
u8: add(intrinsics::u8_add_with_overflow), mul/div(u16);
8989
u16: add(intrinsics::u16_add_with_overflow), mul/div(u32);
9090
u32: add(intrinsics::u32_add_with_overflow), mul/div(u64);
91-
// u64: add(intrinsics::u64_add_with_overflow), mul/div(u128); // damn!
91+
// u64: add(intrinsics::u64_add_with_overflow), mul/div(u128); // see RFC #521 for enabling this.
9292
}
9393

9494
macro_rules! define_bignum {
@@ -103,11 +103,12 @@ macro_rules! define_bignum {
103103
/// All operations available to bignums panic in the case of over/underflows.
104104
/// The caller is responsible to use large enough bignum types.
105105
pub struct $name {
106-
/// One plus the offset to the maximum "digit" in the use.
106+
/// One plus the offset to the maximum "digit" in use.
107107
/// This does not decrease, so be aware of the computation order.
108108
/// `base[size..]` should be zero.
109109
size: usize,
110-
/// Digits. `[a, b, c, ...]` represents `a + b*n + c*n^2 + ...`.
110+
/// Digits. `[a, b, c, ...]` represents `a + b*2^W + c*2^(2W) + ...`
111+
/// where `W` is the number of bits in the digit type.
111112
base: [$ty; $n]
112113
}
113114

@@ -236,8 +237,9 @@ macro_rules! define_bignum {
236237
self
237238
}
238239

239-
/// Multiplies itself by a number described by `other[0] + other[1] * n +
240-
/// other[2] * n^2 + ...` and returns its own mutable reference.
240+
/// Multiplies itself by a number described by `other[0] + other[1] * 2^W +
241+
/// other[2] * 2^(2W) + ...` (where `W` is the number of bits in the digit type)
242+
/// and returns its own mutable reference.
241243
pub fn mul_digits<'a>(&'a mut self, other: &[$ty]) -> &'a mut $name {
242244
// the internal routine. works best when aa.len() <= bb.len().
243245
fn mul_inner(ret: &mut [$ty; $n], aa: &[$ty], bb: &[$ty]) -> usize {

src/libcore/num/flt2dec/mod.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Both implementations expose two public functions:
9393
9494
They try to fill the `u8` buffer with digits and returns the number of digits
9595
written and the exponent `k`. They are total for all finite `f32` and `f64`
96-
inputs (Grisu internally falls back to Dragon if possible).
96+
inputs (Grisu internally falls back to Dragon if necessary).
9797
9898
The rendered digits are formatted into the actual string form with
9999
four functions:
@@ -114,8 +114,8 @@ four functions:
114114
They all return a slice of preallocated `Part` array, which corresponds to
115115
the individual part of strings: a fixed string, a part of rendered digits,
116116
a number of zeroes or a small (`u16`) number. The caller is expected to
117-
provide an enough buffer and `Part` array, and to assemble the final
118-
string from parts itself.
117+
provide a large enough buffer and `Part` array, and to assemble the final
118+
string from resulting `Part`s itself.
119119
120120
All algorithms and formatting functions are accompanied by extensive tests
121121
in `coretest::num::flt2dec` module. It also shows how to use individual
@@ -639,9 +639,8 @@ pub fn to_exact_fixed_str<'a, T, F>(mut format_exact: F, v: T,
639639
let limit = if frac_digits < 0x8000 { -(frac_digits as i16) } else { i16::MIN };
640640
let (len, exp) = format_exact(decoded, &mut buf[..maxlen], limit);
641641
if exp <= limit {
642-
// `format_exact` always returns at least one digit even though the restriction
643-
// hasn't been met, so we catch this condition and treats as like zeroes.
644-
// this does not include the case that the restriction has been met
642+
// the restriction couldn't been met, so this should render like zero no matter
643+
// `exp` was. this does not include the case that the restriction has been met
645644
// only after the final rounding-up; it's a regular case with `exp = limit + 1`.
646645
debug_assert_eq!(len, 0);
647646
if frac_digits > 0 { // [0.][0000]

0 commit comments

Comments
 (0)