Repository navigation
Conversation
Three defects in LogNode: - A zero value passed the two-argument domain checks, which tested value < 0, so math.log(0, 2) returned -inf. - The one-argument specializations took any PNone, so an explicit base of None was treated as omitted and math.log(10, None) returned the natural logarithm. - The specializations for a non-number base converted the base before checking the value, so math.log(-1, object()) raised TypeError. CPython checks the value, then converts the base, and raises ValueError for any value <= 0. Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
logPIO also needs the missing-base guard; assert that math.log on a large int still works after math.log(2**70, None). Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #1253
LogNodehad three gaps in its argument checks. The specializations that take a base tested the value with< 0, so a zero value returned-inf. The one-argument specializations took the base as an unguardedPNone, soNonewas treated as a missing base. The specializations for a non-number base converted it before the value was checked. CPython'smath_logcomputeslog(x)first, rejecting anyx <= 0, and only then converts the second argument, whatever it is (mathmodule.c#L2269-L2273).AS-IS
TO-BE
(matching CPython)
Changes
<= 0inlogPIN,logDD,logDPI,logPID,logLPIandlogPIPI, aslogDNalready does.log(long, PNone),logDN,logPINandlogOwithisNoValue(novalue), soNonegoes to the specializations that convert the base.logOO,logLO,logDOandlogPIObefore converting the base, and add!isNoValue(base)tologLO,logDOandlogPIO, aslogOOhas. Without that guard, once aNonebase had activated one of them, a latermath.log(10)was dispatched there and raisedTypeError.tests/test_math_log.py.Testing
mx python-jvmon darwin-aarch64, thenmx graalpytest test_math_log.py(3 passed) andtest_math.py(61 passed), andtest.test_mathfromlib-pythonwith--tagged(79 passed). The new tests fail on the unpatched build (2 failures, 1 error). 25math.logcall shapes, coveringintsubclasses,None,object()and__float__arguments, now print the same as CPython 3.13.14, except for a last-digit difference inmath.log(8.0, 2**70)that master has too.