-
Notifications
You must be signed in to change notification settings - Fork 23
Update numberOf{Leading,Trailing}Zeros documentation #119
Conversation
osa1
commented
Oct 18, 2023
- Mention the result when the integer is 0.
- Clarify that leading = most significant, trailing = least significant.
- Remove the documentation from the implementation class.
- Mention the result when the integer is 0. - Clarify that leading = most significant, trailing = least signitifant.
/// Returns the number of leading (most significant) zeros in this integer's | ||
/// two's complement representation. | ||
/// | ||
/// For zero, the result is the same as the integer type's bit max. bit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something left over here? "bit max.bit length".
I don't know what a "bit max" is, and it's not defined.
Maybe:
/// For the value zero, the number of leading zeros is the entire
/// number of bits of the type (64 for [Int64], 32 for [Int32]).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also worth adding that
/// Negative numbers have no leading zero bits, their most signfiicant
/// bit is always set.
@@ -125,12 +125,18 @@ abstract class IntX implements Comparable<Object> { | |||
/// value, add one, i.e. use `x.bitLength + 1`. | |||
int get bitLength; | |||
|
|||
/// Returns the number of high-order zeros in this integer's bit | |||
/// representation. | |||
/// Returns the number of leading (most significant) zeros in this integer's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're touching this, remove the "Returns". It's a getter, so document using a noun phrase.
(Actually, it's not a getter. It definitely should have been. But it's named as one, with a noun phrase name, so it should still be documented the same way.)
int numberOfLeadingZeros(); | ||
|
||
/// Returns the number of low-order zeros in this integer's bit | ||
/// representation. | ||
/// Returns the number of trailing (least significant) zeros in this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop "Returns" here too.
/// integer's two's complement representation. | ||
/// | ||
/// For zero, the result is the same as the integer type's bit max. bit | ||
/// length. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same phrase,
/// For the value zero, the number of leading zeros is the entire
/// number of bits of the type (64 for [Int64], 32 for [Int32]).
And consider adding
/// Odd numbers have no trailing zero bits, their least significant bit
/// is always set.
It's just explanatory, but may help intuition.
Can also add
/// A number `n` is evenly divisible by `pow(2, n.numberOfTrailingZeros())`.
as another intuitional hint, building on the odd
one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can keep tweaking documentation forever. Take whatever you like.
Closing as the dart-lang/fixnum repository is merged into the dart-lang/core monorepo. Please re-open this PR there! |