API
RepeatingDecimalNotations.DotsNotation
— TypeDotsNotation <: RepeatingDecimalNotation
A type to represent a repeating decial with parentheses notation like "0.1(6)".
julia> rd"123.456̇78̇"
4111111//33300
julia> no = DotsNotation()
DotsNotation()
julia> stringify(no, 1//11)
"0.0̇9̇"
julia> rationalify(no, "123.456̇78̇")
4111111//33300
RepeatingDecimalNotations.EllipsisNotation
— TypeEllipsisNotation <: RepeatingDecimalNotation
A type to represent a repeating decial with ellipsis notation like "0.1666...".
julia> rd"123.45678678..."
4111111//33300
julia> no = EllipsisNotation()
EllipsisNotation()
julia> stringify(no, 1//11)
"0.0909..."
julia> rationalify(no, "123.45678678...")
4111111//33300
julia> rd"0.4545..." # Same as 0.(45), repeating [45] two times
5//11
julia> rd"0.333..." # Same as 0.(3), repeating one digit [3] three times
1//3
julia> rd"0.13331333..." # Same as 0.(1333), repeating [1333] has priority over repeating [3]
1333//9999
julia> rd"0.133313333..." # Same as 0.13331(3), adding additional [3] resolves the ambiguity.
19997//150000
RepeatingDecimalNotations.ParenthesesNotation
— TypeParenthesesNotation <: RepeatingDecimalNotation
A type to represent a repeating decial with parentheses notation like "0.1(6)".
julia> rd"123.45(678)"
4111111//33300
julia> no = ParenthesesNotation()
ParenthesesNotation()
julia> stringify(no, 1//11)
"0.(09)"
julia> rationalify(no, "123.45(678)")
4111111//33300
RepeatingDecimalNotations.RepeatingDecimal
— TypeRepeatingDecimal
Intermediate struct to represent a repeating decimal number.
Examples
julia> RepeatingDecimal(false, 12743, 857142, 2, 6)
2|--|------|6
-127.43(857142)
----------- --------------
Finite part Repeating part
julia> RepeatingDecimal(1//17)
0||----------------|16
+0.(0588235294117647)
----------- -------------------
Finite part Repeating part
RepeatingDecimalNotations.RepeatingDecimalNotation
— TypeAbstract supertype for repeating decimals notations.
RepeatingDecimalNotations.ScientificNotation
— TypeScientificNotation <: RepeatingDecimalNotation
A type to represent a repeating decial with scientific notation like "0.1r6".
julia> rd"123.45r678"
4111111//33300
julia> no = ScientificNotation()
ScientificNotation()
julia> stringify(no, 1//11)
"0.r09"
julia> rationalify(no, "123.45r678")
4111111//33300
julia> rd"1.2345r678e2" # Exponent term is supported.
4111111//33300
RepeatingDecimalNotations.rationalify
— Functionrationalify(::Type{<:Integer}, ::RepeatingDecimalNotation, ::AbstractString)
rationalify(::Type{<:Integer}, ::RepeatingDecimal)
rationalify(::Type{<:Integer}, ::AbstractString)
rationalify(::RepeatingDecimalNotation, ::AbstractString)
rationalify(::RepeatingDecimal)
rationalify(::AbstractString)
Generate String
from Rational
or RepeatingDecimal
instance.
Examples
julia> using RepeatingDecimalNotations: rationalify # `rationalify` is not exported.
julia> rationalify(RepeatingDecimal(true, 123, 45, 2, 3)) # `RepeatingDecimal` to `Rational{Int}`
6829//5550
julia> rationalify("1.23r045") # `String` to `Rational{Int}`
6829//5550
julia> rationalify(EllipsisNotation(), "1.23r045") # If notation style is specified, the input string should follow the style.
ERROR: invalid input!
Stacktrace:
[...]
julia> rationalify(Int128, "1.23r045") # `String` to `Rational{Int128}`
6829//5550
julia> typeof(ans)
Rational{Int128}
RepeatingDecimalNotations.stringify
— Functionstringify(::RepeatingDecimalNotation, ::RepeatingDecimal)
stringify(::RepeatingDecimalNotation, ::Rational)
stringify(::RepeatingDecimal)
stringify(::Rational)
Generate String
from Rational
or RepeatingDecimal
instance.
Examples
julia> using RepeatingDecimalNotations: stringify # `stringify` is not exported.
julia> stringify(ScientificNotation(), RepeatingDecimal(true, 123, 45, 2, 3))
"1.23r045"
julia> stringify(EllipsisNotation(), 1//11)
"0.0909..."
julia> stringify(RepeatingDecimal(true, 123, 45, 2, 3)) # Defaults to `ParenthesesNotation()`.
"1.23(045)"
julia> stringify(1//11)
"0.(09)"
RepeatingDecimalNotations.@rd_str
— Macro@rd_str
A string macro to create a rational number.
Examples
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)