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 several issues:
* Set `BigFloat` precision without mutating the global default.
* Assume just the `:foldable` effect, instead of `:total`.
* Assume effects only for `Irrational`, it's incorrect to do that for
`AbstractIrrational` in general.
* Avoid infinite loop for `AbstractIrrational`.
* Check for the case of the irrational number getting rounded to an
integer `BigFloat`.
function_rationalize_irrational(::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 =_rationalize_irrational_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
+
@assume_effects:foldablefunctionRational{T}(x::Irrational) where {T <:Integer}
97
+
_rationalize_irrational(T, x)
98
+
end
99
+
functionRational{T}(x::AbstractIrrational) where {T <:Integer}
100
+
_rationalize_irrational(T, x)
68
101
end
69
-
Rational{BigInt}(x::AbstractIrrational) =throw(ArgumentError("Cannot convert an AbstractIrrational to a Rational{BigInt}: use rationalize(BigInt, x) instead"))
70
102
71
103
@assume_effects:totalfunction (t::Type{T})(x::AbstractIrrational, r::RoundingMode) where T<:Union{Float32,Float64}
0 commit comments