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
decimal.py: logb: round the result if it is greater than prec #51297
Comments
>>> from decimal import *
>>> c = getcontext()
>>> c.prec = 2
>>> c.logb(Decimal("1E123456"))
Decimal('123456')
>>> This result agrees with the result of decNumber, but the spec says: My interpretation is that the result should be 1.2E+5. |
Hmm. The problem here is that the specification says nothing at all Rather than rounding, I'd say that a more useful result in this case Maybe we should ask Mike Cowlishaw what the intended behaviour here is? IEEE 754-2008 (section 5.3.3) requires that languages define a |
(Stefan emailed Mike Cowlishaw about this: thanks, Stefan!) Mike's initial response suggests that we *should* be rounding the result |
Attaching additional testcases from Mike Cowlishaw. |
Mike's response makes sense to me. If the precision is 2, the result |
Patch to update to the most recent official set of tests. With this patch, logb and scaleb fail. |
Patch to fix logb. |
I don't understand the new scaleb testcases (from Mike). They look like precision: 34 The specification says that the second operand should be in the range |
The IEEE 754-2008 description of scaleB makes a lot more sense, IMO: The restriction in the specification seems arbitrary and questionable. |
Applied the fix for logb in r75275 (trunk), r75276 (py3k) and r75277 |
precision: 34 I would say that this is implementation specific, as a workaround for |
I've updated to the newest version of the test-suite in r75285 through I'm currently skipping those two scaleb tests, until we work out what |
I just want to note another problem with logb: it doesn't use the correct |
Sorry; ignore that last. I was confused by the fact that the _check_nans |
logb fix applied to release26-maint in r75804. |
Updated release26-maint to new test-suite in r75806. |
There's a restriction on the second argument to scaleb in the spec, This restriction seems entirely arbitrary and unnecessary to me. My Here's a patch that removes this restriction on scaleb in the Python |
Mike Cowlishaw has confirmed that the tests scbx164, scbx165 (in version I don't think it's worth removing the restriction on the 2nd scaleb |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: