Expand std:fmath with sqrt, trig, exp/log, rounding, and constants #468
Labels
No labels
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
refactor
rust
technical-debt
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
navicore/patch-seq#468
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
std:fmathcurrently exposes only a small set of float ops —f.abs,f.min,f.max,f.sign,f.square,f.clamp,f.neg. The rest of the standard floating-point math surface (sqrt, trig, exp/log, rounding, common constants) is missing.This is a real gap, not a duplicate of
std:imath: most of these functions are inherently float-valued and have no meaningful integer analogue.Functions to add
Square / power / root:
f.sqrt ( Float -- Float )f.cbrt ( Float -- Float )f.pow ( Float Float -- Float )—base exp powExponential / logarithmic:
f.exp ( Float -- Float )— e^xf.ln ( Float -- Float )— natural logf.log10 ( Float -- Float )f.log2 ( Float -- Float )(nice-to-have)Trigonometric:
f.sin ( Float -- Float )f.cos ( Float -- Float )f.tan ( Float -- Float )f.asin ( Float -- Float )f.acos ( Float -- Float )f.atan ( Float -- Float )f.atan2 ( Float Float -- Float )—y x atan2Rounding:
f.floor ( Float -- Float )f.ceil ( Float -- Float )f.round ( Float -- Float )(banker's rounding or half-away-from-zero — pick one and document)f.trunc ( Float -- Float )(nice-to-have, matchesfloat->intsemantics in Float space)Constants:
f.pi ( -- Float )— 3.14159...f.e ( -- Float )— 2.71828...f.tau ( -- Float )(nice-to-have, = 2π)Why
These are bread-and-butter floating-point ops. Without them, you can't write graphics math, physics simulations, signal processing, statistics, or even simple things like
hypotenuseordegrees-to-radians.Implementation
All of these have direct one-liner mappings to
f64::sqrt,f64::sin,f64::ln,f64::round, etc. in Rust's stdlib, so the runtime cost is just FFI plumbing. NaN/Infinity propagate per IEEE 754, matching the existingstd:fmathdoc note.Cross-reference
Blocking seqlings chapter 28 (
28-std-fmath), which currently references all of the above and won't compile against the real stdlib. The chapter is being held until this lands.#469