Expand std:fmath with sqrt, trig, exp/log, rounding, and constants #468

Closed
opened 2026-05-10 13:31:04 +00:00 by navicore · 1 comment
Owner

Summary

std:fmath currently 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 pow

Exponential / logarithmic:

  • f.exp ( Float -- Float ) — e^x
  • f.ln ( Float -- Float ) — natural log
  • f.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 atan2

Rounding:

  • 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, matches float->int semantics 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 hypotenuse or degrees-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 existing std:fmath doc 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.

## Summary `std:fmath` currently 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 pow` Exponential / logarithmic: - `f.exp ( Float -- Float )` — e^x - `f.ln ( Float -- Float )` — natural log - `f.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 atan2` Rounding: - `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, matches `float->int` semantics 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 `hypotenuse` or `degrees-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 existing `std:fmath` doc 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.
Author
Owner
https://git.navicore.tech/navicore/patch-seq/pulls/469
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
navicore/patch-seq#468
No description provided.