-
Notifications
You must be signed in to change notification settings - Fork 194
Binary/octal/hexadecimal string support #414
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
Conversation
I still need to add some tests for the new stuff and debug. This is not quite ready yet, but if you have any comments, feel free to state them. If anyone else wants to add tests for this, I am open to that as well. |
146ff70
to
c2711ea
Compare
I have not reviewed everything yet, but a first observation is that all the convenience methods are unnecessary. This is not user-facing code. The extra base keyword argument to A small optimization: in the line |
This is a response to issue mpmath#345. Also note that the functions to_bstr and from_bstr have been replaced by to_str_p2 (along with to_bin) and from_bin
b9fe7a5
to
91ef47e
Compare
I removed some of the convenience methods and did a few other things. Still need to add more tests |
At least all of the regular tests pass now |
…into HexRepresentation345
@warnerjon12, could you merge the master branch to trigger CI build? |
to_digits_exp, to_str, to_bin, to_oct, to_hex, str_to_man_exp, | ||
from_str, from_bin, from_oct, from_hex, mpf_sqrt, mpf_hypot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it was noted by Fredrik, there is no need for additional methods
return sign, digits, exponent | ||
|
||
def to_str(s, dps, strip_zeros=True, min_fixed=None, max_fixed=None, | ||
show_zero_exponent=False): | ||
def to_str(s, ps, strip_zeros=True, min_fixed=None, max_fixed=None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? In fact, this is an API change: to_str() seems to be a public function.
There are test failures with gmpy2. |
def to_str_p2(x, base=2): | ||
sign, man, exp, bc = x | ||
return ['','-'][sign] + numeral(man, size=bitcount(man)//base_exp[base], \ | ||
base=base) + ("p%i" % exp) | ||
|
||
def str_to_man_exp(x, base=10): | ||
"""Helper function for from_str.""" | ||
x = x.lower().rstrip('l') | ||
# Verify that the input is a valid float literal | ||
float(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not work for hexadecimal strings.
base=2**n and base=10 are supported so far. to/from_bstr() undocumented helper functions are removed. Partially taken from mpmath#414. Co-authored-by: Jonathan Warner <warnerjon12@gmail.com>
base=2**n and base=10 are supported so far. to/from_bstr() undocumented helper functions are removed. Partially taken from mpmath#414. Co-authored-by: Jonathan Warner <warnerjon12@gmail.com>
base=2**n and base=10 are supported so far. to/from_bstr() undocumented helper functions are removed. Partially taken from mpmath#414. Co-authored-by: Jonathan Warner <warnerjon12@gmail.com>
base=2**n and base=10 are supported so far. float(), float.fromhex() and MPFR's style (see mpfr_strtofr() function) string formats are accepted. to/from_bstr() undocumented helper functions were removed. Partially taken from mpmath#414. Co-authored-by: Jonathan Warner <warnerjon12@gmail.com>
Ok, #703 will include Lets close this stale pr. Feel free to address pr review comments and re-open the pr. |
base=2**n and base=10 are supported so far. float(), float.fromhex() and MPFR's style (see mpfr_strtofr() function) string formats are accepted. to/from_bstr() undocumented helper functions were removed. Partially taken from mpmath#414. Co-authored-by: Jonathan Warner <warnerjon12@gmail.com>
base=2**n and base=10 are supported so far. float(), float.fromhex() and MPFR's style (see mpfr_strtofr() function) string formats are accepted. to/from_bstr() undocumented helper functions were removed. Partially taken from mpmath#414. Co-authored-by: Jonathan Warner <warnerjon12@gmail.com>
base=2**n and base=10 are supported so far. float(), float.fromhex() and MPFR's style (see mpfr_strtofr() function) string formats are accepted. to/from_bstr() undocumented helper functions were removed. Partially taken from mpmath#414. Co-authored-by: Jonathan Warner <warnerjon12@gmail.com>
Adapted from mpmath#414. Closes mpmath#345 Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com> * this version doesn't touch argument names (dps->ps) * no support for float.hex()-style binary exponents
Adapted from mpmath#414. Closes mpmath#345 Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com> * this version doesn't touch argument names (dps->ps) * no support for float.hex()-style binary exponents
Adapted from mpmath#414. Partial fix for mpmath#345 Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com> * this version doesn't touch argument names (dps->ps) * no support for float.hex()-style binary exponents
Adapted from mpmath#414. Partial fix for mpmath#345 Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com> * this version doesn't touch argument names (dps->ps) * no support for float.hex()-style binary exponents
Response to issue #345.
Closes #345