Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added min_fixed and max_fixed options for Float in printers #18477

Merged
merged 6 commits into from
Jan 29, 2020

Conversation

mijo2
Copy link
Contributor

@mijo2 mijo2 commented Jan 27, 2020

References to other Issues or PRs

Fixes #7847

Brief description of what is fixed or changed

--> Exposed min_fixed and max_fixed options for printers to print floating point numbers

Other comments

Example:

>>> from sympy import *
>>> from sympy.printing.str import StrPrinter
>>> StrPrinter({'full_prec': False, 'min': -2, 'max':2}).doprint(Float('10000000', 5))
'1.0e+7'
>>> StrPrinter({'full_prec': False, 'min': -2, 'max':2}).doprint(Float('10000000'))
'1.0e+7'
>>> StrPrinter({'full_prec': False, 'min': -2, 'max':8}).doprint(Float('10000000'))
'10000000.0'
>>> StrPrinter({'full_prec': False, 'min': -2, 'max':7}).doprint(Float('10000000'))
'1.0e+7'
>>> StrPrinter({'full_prec': False, 'min': -2, 'max':7}).doprint(Float('0.45'))
'0.45'
>>> StrPrinter({'full_prec': False, 'min': -1, 'max':7}).doprint(Float('0.45'))
'4.5e-1'
>>> 

As you can see, the bounds are exclusive.

Release Notes

  • printing
    • Added min and max options for printers to set a range for floating point numbers that can
      be printed in fixed-point format.

Mpmath module has min_fixed and max_fixed options for printing
floating point numbers and in this commit, these options are
exposed for StrPrinter, LatexPrinter and all its subclasses
@sympy-bot
Copy link

sympy-bot commented Jan 27, 2020

Hi, I am the SymPy bot (v149). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

Your release notes are in good order.

Here is what the release notes will look like:

  • printing
    • Added min and max options for printers to set a range for floating point numbers that can
      be printed in fixed-point format. (#18477 by @mijo2)

This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.6.

Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it.

Click here to see the pull request description that was parsed.

#### References to other Issues or PRs

Fixes #7847 

#### Brief description of what is fixed or changed

--> Exposed min_fixed and max_fixed options for printers to print floating point numbers

#### Other comments

Example:
```
>>> from sympy import *
>>> from sympy.printing.str import StrPrinter
>>> StrPrinter({'full_prec': False, 'min': -2, 'max':2}).doprint(Float('10000000', 5))
'1.0e+7'
>>> StrPrinter({'full_prec': False, 'min': -2, 'max':2}).doprint(Float('10000000'))
'1.0e+7'
>>> StrPrinter({'full_prec': False, 'min': -2, 'max':8}).doprint(Float('10000000'))
'10000000.0'
>>> StrPrinter({'full_prec': False, 'min': -2, 'max':7}).doprint(Float('10000000'))
'1.0e+7'
>>> StrPrinter({'full_prec': False, 'min': -2, 'max':7}).doprint(Float('0.45'))
'0.45'
>>> StrPrinter({'full_prec': False, 'min': -1, 'max':7}).doprint(Float('0.45'))
'4.5e-1'
>>> 
```
As you can see, the bounds are exclusive.

#### Release Notes

<!-- BEGIN RELEASE NOTES -->
* printing
  * Added min and max options for printers to set a range for floating point numbers that can\
    be printed in fixed-point format.
<!-- END RELEASE NOTES -->

Update

The release notes on the wiki have been updated.

@sylee957
Copy link
Member

sylee957 commented Jan 27, 2020

I'd agree to add this to string printers,
I'm not sure that it's useful for code printers unless it's about printing human-readable code.

@mijo2
Copy link
Contributor Author

mijo2 commented Jan 27, 2020

Ok @sylee957, I will add min_fixed and max_fixed options only for Latex printers and string printers.

@codecov
Copy link

codecov bot commented Jan 27, 2020

Codecov Report

Merging #18477 into master will decrease coverage by 21.731%.
The diff coverage is 100%.

@@              Coverage Diff               @@
##            master    #18477        +/-   ##
==============================================
- Coverage   75.323%   53.592%   -21.732%     
==============================================
  Files          637       640         +3     
  Lines       167068    167185       +117     
  Branches     39416     39429        +13     
==============================================
- Hits        125842     89599     -36243     
- Misses       35692     71744     +36052     
- Partials      5534      5842       +308

Restricting the min and max options for printing floating point numbers
to string and latex printers
In this commit, some of the options were left unedited that were supposed
to be removed in the last commit. This commit fixes that.
Updates to docstring of rust.py in first commit were removed and
safe check in getting low and high values was added in latex pri-
-nters code
@mijo2 mijo2 requested a review from sylee957 January 27, 2020 10:54
@asmeurer
Copy link
Member

This needs tests.

I wouldn't put this in the code printers. For the code printers, it is more important to print the exact float value so precision isn't lost. Different parameters might exist to approximate float literals in the code printers, but those would work differently than these, which are based on visual output rather than mathematical rounding.

@mijo2
Copy link
Contributor Author

mijo2 commented Jan 27, 2020

@asmeurer thanks for your feedback! I have already removed the options from codeprinters. I will start making test cases for latex printers and string printers and will add them soon along with updating the docstring for adding this feature.

For testing the new functionality added for Float printing, tests
are added in sympy.printing
@mijo2
Copy link
Contributor Author

mijo2 commented Jan 28, 2020

@asmeurer I have added the tests for string printers as of now. Working on tests for latex printers.

In this commit, tests for checking the printing of float numbers
by latex printers were added and some minor changes to latex.py
was made.
@mijo2 mijo2 requested review from sylee957 and removed request for oscarbenjamin and sylee957 January 29, 2020 08:50
@mijo2
Copy link
Contributor Author

mijo2 commented Jan 29, 2020

@asmeurer I have added the tests for latex printers as well.

@sylee957 @asmeurer You can review this now to check if anything else needs to be changed or added. Thanks.

@sylee957 sylee957 merged commit 53733f0 into sympy:master Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to set min_fixed and max_fixed for Float in the printers
5 participants