Skip to content

Write out numbers#327

Merged
tolik518 merged 8 commits intotolik518:masterfrom
Aras14HD:write-out
Mar 7, 2026
Merged

Write out numbers#327
tolik518 merged 8 commits intotolik518:masterfrom
Aras14HD:write-out

Conversation

@Aras14HD
Copy link
Collaborator

@Aras14HD Aras14HD commented Feb 27, 2026

DEPENDS ON #326 (Merged)

This adds the ability to write out numbers up to 9.9999999...*10^3000000.

It only writes out the most significant parts.

This is a breaking change in the library as the arguments for format change. To combat this in the future and make the signature less cluttered, I added a FormatOptions struct.

This is also only in english, as of this point. There would be a lot to add to locale, otherwise.

Resolves #150

@tolik518
Copy link
Owner

This is hilarious!
Could you write a test please how it behaves with other languages like russian and/or german?

From what I have seen so far the pr looks good, but now calculation_results.rs feels like it has more than I would expect from it, maybe move the logic for writing out to a dedicated file? What do you think?

Also I don't think I can remotely verify if

Factorial of one hundred seventy six thousand nine hundred two is seventy five quintriginoctingentrilloctogintillducentillillion five hundred fourty five quattuortriginoctingentrilloctogintillducentillillion seven hundred sixty six tretriginoctingentrilloctogintillducentillillion three hundred five duotriginoctingentrilloctogintillducentillillion fourty seven untriginoctingentrilloctogintillducentillillion one hundred fourty three triginoctingentrilloctogintillducentillillion

is correct, but I'll take it :D

@Aras14HD
Copy link
Collaborator Author

It would still write the number in english with everything around it localized. (if it's breaking anyway, I might add localization to it now)

Maybe a format for basic formatting functions like round truncate fromat_float get_factorial_level_string and write_out_number. With calculation_results just implementing methods of/traits for the types Calculation and CalculationResult.

And for the correctness, while I doubt anyone would unironically say centillillion, https://bignumbers.fandom.com/wiki/Millillion shows, that this is somewhat used/recognized. And for more normal numbers, it matches the Wikipedia list.

@Aras14HD
Copy link
Collaborator Author

Aras14HD commented Mar 1, 2026

I tried and concluded, that localizing that is infeasible, even german is quite some effort, and I have no idea how you would do something like french for example.

Instead, I would maybe add a warning for non en locales, so that people don't think it's a bug.

Also noticed: We could make locale way simpler, if we abandon the versioning and just have one struct with optional fields (default/missing field means None). That way we don't have all the boilerplate and repetition we have now.

Correction: localization basically means a fully new algorithm each time. So it is way lower on priority of localization

@tolik518
Copy link
Owner

tolik518 commented Mar 6, 2026

Maybe a format for basic formatting functions like round truncate fromat_float get_factorial_level_string and write_out_number. With calculation_results just implementing methods of/traits for the types Calculation and CalculationResult.

Yeah I would welcome a clearer calculation -> result -> formatting pipeline. But this doesn't have to be done in the PR here

Copy link
Owner

@tolik518 tolik518 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please add a test in integration.rs for behavior with different languages. This would be a good documentation for what would happen in that case

…them

fix factorion_math::length of negative numbers (use abs)
add write_out for ApproximateDigits
add write_out for ComplexInfinity
add minus and zero support to write_out_number
fix spelling of forty
@Aras14HD
Copy link
Collaborator Author

Aras14HD commented Mar 7, 2026

In addition to the fixes, asked additions, I added support for negative numbers and writing out the number of digits.

@tolik518
Copy link
Owner

tolik518 commented Mar 7, 2026

Great! Thank you! I'll start the merge train!
(I'll merge slowly)

@tolik518 tolik518 merged commit 64504c7 into tolik518:master Mar 7, 2026
6 checks passed
@Aras14HD Aras14HD deleted the write-out branch March 7, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for formatting factorial results as words

2 participants