Skip to content

add scalbn and ilogb methods on floats - #163187

Open
folkertdev wants to merge 2 commits into
rust-lang:mainfrom
folkertdev:scalbn
Open

folkertdev wants to merge 2 commits into
rust-lang:mainfrom
folkertdev:scalbn

Conversation

@folkertdev

@folkertdev folkertdev commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

tracking issue: #163184

@rustbot rustbot added A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 22, 2026
Comment thread library/core/src/num/f32.rs Resolved
Comment thread library/coretests/tests/num/floats.rs Resolved
Comment thread library/coretests/tests/num/floats.rs Resolved
Comment thread library/core/src/intrinsics/mod.rs Resolved
Comment thread library/core/src/intrinsics/mod.rs Resolved
Comment thread library/core/src/num/f128.rs Outdated
Comment on lines +1685 to +1694
/// Placeholder.
#[inline]
#[unstable(feature = "float_exponent_methods", issue = "163184")]
#[rustc_const_unstable(feature = "float_exponent_methods", issue = "163184")]
#[must_use = "method returns a new number and does not mutate the original value"]
pub const fn scalbn(self, exponent: i32) -> f128 {
intrinsics::scalbn(self, exponent)
}

/// Placeholder.

@clarfonthey clarfonthey Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Placeholder docs. (I hate that we can't just use macros to define the float types.)

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What could be nice nowadays is putting the docs into one of the macro_rules! attribute macros so you could do something like #[float_docs(ilogb, f128, constant_a = 1234, constant_b = 3.141)]. So the docs can get reused but "go to source" works correctly and the implementations can deviate where necessary.

Comment thread library/core/src/num/f16.rs Outdated
Comment on lines +1671 to +1680
/// Placeholder.
#[inline]
#[unstable(feature = "float_exponent_methods", issue = "163184")]
#[rustc_const_unstable(feature = "float_exponent_methods", issue = "163184")]
#[must_use = "method returns a new number and does not mutate the original value"]
pub const fn scalbn(self, exponent: i32) -> f16 {
intrinsics::scalbn(self, exponent)
}

/// Placeholder.

@clarfonthey clarfonthey Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Placeholder docs. (I hate that we can't just use macros to define the float types.)

View changes since the review

Comment thread library/core/src/num/f32.rs Resolved
Comment thread library/core/src/num/f64.rs Outdated
Comment on lines +1806 to +1815
/// Placeholder.
#[inline]
#[unstable(feature = "float_exponent_methods", issue = "163184")]
#[rustc_const_unstable(feature = "float_exponent_methods", issue = "163184")]
#[must_use = "method returns a new number and does not mutate the original value"]
pub const fn scalbn(self, exponent: i32) -> f64 {
intrinsics::scalbn(self, exponent)
}

/// Placeholder.

@clarfonthey clarfonthey Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Placeholder docs. (I hate that we can't just use macros to define the float types.)

View changes since the review

@tgross35 tgross35 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Poor Folkert, just a draft PR and already there's so much feedback :) sorry to pile on here

View changes since this review

Comment thread library/core/src/intrinsics/macros.rs Resolved
Comment thread library/core/src/num/f128.rs Outdated
Comment on lines +1685 to +1694
/// Placeholder.
#[inline]
#[unstable(feature = "float_exponent_methods", issue = "163184")]
#[rustc_const_unstable(feature = "float_exponent_methods", issue = "163184")]
#[must_use = "method returns a new number and does not mutate the original value"]
pub const fn scalbn(self, exponent: i32) -> f128 {
intrinsics::scalbn(self, exponent)
}

/// Placeholder.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What could be nice nowadays is putting the docs into one of the macro_rules! attribute macros so you could do something like #[float_docs(ilogb, f128, constant_a = 1234, constant_b = 3.141)]. So the docs can get reused but "go to source" works correctly and the implementations can deviate where necessary.

Comment thread library/core/src/num/f128.rs Resolved
@rust-bors

This comment has been minimized.

@folkertdev folkertdev left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rustbot

rustbot commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

tgross35 is currently at their maximum review capacity.
They may take a while to respond.

@folkertdev
folkertdev marked this pull request as ready for review November 20, 2026 22:35
@rustbot

rustbot commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

compiler-builtins is developed in its own repository. If possible, consider making this change to rust-lang/compiler-builtins instead.

cc @tgross35

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 20, 2026

@folkertdev folkertdev left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only remaining item is the doc comment then (unless something new pops up), which I'd like to settle on first and can then copy. Or maybe #165773 merges in the meantime and we don't need to copy the comment.

View changes since this review

@tgross35

Copy link
Copy Markdown
Member

Fyi it looks like the Miri commit was dropped?

@folkertdev

Copy link
Copy Markdown
Contributor Author

I did some squashing but all the code should still be there?

@tgross35 tgross35 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once the try passes

View changes since this review

@rust-bors

rust-bors Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 9845442 (9845442ca90b019a0d95433e1c7867d346006874)
Base parent: 2772402 (277240238554297f93fa9ee3c7643dfa03ccbbb4)

@folkertdev

Copy link
Copy Markdown
Contributor Author

@bors r=tgross35,RalfJung

@rust-bors

rust-bors Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 3a898d8 has been approved by tgross35,RalfJung

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 24, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Nov 24, 2026
…Jung

add `scalbn` and `ilogb` methods on floats

tracking issue: rust-lang#163184
rust-bors Bot pushed a commit that referenced this pull request Nov 24, 2026
Rollup of 3 pull requests

Successful merges:

 - #163187 (add `scalbn` and `ilogb` methods on floats)
 - #166033 (Abby: move span out of leaf region constraint)
 - #166420 ([rustdoc] Fix search index generation: if crate content didn't change, it should generate the same search index)
@JonathanBrouwer

Copy link
Copy Markdown
Member

💔 I suspect this PR failed tests as part of a rollup
@bors r-

After fixing the problem, consider running a try job for the failed job before re-approving.

Link to failure: #166436 (comment)

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 24, 2026
@rust-bors

rust-bors Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#166436), which was unapproved.

View changes since this unapproval

Comment thread library/core/src/num/f64.rs Outdated
Comment on lines +1602 to +1603
/// assert_eq!(3.0_f64.scalbn(4), 3.0 * 2.0_f64.powi(4)); // = 3 * 16 = 48
/// assert_eq!(3.0_f64.scalbn(-1), 3.0 * 2.0_f64.powi(-1)); // = 3 * 0.5 = 1.5

@folkertdev folkertdev Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With Miri (and who knows, some libcs) the powi here is not exact, so I'll make this match on the answer and put the calculation in the comment.

View changes since the review

@folkertdev

Copy link
Copy Markdown
Contributor Author

@bors try jobs=test-x86_64-gnu-aux

rust-bors Bot pushed a commit that referenced this pull request Nov 24, 2026
add `scalbn` and `ilogb` methods on floats


try-job: test-x86_64-gnu-aux
@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 0ab3dba (0ab3dba9a45daa09b6555593c9b12e9bd500b7e3)
Base parent: 058c701 (058c701055c4b6f60f622d616afc0349911c38c3)

@folkertdev

Copy link
Copy Markdown
Contributor Author

@bors r=tgross35,RalfJung

@rust-bors

rust-bors Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 696aebd has been approved by tgross35,RalfJung

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 24, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 24, 2026
…Jung

add `scalbn` and `ilogb` methods on floats

tracking issue: rust-lang#163184

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants