Skip to content

refactor(proto): call the std-only float math through crate-root helpers - #848

Merged
flub merged 8 commits into
n0-computer:mainfrom
ecalifornica:ecalifornica/float-math-helpers
Nov 20, 2026
Merged

flub merged 8 commits into
n0-computer:mainfrom
ecalifornica:ecalifornica/float-math-helpers

Conversation

@ecalifornica

Copy link
Copy Markdown
Contributor

Description

Closes #847

round, cbrt, and powi on f64 exist only in std. With the calls going through a math module at the crate root, a build without std can switch them to libm in one place.

clippy.toml prevents new code from calling the std methods directly.

API Changes

None

Notes & open questions

Design notes
  • Functions, not an extension trait: with std, the inherent f64 methods win over trait methods, so the trait import would be unused and warn, and disallowed_methods would flag every call.
  • The BBRv3 tests call math::round too, because the lint also checks test code.

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All API changes documented.
  • cargo make passes locally.

@n0bot n0bot Bot added this to iroh Oct 15, 2026
@github-project-automation github-project-automation Bot moved this to 🚑 Needs Triage in iroh Oct 15, 2026
@ecalifornica
ecalifornica force-pushed the ecalifornica/float-math-helpers branch from 0453fd6 to 23763d7 Compare October 16, 2026 03:24
@ecalifornica
ecalifornica force-pushed the ecalifornica/float-math-helpers branch from 23763d7 to c21dbc3 Compare October 17, 2026 15:41

@flub flub left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Any reason this is still in draft? A few notes but generally it looks good.

Comment thread noq-proto/src/lib.rs Outdated
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
pub(crate) use web_time::{Instant, SystemTime, UNIX_EPOCH};

// Deal with float math

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you make this a full doc comment and add an explanation of why we're doing things this way?

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.

Good call, done.

Comment thread noq-proto/clippy.toml

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do you want to add more methods here to be more future proof in case other methods start being used? They could say something like "add this to crate::math module" or something similar, no need to add the code for all of them. Though I'm not sure how extensive this list is, or whether you can use wildcards.

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.

Looks like clippy doesn't have wildcards for method paths, listed them all :p 2206a92

…math-helpers

# Conflicts:
#	noq-proto/clippy.toml
#	noq-proto/src/bloom_token_log.rs
#	noq-proto/src/lib.rs
The 37 methods per type are the stable ones that Rust 1.99 has in std
but not in core. Clippy takes no wildcard in a method path, so each
method has its own entry. The reason tells the developer to add a
helper to crate::math.
@ecalifornica

Copy link
Copy Markdown
Contributor Author

Any reason this is still in draft? A few notes but generally it looks good.

Was waiting for the ready-for-pr label on #847

@ecalifornica
ecalifornica marked this pull request as ready for review November 13, 2026 22:34
@ecalifornica
ecalifornica requested a review from flub November 13, 2026 22:34
@flub
flub enabled auto-merge November 20, 2026 01:18
@flub

flub commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Any reason this is still in draft? A few notes but generally it looks good.

Was waiting for the ready-for-pr label on #847

ah, apologies. but yeah, this is fine. thanks for the gradual approach to making noq more no_std-friendly!

@flub
flub added this pull request to the merge queue Nov 20, 2026
Merged via the queue into n0-computer:main with commit b36dc4d Nov 20, 2026
34 checks passed
@github-project-automation github-project-automation Bot moved this from 🚑 Needs Triage to ✅ Done in iroh Nov 20, 2026
emrul added a commit to GetAster/noq that referenced this pull request Nov 24, 2026
* upstream/main: (24 commits)
  refactor(proto): call the std-only float math through crate-root helpers (n0-computer#848)
  refactor(proto): Avoid PathId allocation when building PATH_ACKS (n0-computer#901)
  chore: Release
  chore(deps): fix unused crates warnings of rust 1.100 (n0-computer#899)
  chore: Update issue template checkboxes (n0-computer#897)
  chore: humantime is unmaintained (n0-computer#900)
  chore(ci): fix workflows for test binaries locations (n0-computer#896)
  fix(perf): don't enable qlog feature in perf binary (n0-computer#850)
  fix(proto): track the key update boundary per path (n0-computer#869)
  tests: additional stream affinity tests (n0-computer#890)
  feat: allow streams to set an affinity for a path, simple version (n0-computer#881)
  fix(udp): handle receive errors before truncation flags in recv_single (n0-computer#884)
  chore: Upgrade async-executor and allow warnings in patchbay build (n0-computer#888)
  chore: Use shared minimal-crates worksflow (n0-computer#862)
  tests: Increase local slow-tests timeout (n0-computer#860)
  fix(proto): keep unread data when compacting an unordered stream (n0-computer#867)
  fix(proto): coalesce contiguous chunks during defragment (n0-computer#866)
  deps: Bump tokio for RUSTSEC-2026-0386 (n0-computer#868)
  feat(proto): Implement `noq_proto::SendStream::set_affinity` (n0-computer#836)
  fix(ci): bump deps for illumos (n0-computer#856)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

proto: route the std-only float math through the crate root

2 participants