Skip to content

Implement 'a'/'A' formating types for mpf.__format__#841

Merged
skirpichev merged 1 commit intompmath:masterfrom
skirpichev:format-hex
Sep 8, 2024
Merged

Implement 'a'/'A' formating types for mpf.__format__#841
skirpichev merged 1 commit intompmath:masterfrom
skirpichev:format-hex

Conversation

@skirpichev
Copy link
Copy Markdown
Collaborator

@skirpichev skirpichev commented Aug 17, 2024

See #337

@skirpichev skirpichev force-pushed the format-hex branch 3 times, most recently from 8b79d83 to 928f216 Compare August 21, 2024 04:34
@skirpichev
Copy link
Copy Markdown
Collaborator Author

See also python/cpython#113804. Potentially, we could reuse 'x'/'X' format codes, but I think it's a good idea to be compatible with gmpy2 (and C) here.

@javierelpianista ?

@skirpichev skirpichev marked this pull request as ready for review August 22, 2024 09:59
@javierelpianista
Copy link
Copy Markdown
Contributor

I

See also python/cpython#113804. Potentially, we could reuse 'x'/'X' format codes, but I think it's a good idea to be compatible with gmpy2 (and C) here.

@javierelpianista ?

Yes, I think it's better to use 'a' and 'A'.

@javierelpianista
Copy link
Copy Markdown
Contributor

I'm not a specialist in hex numbers but gmpy2 gives a different output than the one in test_format.py:

>>> import gmpy2
>>> gmpy2.get_context().precision = 5300
>>> print(f"{gmpy2.mpfr('1.234567890123456789'):.20a}") # This one is the same as gmpy2
0x1.3c0ca428c59fb71a4194p+0
>>> print(f"{gmpy2.mpfr('1.234567890123456789'):.0a}") # This one is different
0xap-3

whereas, according to the tests you wrote, the latter one should return "0x1p+0". Similar for the other two tests.

@skirpichev
Copy link
Copy Markdown
Collaborator Author

print(f"{gmpy2.mpfr('1.234567890123456789'):.0a}") # This one is different

It's not. The mpmath always use 1-normalization for normal numbers, while in the MPFR - the digit before decimal dot should be just non-zero. This is something they wish to fix, but... See https://sympa.inria.fr/sympa/arc/mpfr/2021-05/msg00002.html

@skirpichev skirpichev force-pushed the format-hex branch 2 times, most recently from b9e4d93 to 0098455 Compare August 26, 2024 06:32
@skirpichev skirpichev mentioned this pull request Aug 27, 2024
@skirpichev skirpichev force-pushed the format-hex branch 2 times, most recently from 6b24b5b to 6e8326a Compare September 2, 2024 02:06
@skirpichev skirpichev force-pushed the format-hex branch 2 times, most recently from cfeb6c4 to f1427a4 Compare September 7, 2024 03:33
@skirpichev skirpichev merged commit 1c76b02 into mpmath:master Sep 8, 2024
@skirpichev skirpichev deleted the format-hex branch September 8, 2024 04:46
@skirpichev skirpichev added this to the 1.4 milestone May 9, 2025
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