Skip to content

Commit 2c7f91b

Browse files
committed
Fix ambiguities in LazyFloat64
1 parent 967d58f commit 2c7f91b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/lazy_float.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# numeric types.
33
struct LazyFloat64 <: AbstractFloat
44
value::Float64
5+
6+
LazyFloat64(x::AbstractFloat) = new(convert(Float64, x))
57
end
68

7-
LazyFloat64(x::LazyFloat64) = x
8-
LazyFloat64(x::Number) = LazyFloat64(convert(Float64, x))
9-
float(x::LazyFloat64) = x.value
9+
Base.float(x::LazyFloat64) = x.value
1010

1111
Base.convert(::Type{LazyFloat64}, x::LazyFloat64) = x
1212
Base.convert(::Type{LazyFloat64}, x::FixedRational) = LazyFloat64(convert(Float64, x))
@@ -15,8 +15,6 @@ Base.convert(::Type{T}, x::LazyFloat64) where {T<:Number} = convert(T, float(x))
1515
Base.promote_rule(::Type{LazyFloat64}, ::Type{T}) where {T<:AbstractFloat} = T
1616
Base.promote_rule(::Type{LazyFloat64}, ::Type{T}) where {T} = promote_type(Float64, T)
1717

18-
(::Type{T})(x::LazyFloat64) where {T<:Number} = T(float(x))
19-
2018
Base.show(io::IO, x::LazyFloat64) = print(io, float(x))
2119

2220
Base.:+(a::LazyFloat64, b::LazyFloat64) = LazyFloat64(float(a) + float(b))
@@ -31,3 +29,8 @@ Base.:^(a::LazyFloat64, b::LazyFloat64) = LazyFloat64(float(a) ^ float(b))
3129
Base.sqrt(a::LazyFloat64) = LazyFloat64(sqrt(float(a)))
3230
Base.cbrt(a::LazyFloat64) = LazyFloat64(cbrt(float(a)))
3331
Base.eps(::Type{LazyFloat64}) = eps(Float64)
32+
33+
# Ambiguities:
34+
for T in (:(Rational{<:Any}), :(Base.TwicePrecision), :AbstractChar, :Complex, :Number)
35+
@eval LazyFloat64(x::$T) = LazyFloat64(float(x))
36+
end

0 commit comments

Comments
 (0)