Skip to content

Conversation

@Joel-Dahne
Copy link
Collaborator

This implements round for Arf, Acf, Arb and Acb as well as conversion to general integer types (not only Int and BigInt). It also implements div for Arb. In theory one could implement div for Arf, but getting that to be correctly rounded (which the div function does specify) seems like it could be a little bit of work and I therefore left it out.

The motivation for this is discussed in #206.

There is still some work to be done, for example there are currently not any tests...

@Joel-Dahne
Copy link
Collaborator Author

It seems like there is some work with getting the ambiguity tests to pass as well...

@Joel-Dahne Joel-Dahne force-pushed the rounding branch 2 times, most recently from 3d3668f to cd6ea60 Compare April 6, 2025 21:24
@Joel-Dahne
Copy link
Collaborator Author

I finally got around to finishing this. I simplified some of the implementations and added tests for everything. I also added a test to make sure that Arb(1):Arb(10) actually works, since this was the initial motivation for this PR.

When implementing the tests for RoundNearest I ran into some issues, that turned out to be due to a bug in Flint. The bug has now been fixed in Flint, but while we wait for a new release I added a temporary implementation which is correct but not optimal (it is a fixed version of the original implementation in Flint, the fixed version in Flint uses a slightly different approach).

Some of the tests are however failing on Julia v1.6. It seems like some of the handling of rounding has been added in later version, and hence are not supported on 1.6. For example round(1.5, RoundFromZero) doesn't work on 1.6 and the definitions

trunc(::Type{T}, x) where T = round(T, x, RoundToZero)
floor(::Type{T}, x) where T = round(T, x, RoundDown)
 ceil(::Type{T}, x) where T = round(T, x, RoundUp)

also seem to not exist in 1.6, leading to floor(Int, Arb(1.5)) not working. Working around all of this would probably take some effort. Maybe this is a good time to drop support for 1.6 in favor of 1.10 (which is the current LTS)?

@Joel-Dahne Joel-Dahne marked this pull request as ready for review April 6, 2025 21:42
@Joel-Dahne
Copy link
Collaborator Author

I rebased this on top of #211 to make sure that everything works as expected on nightly. So this would now have to be rebased once #211 is merged.

@kalmarek
Copy link
Owner

@Joel-Dahne Thanks for all of those changes and staying up to date with julia-nightly ;)

@Joel-Dahne Joel-Dahne merged commit 158e5bc into master May 18, 2025
13 checks passed
@Joel-Dahne Joel-Dahne deleted the rounding branch May 18, 2025 20:59
@kalmarek
Copy link
Owner

@Joel-Dahne minor release?

@Joel-Dahne
Copy link
Collaborator Author

I'm currently looking at making setprecision use ScopeValue. I think making a release once that is finished (hopefully soon) would be a good idea!

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.

3 participants