You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fixes for constructing a Rational from an AbstractIrrational
Fixes several issues:
* Set `BigFloat` precision without mutating the global default.
* Avoid infinite loop for `AbstractIrrational`.
* Check for the case of the irrational number getting rounded to an
integer `BigFloat`.
function_irrational_to_rational(::Type{T}, x::AbstractIrrational) where {T <:Integer}
83
+
if T <:BigInt
84
+
throw(ArgumentError("Cannot convert an AbstractIrrational to a Rational{BigInt}: use rationalize(BigInt, x) instead"))
85
+
end
86
+
ran =256:32:65536
87
+
for p ∈ ran
88
+
r =_irrational_to_rational_at_precision(T, x, p)
89
+
if r !==nothing
64
90
return r
65
91
end
66
-
p +=32
67
92
end
93
+
throw(ArgumentError("failed to rationalize irrational"))
94
+
end
95
+
96
+
functionRational{T}(x::AbstractIrrational) where {T <:Integer}
97
+
_irrational_to_rational(T, x)
68
98
end
69
-
Rational{BigInt}(x::AbstractIrrational) =throw(ArgumentError("Cannot convert an AbstractIrrational to a Rational{BigInt}: use rationalize(BigInt, x) instead"))
70
99
71
100
@assume_effects:totalfunction (t::Type{T})(x::AbstractIrrational, r::RoundingMode) where T<:Union{Float32,Float64}
0 commit comments