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

Don't use BigFloat.exact in repr output. #11

Open
mdickinson opened this issue Jun 29, 2014 · 4 comments
Open

Don't use BigFloat.exact in repr output. #11

mdickinson opened this issue Jun 29, 2014 · 4 comments

Comments

@mdickinson
Copy link
Owner

repr output for BigFloat objects should show the hex form of the float instead, since recreation is then unaffected by context. str can continue to show a decimal string.

@mdickinson mdickinson added this to the 0.4 milestone Sep 20, 2015
@mdickinson
Copy link
Owner Author

At the same time, disable the use of BigFloat.exact for strings: it's misleading.

@mdickinson
Copy link
Owner Author

We need to support various cases:

  1. Conversion from a decimal string, hex string, integer or float to the current context, taking into account the current rounding mode. This operation is provided by the regular BigFloat constructor.
  2. Context-independent conversion from a hex string with given precision in bits, as an inverse to the repr operation. The precision is necessary, since it can't be inferred uniquely from the hex form of the output (unless we use a nonstandard normalization). This could be provided by the BigFloat.exact constructor with a precision argument.
  3. Context-independent conversion from a hex string, float, or int, inferring the number of bits necessary to do an exact conversion. (Could also be extended to those decimal strings that are exactly representable in binary, with an error for strings not exactly representation in binary.) This could be provided by the BigFloat.exact constructor without a precision argument.

Proposed behaviour:

  • The output of repr should look like BigFloat.exact('0x1234p+1', precision=53).
  • The BigFloat.exact constructor should always require a precision.
  • The BigFloat.exact constructor should only accept values for which an exact conversion (with the given precision) can be performed. That excludes most decimal strings, for example.
  • The regular BigFloat constructor always uses the current context, as before.

@casevh
Copy link

casevh commented Nov 11, 2015

Do you even need exact? In gmpy2, mpfr currently accepts base and precision keywords. You could add an exact keyword that will raise an exception is the conversion is inexact. If no precision is specified, then try to determine a precision that is large enough to guarantee an exact conversion. (Ugly hack - I sort of do this already by associating a special meaning to precision=1. It works with float and integers but not hex strings.)

@mdickinson
Copy link
Owner Author

Moving this out of the 0.4.0 milestone.

@mdickinson mdickinson removed this from the 0.4 milestone Dec 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants