# Rationalize() error

**URL:** <https://discourse.julialang.org/t/rationalize-error/8544>\
**Category:** Numerics\
**Created:** [January 23, 2018, 3:23pm UTC](https://discourse.julialang.org/t/rationalize-error/8544 "2018-01-23T15:23:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yaroslav\_Kavenchuk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yaroslav_kavenchuk/32/7642_2.png) [@Yaroslav\_Kavenchuk](https://discourse.julialang.org/u/Yaroslav_Kavenchuk)\
**Post date:** [January 23, 2018, 3:23pm UTC](https://discourse.julialang.org/t/rationalize-error/8544/1 "2018-01-23T15:23:57Z")

</div>

```julia
               _
   _ _ _(_)_ | 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>

```

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 23, 2018, 3:26pm UTC](https://discourse.julialang.org/t/rationalize-error/8544/2 "2018-01-23T15:26:55Z")

</div>

The tolerance is a keyword argument:

```julia
julia> rationalize(Int128, pi, tol=0.000001)
355//113

```

That’s what arguments after a semicolon in the method signature mean:

```julia
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

```

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [January 23, 2018, 9:34pm UTC](https://discourse.julialang.org/t/rationalize-error/8544/3 "2018-01-23T21:34:56Z")

</div>

Sorry to remember this:  
[https://github.com/JuliaLang/julia/pull/16143](https://github.com/JuliaLang/julia/pull/16143)
