JuliaMath / JuliaMath/FixedPointNumbers.jl

Reducing the definitions of the `floor`, `ceil`, and `trunc` methods to mitigate invalidation

Open
#335 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
95
Forks
38
Avg merge
13m
Merged PRs (30d)
2

Description

At least as of julia v1.0, `floor(x)` has fallen back to `round(x, RoundDown)`.
Starting with julia v1.11, `floor(T, x)` has also been made to fall back to `round(T, x, RoundDown)`.(cf. https://github.com/JuliaLang/julia/pull/45598)

Therefore, it should be sufficient to define only `round(x, ::RoundingMode)` and `round(T, x, ::RoundingMode)` in FPN.
Conversely, starting with Julia v1.11, defining methods such as `floor(T, x)` may carry a higher risk of invalidation.
(As efforts related to TTFX within the Julia ecosystem are also advancing, it is unclear what impact this will have on actual performance.)

Of course, invalidation triggered by the 2-/3-arg `round` is, in principle, unavoidable.
However, I think it can be effective if the invalidation results from the casual (type-instable) use of functions like `floor`.

Since rounding functions like `floor` are expected to be inlined when there is no risk of overflow/underflow (e.g., `ceil(typemax(Q0f7))`), I don't think there will be much of a performance penalty.
It’s fragile against piracy and future changes to `Base` implementation, but I’m sure someone will notice and fix it.

Contributor guide

Open the contributing guide

Research direction

Locate the FPN definitions of floor, ceil, trunc, and round, then compare their behavior with Julia 1.11's fallback methods. The work is done when the redundant definitions are reduced without changing rounding behavior and the existing package checks confirm the result.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.