Skip to content

Add hypothesis-based formatting tests and workaround #858#859

Merged
skirpichev merged 4 commits intompmath:masterfrom
skirpichev:fix-858-and-tests
Sep 6, 2024
Merged

Add hypothesis-based formatting tests and workaround #858#859
skirpichev merged 4 commits intompmath:masterfrom
skirpichev:fix-858-and-tests

Conversation

@skirpichev
Copy link
Copy Markdown
Collaborator

@skirpichev skirpichev commented Sep 1, 2024

@skirpichev skirpichev marked this pull request as ready for review September 1, 2024 06:57
@javierelpianista javierelpianista mentioned this pull request Sep 1, 2024
@javierelpianista
Copy link
Copy Markdown
Contributor

javierelpianista commented Sep 1, 2024

This is better but still fails in some cases, for example,

>>> format(mp.mpf('0.99'), '.1f')
'1.'
>>> format(mp.mpf('0.999'), '.2f')
'1.0'

The reason is that to_digits_exp not always produces a string of 9s.
For example,

>>> to_digits_exp(mp.mpf(0.99)._mpf_, 15)
('', '989999999999999991', -1)
>>> to_digits_exp(mp.mpf(0.999)._mpf_, 15)
('', '998999999999999999', -1)

The solution is to improve the hack to take into account the cases where the last rounded digit is not a 9, but one of the digits that would be rounded up.
I've made a separate PR for this. #860

@skirpichev
Copy link
Copy Markdown
Collaborator Author

I've made a separate PR for this

Thanks, I've cherry-picked some commits from that pr and did some cleanup for the fix.

@skirpichev

This comment was marked as outdated.

skirpichev and others added 4 commits September 3, 2024 11:27
Fix also few other minor issues, coming from tests.

Closes mpmath#858

Co-authored-by: Javier Garcia <javier.garcia.tw@hotmail.com>
Should be useful for formatting complex numbers
@skirpichev
Copy link
Copy Markdown
Collaborator Author

I did rebase. Now first commit include fix for #858, including #860. The 'g' format also fixed.

@skirpichev
Copy link
Copy Markdown
Collaborator Author

@javierelpianista, are you ok with this or prefer #860?

@javierelpianista
Copy link
Copy Markdown
Contributor

@javierelpianista, are you ok with this or prefer #859

I'm OK with this!

@skirpichev skirpichev merged commit f36220e into mpmath:master Sep 6, 2024
@skirpichev skirpichev deleted the fix-858-and-tests branch September 6, 2024 12:05
@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.

format(mp.mpf(0.99999), '.4f') returns '0.99999'

2 participants