Skip to content

Conversation

@eggyal
Copy link
Contributor

@eggyal eggyal commented Jan 10, 2026

Rather than convert Duration to a float in order to multiply or divide by a floating point number, which entails a loss of precision, we instead represent both operands as u128 nanoseconds and perform integer arithmetic thereupon.

This improvement in precision affects some of the documented examples.

Given that these methods have been stabilised, is it a breaking change to affect their output? If so, this PR obviously cannot be merged as-is: we might instead need to create new methods for this more precise calculation (and possibly deprecate the existing ones).

Fixes #149794
r? libs-api

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 10, 2026
@eggyal eggyal marked this pull request as draft January 11, 2026 03:09
@rustbot rustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels Jan 11, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 11, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@eggyal eggyal force-pushed the issue-149794 branch 2 times, most recently from 5844308 to adc30ec Compare January 11, 2026 15:14
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@eggyal
Copy link
Contributor Author

eggyal commented Jan 12, 2026

@rustbot ready

@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 Jan 12, 2026
@eggyal eggyal marked this pull request as ready for review January 12, 2026 03:23
@eggyal eggyal requested a review from quaternic January 12, 2026 03:23
@eggyal eggyal force-pushed the issue-149794 branch 2 times, most recently from cf585ba to c7098b3 Compare January 12, 2026 10:48
@eggyal
Copy link
Contributor Author

eggyal commented Jan 12, 2026

No, some corner cases are not quite right here. I'll add some more tests and push a fix.

@rustbot author

@rustbot rustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels Jan 12, 2026
@eggyal eggyal marked this pull request as draft January 12, 2026 14:27
@eggyal
Copy link
Contributor Author

eggyal commented Jan 12, 2026

@rustbot ready

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 12, 2026
@eggyal eggyal marked this pull request as ready for review January 12, 2026 18:35
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 12, 2026
@rust-log-analyzer

This comment has been minimized.

@eggyal eggyal force-pushed the issue-149794 branch 5 times, most recently from a52d3a0 to 6827d88 Compare January 13, 2026 18:35
Rather than convert Duration to a float in order to multiply or divide
by a floating point number, which entails a loss of precision, we
instead represent both operands as u128 nanoseconds and perform integer
arithmetic thereupon.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

Loss of precision in Duration::mul_f32 (and mul_f64)

5 participants