-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Tracking Issue for Integer::{ilog,ilog2,ilog10} #70887
Copy link
Copy link
Closed
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Metadata
Metadata
Assignees
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Feature gate:
#![feature(int_log)]Stabilization report: #70887 (comment)
This is a tracking issue for adding
{checked_,}{ilog,ilog2,ilog10}methods to{u8,u16,u32,u64,u128}. A full rationale can be found in #80918 (comment). But in short: integer logarithms are fairly common, but require care to implement correctly, and effort to implement efficiently.Because we expose
logmethods for floats it can be tempting for users to use that instead, which can lead to rounding errors. In the following example we're trying to calculatebase10for an integer. We might try and calculate thebase2for the values, and attempt a base swap to arrive atbase10. However because we're performing intermediate rounding we arrive at the wrong result:Public API
Steps / History
Unresolved Questions
ilog10implementation? Add Integer::checked_{log,log2,log10} #70835 (comment)const fn?NonZero{Int}? Add Integer::checked_{log,log2,log10} #70835 (comment)Optionforilog2/ilog10onNonZero{Int}?Integer::{ilog,ilog2,ilog10}instead? Add Integer::checked_{log,log2,log10} #70835 (comment) Tracking Issue for Integer::{ilog,ilog2,ilog10} #70887 (comment)Implementation History
logmethods, mergedlog2andlog10toNonZeroU*#92956 -logmethods forNonZerotypeslogmethods toilog{integer primitive}::ilog{,2,10}in all modes #102578 - panic on invalid args