Skip to content

Commit 6cef103

Browse files
committed
Touch up checked_log PR
1 parent 8a2e376 commit 6cef103

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

src/libcore/num/mod.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -2163,7 +2163,7 @@ assert_eq!((-a).rem_euclid(-b), 1);
21632163
doc_comment! {
21642164
concat!("Returns the logarithm of the number with respect to an arbitrary base.
21652165
2166-
Returns `None` if the number is zero, or if the base is zero or one.
2166+
Returns `None` if the number is negative or zero, or if the base is not at least 2.
21672167
21682168
This method may not be optimized owing to implementation details;
21692169
`self.checked_log2()` can produce results more efficiently for base 2, and
@@ -2214,7 +2214,7 @@ assert_eq!(result, Some(1));
22142214
doc_comment! {
22152215
concat!("Returns the base 2 logarithm of the number.
22162216
2217-
Returns `None` if the number is lower than 1.
2217+
Returns `None` if the number is negative or zero.
22182218
22192219
# Examples
22202220
@@ -2246,7 +2246,7 @@ assert_eq!(result, Some(1));
22462246
doc_comment! {
22472247
concat!("Returns the base 10 logarithm of the number.
22482248
2249-
Returns `None` if the number is lower than 1.
2249+
Returns `None` if the number is negative or zero.
22502250
22512251
# Examples
22522252
@@ -2269,8 +2269,6 @@ assert_eq!(result, Some(1));
22692269
}
22702270
}
22712271

2272-
2273-
22742272
doc_comment! {
22752273
concat!("Computes the absolute value of `self`.
22762274
@@ -4283,7 +4281,7 @@ assert_eq!(7", stringify!($SelfT), ".rem_euclid(4), 3); // or any other integer
42834281
doc_comment! {
42844282
concat!("Returns the logarithm of the number with respect to an arbitrary base.
42854283
4286-
Returns `None` if the number is negative or zero, or if the base is negative, zero, or one.
4284+
Returns `None` if the number is zero, or if the base is not at least 2.
42874285
42884286
This method may not be optimized owing to implementation details;
42894287
`self.checked_log2()` can produce results more efficiently for base 2, and
@@ -4334,7 +4332,7 @@ assert_eq!(result, Some(1));
43344332
doc_comment! {
43354333
concat!("Returns the base 2 logarithm of the number.
43364334
4337-
Returns `None` if the number is lower than 1.
4335+
Returns `None` if the number is zero.
43384336
43394337
# Examples
43404338
@@ -4366,7 +4364,7 @@ assert_eq!(result, Some(1));
43664364
doc_comment! {
43674365
concat!("Returns the base 10 logarithm of the number.
43684366
4369-
Returns `None` if the number is lower than 1.
4367+
Returns `None` if the number is zero.
43704368
43714369
# Examples
43724370

src/libcore/tests/num/int_log.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ fn checked_log() {
1616
assert_eq!(i.checked_log(4), None);
1717
}
1818
for i in 1..=i16::MAX {
19-
assert_eq!(i.checked_log(13), Some((i as f32).checked_log(13.0) as i16));
19+
assert_eq!(i.checked_log(13), Some((i as f32).log(13.0) as i16));
2020
}
2121
for i in 1..=u16::MAX {
22-
assert_eq!(i.checked_log(13), Some((i as f32).checked_log(13.0) as u16));
22+
assert_eq!(i.checked_log(13), Some((i as f32).log(13.0) as u16));
2323
}
2424
}
25+
2526
#[test]
2627
fn checked_log2() {
2728
assert_eq!(5u32.checked_log2(), Some(2));
@@ -30,35 +31,34 @@ fn checked_log2() {
3031
assert_eq!((-55i16).checked_log2(), None);
3132

3233
for i in 1..=u8::MAX {
33-
assert_eq!(i.checked_log2(), Some((i as f32).checked_log2() as u8));
34+
assert_eq!(i.checked_log2(), Some((i as f32).log2() as u8));
3435
}
3536
for i in 1..=u16::MAX {
36-
assert_eq!(i.checked_log2(), Some((i as f32).checked_log2() as u16));
37+
assert_eq!(i.checked_log2(), Some((i as f32).log2() as u16));
3738
}
3839
for i in i8::MIN..=0 {
3940
assert_eq!(i.checked_log2(), None);
4041
}
4142
for i in 1..=i8::MAX {
42-
assert_eq!(i.checked_log2(), Some((i as f32).checked_log2() as i8));
43+
assert_eq!(i.checked_log2(), Some((i as f32).log2() as i8));
4344
}
4445
for i in i16::MIN..=0 {
4546
assert_eq!(i.checked_log2(), None);
4647
}
4748
for i in 1..=i16::MAX {
48-
assert_eq!(i.checked_log2(), Some((i as f32).checked_log2() as i16));
49+
assert_eq!(i.checked_log2(), Some((i as f32).log2() as i16));
4950
}
5051
}
5152

5253
#[test]
5354
fn checked_log10() {
54-
// checked_log10()
5555
for i in i16::MIN..=0 {
5656
assert_eq!(i.checked_log10(), None);
5757
}
5858
for i in 1..=i16::MAX {
59-
assert_eq!(i.checked_log10(), Some((i as f32).checked_log10() as i16));
59+
assert_eq!(i.checked_log10(), Some((i as f32).log10() as i16));
6060
}
6161
for i in 1..=u16::MAX {
62-
assert_eq!(i.checked_log10(), Some((i as f32).checked_log10() as u16));
62+
assert_eq!(i.checked_log10(), Some((i as f32).log10() as u16));
6363
}
6464
}

0 commit comments

Comments
 (0)