Skip to content

Conversation

warnerjon12
Copy link
Contributor

@warnerjon12 warnerjon12 commented Oct 18, 2018

Response to issue #345.

Closes #345

@warnerjon12
Copy link
Contributor Author

warnerjon12 commented Oct 18, 2018

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.

@warnerjon12 warnerjon12 force-pushed the HexRepresentation345 branch 3 times, most recently from 146ff70 to c2711ea Compare October 18, 2018 19:51
@fredrik-johansson
Copy link
Collaborator

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 to_str etc. should be sufficient.

A small optimization: in the line while i >= 0 and digits[i] == stddigits[base-1]: pull out stddigits[base-1] so that this doesn't have to be executed each iteration.

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
@warnerjon12 warnerjon12 force-pushed the HexRepresentation345 branch 2 times, most recently from b9fe7a5 to 91ef47e Compare October 19, 2018 23:07
@warnerjon12
Copy link
Contributor Author

I removed some of the convenience methods and did a few other things. Still need to add more tests

@warnerjon12
Copy link
Contributor Author

At least all of the regular tests pass now

@skirpichev
Copy link
Collaborator

@warnerjon12, could you merge the master branch to trigger CI build?

Comment on lines +14 to +15
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)
Copy link
Collaborator

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,
Copy link
Collaborator

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.

@skirpichev skirpichev closed this May 11, 2023
@skirpichev skirpichev reopened this May 11, 2023
@skirpichev
Copy link
Collaborator

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)
Copy link
Collaborator

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.

skirpichev added a commit to skirpichev/mpmath that referenced this pull request May 19, 2023
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>
skirpichev added a commit to skirpichev/mpmath that referenced this pull request May 21, 2023
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>
skirpichev added a commit to skirpichev/mpmath that referenced this pull request May 21, 2023
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>
@skirpichev skirpichev mentioned this pull request May 22, 2023
skirpichev added a commit to skirpichev/mpmath that referenced this pull request Jun 3, 2023
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>
@skirpichev
Copy link
Collaborator

Ok, #703 will include from_str()-stuff from this pr.

Lets close this stale pr. Feel free to address pr review comments and re-open the pr.

@skirpichev skirpichev closed this Jun 3, 2023
skirpichev added a commit to skirpichev/mpmath that referenced this pull request Jun 3, 2023
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>
skirpichev added a commit to skirpichev/mpmath that referenced this pull request Jun 3, 2023
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>
skirpichev added a commit to skirpichev/mpmath that referenced this pull request Jun 3, 2023
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>
skirpichev pushed a commit to skirpichev/mpmath that referenced this pull request Jun 28, 2023
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
skirpichev pushed a commit to skirpichev/mpmath that referenced this pull request Oct 7, 2023
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
skirpichev pushed a commit to skirpichev/mpmath that referenced this pull request Oct 7, 2023
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
skirpichev pushed a commit to skirpichev/mpmath that referenced this pull request Feb 22, 2024
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
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.

hex representation
3 participants