Skip to content

Convert bases to 36 exactly, and refuse a digit not in the base - #2351

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
base-conversion-to-thirty-six-and-exact
Nov 3, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
base-conversion-to-thirty-six-and-exact

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Closes #2343. Closes #2344.

2.6.0 and master now
MathS.FromBaseN("80000000", 16) -2147483648 2147483648
MathS.FromBaseN("10000000000", 10) 2147483647 10000000000
MathS.FromBaseN("102", 2) 6 InvalidNumericSystemException
MathS.FromBaseN("ff", 16) KeyNotFoundException 255
MathS.FromBaseN("G", 17) KeyNotFoundException 16
MathS.ToBaseN(35, 36) InvalidNumericSystemException Z
MathS.ToBaseN(1/7, 7) 121 characters, the last digit wrong 0.1
MathS.ToBaseN(1/3, 3) 0.0222…2, 210 digits 0.1
  • FromBaseN adds the whole part by Horner's rule in EInteger, sums the fraction exactly as a rational, and rounds once into the precision context. A digit that is not below the base, a character that is not a digit, an empty string and a base outside 2 to 36 throw InvalidNumericSystemException.
  • The digits go to Z, read in either case. The catalogue's to_base and from_base, and the MCP server's am_represent, already said "a base from 2 to 36".
  • ToBaseN of a Rational divides it out in the base, digit by digit, exactly. A real that is not rational goes through its decimal as before. A repeating expansion is still cut at the precision (0.333… to 100 digits in base 10), as Hangs on imprecise number base conversions #584 left it. The issue raises marking the period as an option, and that is a display decision this leaves open.

Tests: ABaseConversionToThirtySixTest, 25 cases. 20 fail on master; the 5 that already worked pass on both. The existing base tests and the documentation examples pass unchanged. The full suite, AOT and the nine harnesses pass. There is a BREAKING-CHANGES entry, measured on 2.6.0.

🤖 Generated with Claude Code

FromBaseN added its digits up in an int with (int)Math.Pow(N, i) for the
place value, so a number past 2^31 wrapped ("80000000" in base 16 was
-2147483648), and it looked each digit up without checking it against the
base ("102" in base 2 was 6). It adds them by Horner's rule in EInteger,
sums the fraction exactly and rounds once, and throws
InvalidNumericSystemException for a digit not below the base or a base
outside 2 to 36.

The digit table stopped at F, where the catalogue's to_base and from_base
and the MCP server's am_represent offer bases to 36: ToBaseN(35, 36) threw
and "ff" was a KeyNotFoundException. It goes to Z now, read in either
case.

And ToBaseN of a rational went through its decimal, rounded to the
precision and the rounding multiplied up digit by digit, so 1/7 in base 7
ran to 119 digits ending on a wrong one. A rational is divided out in the
base, exactly; a repeating expansion is cut where it was.

Closes #2343
Closes #2344

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Rafael-SOWNet Rafael-SOWNet added this to the 2.7.0 milestone Nov 3, 2026
@Rafael-SOWNet Rafael-SOWNet moved this to In review in AngouriMath Nov 3, 2026
@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.85714% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.77%. Comparing base (0731fc1) to head (debd7b5).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
Sources/AngouriMath/Functions/BaseConversion.cs 92.68% 1 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2351      +/-   ##
==========================================
- Coverage   86.78%   86.77%   -0.02%     
==========================================
  Files         312      312              
  Lines       68675    68733      +58     
  Branches    19988    20014      +26     
==========================================
+ Hits        59602    59643      +41     
- Misses       4905     4917      +12     
- Partials     4168     4173       +5     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.31% <92.85%> (-0.02%) ⬇️
fsharp 32.97% <ø> (ø)
interactive 40.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Sources/AngouriMath/Convenience/MathS.cs 90.51% <100.00%> (ø)
Sources/AngouriMath/Functions/BaseConversion.cs 88.50% <92.68%> (-3.56%) ⬇️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rafael-SOWNet
Rafael-SOWNet merged commit 339204f into master Nov 3, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Nov 3, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the base-conversion-to-thirty-six-and-exact branch November 3, 2026 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

1 participant