Skip to content

Mpzf small improvements - #9808

Open
mglisse wants to merge 5 commits into
CGAL:mainfrom
mglisse:mpzf-fix
Open

mglisse wants to merge 5 commits into
CGAL:mainfrom
mglisse:mpzf-fix

Conversation

@mglisse

@mglisse mglisse commented Oct 30, 2026

Copy link
Copy Markdown
Member

Summary of Changes

Each commit has a separate change, to make it easier to follow. The first patch was motivated by @BrunoLevy (thanks!).
These changes do not affect the use of Mpzf in Epick, but they can be relevant for other uses.
I was also thinking of improving to_double (make it correctly rounded?), but motivation stopped, so maybe some other time.

Release Management

  • Affected package(s): Number_types
  • License and copyright ownership: unchanged

Questionable whether this is needed, but it is cheap and avoids some
accidents.
It is safe on all the compilers we support, but the version with memcpy
and shift avoids explicit handling of byte order.
@afabri

afabri commented Nov 17, 2026

Copy link
Copy Markdown
Member

In one commit you write "fix", Is there a small cpp to show the problem?

@mglisse

mglisse commented Nov 17, 2026

Copy link
Copy Markdown
Member Author
#define CGAL_USE_GMPXX
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <iostream>
#include <cassert>

int main(){
  mpz_class z=-1;
  CGAL::Mpzf f=z;
  assert(f<0);
}

The assertion fails with current master (it doesn't copy the sign). I think you get the same error with Gmpz instead of mpz_class. The main use case for Mpzf in CGAL only has constructions from double (and maybe a few int) so this hasn't shown up before.

@afabri

afabri commented Nov 17, 2026

Copy link
Copy Markdown
Member

I guess you are confident in the code and we can consider four eyes having had a look at it, as you mention Bruno, or do you expect a review?
The assertion below should be added to the testsuite of Number_types. Can you do that?

@mglisse

mglisse commented Nov 18, 2026

Copy link
Copy Markdown
Member Author

I guess you are confident in the code

Bugs are always possible... Bit manipulations can be tricky, and off-by-1 errors can appear quite easily.

and we can consider four eyes having had a look at it, as you mention Bruno,

Bruno reported some of the issues, but never looked at the patch.

or do you expect a review?

As you prefer.

The assertion below should be added to the testsuite of Number_types. Can you do that?

Doesn't feel super useful, but ok...

@BrunoLevy

Copy link
Copy Markdown

Hi guys, I can take a look if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants