Skip to content

Pipe ceil, trunc and floor through round - #200

Draft
lgoettgens wants to merge 5 commits into
JuliaMath:masterfrom
lgoettgens:lg/invalidations-trunc-ceil-floor
Draft

lgoettgens wants to merge 5 commits into
JuliaMath:masterfrom
lgoettgens:lg/invalidations-trunc-ceil-floor

Conversation

@lgoettgens

@lgoettgens lgoettgens commented Feb 23, 2026 •

Copy link
Copy Markdown
Collaborator

similar to how it is done in julia Base. Also make use of the generic methods from Base where possible, to avoid invalidations.
This PR reduces the number of invalidations of loading DecFP from 517 to 437 (on julia 1.12.5). In particular, the following invalidation trees get resolved:

 inserting floor(::Type{Int64}, x::Dec128) @ DecFP ~/code/julia/DecFP.jl/src/DecFP.jl:552 invalidated:
   backedges: 1: superseding floor(::Type{T}, x) where T @ Base rounding.jl:475 with MethodInstance for floor(::Type{Int64}, ::Any) (3 children)

 inserting ceil(::Type{Int64}, x::Dec128) @ DecFP ~/code/julia/DecFP.jl/src/DecFP.jl:553 invalidated:
   backedges: 1: superseding ceil(::Type{T}, x) where T @ Base rounding.jl:476 with MethodInstance for ceil(::Type{Int64}, ::Any) (30 children)

 inserting ceil(::Type{I}, x::DecFP.DecimalFloatingPoint) where I<:Integer @ DecFP ~/code/julia/DecFP.jl/src/DecFP.jl:576 invalidated:
   backedges: 1: superseding ceil(::Type{T}, x) where T @ Base rounding.jl:476 with MethodInstance for ceil(::Type{Integer}, ::Any) (59 children)

Rebased on current master: 174 → 71 on julia 1.12.7, 12 → 9 on julia 1.13.3.

@codecov

codecov Bot commented Feb 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.01%. Comparing base (5ec7f57) to head (d6e5aed).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #200      +/-   ##
==========================================
+ Coverage   97.35%   98.01%   +0.66%     
==========================================
  Files           2        2              
  Lines         606      606              
==========================================
+ Hits          590      594       +4     
+ Misses         16       12       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lgoettgens lgoettgens closed this Aug 31, 2026
@lgoettgens lgoettgens reopened this Aug 31, 2026
@ViralBShah

Copy link
Copy Markdown
Member

The Julia 1.7 failures were because the generic trunc/floor/ceil(::Type{T}, x) = round(T, x, mode) fallbacks in Base only exist since Julia 1.11 (JuliaLang/julia#50812). I pushed a commit that adds those three methods for DecimalFloatingPoint under @static if VERSION < v"1.11", restricted to T<:Integer to avoid an ambiguity with Base.ceil(::Type{T<:Integer}, ::AbstractFloat) on older versions. Tests pass locally on 1.9, 1.10 and 1.12.

@lgoettgens
lgoettgens force-pushed the lg/invalidations-trunc-ceil-floor branch from c50d4ee to 50a890c Compare November 9, 2026 11:12
@ViralBShah

Copy link
Copy Markdown
Member

Do you have commit access here?

@lgoettgens

Copy link
Copy Markdown
Collaborator Author

Do you have commit access here?

Yes, you invited me a few weeks ago.

I haven't merged it yet, as I want to let Claude check all my pre-AI PRs, and I haven't come to this one yet.

@lgoettgens
lgoettgens marked this pull request as draft November 9, 2026 14:38
@lgoettgens
lgoettgens force-pushed the lg/invalidations-trunc-ceil-floor branch from 50a890c to e3e9c91 Compare November 23, 2026 16:35
@lgoettgens
lgoettgens force-pushed the lg/invalidations-trunc-ceil-floor branch from e3e9c91 to dac8c8f Compare December 4, 2026 11:06
lgoettgens and others added 5 commits December 4, 2026 15:07
The generic Base fallbacks trunc/floor/ceil(::Type{T}, x) = round(T, x, mode)
were only added in Julia 1.11 (JuliaLang/julia#50812), so the previous commit
broke these calls on 1.7-1.10. Restrict to T<:Integer to avoid an ambiguity
with Base's ceil(::Type{T<:Integer}, ::AbstractFloat) on older versions.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014GD7jbSks8x6h6QThUrhk3
The generic `round` fallback for `Int128`, `BigInt` etc. reported
`:round` for every mode, unlike master and the fast paths.

Assisted-by: Claude Code (Opus 5.5)
The generic integer fallback builds `Bool(10)` and fails; JuliaMath#210
relied on the `round` → `trunc`/`floor`/`ceil` methods removed here.

Assisted-by: Claude Code (Opus 5.5)
@lgoettgens
lgoettgens force-pushed the lg/invalidations-trunc-ceil-floor branch from 7838f5f to d6e5aed Compare December 4, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants