_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: https://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.7.0-DEV.3404 (2018-01-14 21:52 UTC)
_/ |\__'_|_|_|\__'_| | Commit d569a2923c* (8 days old master)
|__/ | x86_64-w64-mingw32
julia> pi
π = 3.1415926535897...
julia> big(pi)
3.141592653589793238462643383279502884197169399375105820974944592307816406286198
julia> rationalize(Int128,pi)
60728338969805745700507212595448411044//19330430665609526556707216376512714945
julia> rationalize(Int128,pi,0.000001)
ERROR: MethodError: no method matching rationalize(::Type{Int128}, ::Irrational{:π}, ::Float64)
Closest candidates are:
rationalize(::Type{T<:Integer}, ::AbstractFloat, ::Real) where T<:Integer at rational.jl:127
rationalize(::Type{T}, ::AbstractIrrational; tol) where T at irrationals.jl:81
rationalize(::Type{T<:Integer}, ::AbstractFloat; tol) where T<:Integer at rational.jl:185
julia>
The tolerance is a keyword argument:
julia> rationalize(Int128, pi, tol=0.000001)
355//113
That’s what arguments after a semicolon in the method signature mean:
help?> rationalize
search: rationalize Rational Irrational AbstractIrrational
rationalize([T<:Integer=Int,] x; tol::Real=eps(x))
Approximate floating point number x as a Rational number with components
of the given integer type. The result will differ from x by no more than
tol.
julia> rationalize(5.6)
28//5
julia> a = rationalize(BigInt, 10.3)
103//10
julia> typeof(numerator(a))
BigInt
Sorry to remember this:
https://github.com/JuliaLang/julia/pull/16143