Hi all,
I’m pleased to announce my package RepeatingDecimalNotations.jl (repo, docs).
This package has some operations with repeating decimals.
- Define rational number with string macro like
rd"123.4(56)"
. - Convert
Rational
toString
,1//7
↦"0.(142857)"
- Convert
String
toRational
,0.1(6)
↦1//6
.
Here are some examples of usage:
Define rational numbers with sting macro
julia> using RepeatingDecimalNotations
julia> r = rd"123.4(56)" # 123.4565656...
61111//495
julia> rd"1.234r56e2" # Other notations
61111//495
julia> rd"123.45656..." # are also supported.
61111//495
julia> float(r) # Check floating point number approximation.
123.45656565656566
julia> rd"0.(9)" # 0.999... is equal to 1.
1//1
julia> rd"0.99(9)", rd"1", rd"1.000_000" # The notation of repeating decimals is not unique.
(1//1, 1//1, 1//1)
Conversion between rational numbers and string
julia> using RepeatingDecimalNotations: stringify, rationalify
julia> stringify(1//7) # Generate `String` from `Rational`.
"0.(142857)"
julia> rationalify("0.1(6)") # vice versa.
1//6
Enjoy Midy’s theorem
julia> stringify(1//19)
"0.(052631578947368421)"
julia> 052631578 + 947368421
999999999
julia> 052631 + 578947 + 368421
999999
Hope you like this package!