From 1c2e689dd476e507fca2e468c1de82e88cfc0808 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sat, 19 Aug 2017 09:14:24 -0500 Subject: [PATCH] Fix eltype conversion for StepRangeLen{BigFloat} (fixes #23300) --- base/twiceprecision.jl | 3 ++- test/ranges.jl | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/base/twiceprecision.jl b/base/twiceprecision.jl index 6607c12e1d1ce..8a849dcb9af68 100644 --- a/base/twiceprecision.jl +++ b/base/twiceprecision.jl @@ -422,7 +422,7 @@ function rat(x) y = x a = d = 1 b = c = 0 - m = maxintfloat(narrow(typeof(x))) + m = maxintfloat(narrow(typeof(x)), Int) while abs(y) <= m f = trunc(Int,y) y -= f @@ -435,6 +435,7 @@ function rat(x) return a, b end +narrow(::Type{T}) where {T<:AbstractFloat} = Float64 narrow(::Type{Float64}) = Float32 narrow(::Type{Float32}) = Float16 narrow(::Type{Float16}) = Float16 diff --git a/test/ranges.jl b/test/ranges.jl index 6ec04c6f89038..1b04b345d8eab 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -957,3 +957,10 @@ end @test logspace(a, b, n, base=base) == base.^linspace(a, b, n) end end + +# Issue #23300 +x = -5:big(1.0):5 +@test map(Float64, x) === -5.0:1.0:5.0 +@test map(Float32, x) === -5.0f0:1.0f0:5.0f0 +@test map(Float16, x) === Float16(-5.0):Float16(1.0):Float16(5.0) +@test map(BigFloat, x) === x