Repository navigation
Conversation
The suffix tables are indexed with value % 10 (and the 11/12/13
special case with value % 100), but Python's modulo maps negative
numbers outside those ranges: -1 % 10 == 9, so every negative number
got the generic 'th' suffix:
>>> ordinal(-1)
'-1th'
>>> ordinal(-101)
'-101th'
Select the suffix on the absolute value so negative ordinals get the
same suffix as their positive counterparts ('-1st', '-101st').
Collaborator
|
Wrong repo, but a duplicate of many others. |
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.
Summary
ordinalindexes its suffix tables withvalue % 10(and the 11/12/13 special case withvalue % 100), but Python's modulo maps negative numbers outside those ranges —-1 % 10 == 9— so every negative number gets the genericthsuffix:The fix selects the suffix on the absolute value, so negative ordinals get the same suffix as their positive counterparts while keeping the sign in the output.
Verification
-1/-2/-3/-4/-11/-111/-101params totest_ordinal; 4 of them fail on master ('-3th' == '-3rd'etc.) and all pass with this change.pytest tests/test_number.py→ 108 passed, no regressions.AI Disclosure
This PR was prepared with the assistance of an AI coding agent.
ZCode (GLM-based coding agent)