Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
putianyi889 authored Dec 23, 2024
1 parent 107d32c commit bf20340
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/PTYQoL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ show(io::IO, f::ComposedFunction{<:Fix2}) = print(io, f.outer.f, '(', f.inner, '
import Base: mapreduce
mapreduce(f, op) = f()

# https://github.com/JuliaLang/julia/pull/51475
import Base: zero, TwicePrecision
function zero(r::StepRangeLen{T,R,S}) where {T,R,S}
StepRangeLen{T}(zero(r.ref), zero(r.step), length(r), r.offset)
end
zero(r::LinRange) = LinRange{eltype(r)}(zero(first(r)), zero(last(r)), length(r))
zero(r::Union{UnitRange, StepRange}) = zero(StepRangeLen(r))
zero(r::TwicePrecision) = zero(typeof(r))

import Base: searchsorted, searchsortedfirst, searchsortedlast, Ordering, Forward, ord, keytype, midpoint, lt

function searchsortedfirst(v, x, lo::T, hi::T, o::Ordering)::keytype(v) where {T<:Integer}
Expand Down Expand Up @@ -174,7 +183,7 @@ end

# https://github.com/JuliaLang/julia/pull/56433
import Base: (:), +, -, TwicePrecision, zero, IEEEFloat
zero(::TwicePrecision{T}) where {T} = TwicePrecision(zero(T))
# zero(::TwicePrecision{T}) where {T} = TwicePrecision(zero(T)) # overwrites https://github.com/JuliaLang/julia/pull/51475
TwicePrecision(x::AbstractIrrational) = TwicePrecision{Float64}(x)
for op in (:+, :-)
for (prec, twiceprec) in ((Float16, Float32), (Float32, Float64))
Expand Down
28 changes: 28 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,34 @@ using Test
@test length(1:π:-1) == 0
@test length(1:π:1) == 1
end

@testset "https://github.com/JuliaLang/julia/pull/51475" begin
@testset "StepRangeLen" begin
for r in (StepRangeLen(im, 2im, 10),
StepRangeLen{Bool}(false, true, 2),
1.0:2.0:5.0)
z = zero(r)
@test r + z == r
@test typeof(z) == typeof(r)
end
end
@testset "LinRange" begin
for r in (LinRange{Int}(2, 3, 2),
LinRange(2, 3, 4),
LinRange{Bool}(false, true, 2))
z = zero(r)
@test r + z == r
@test typeof(z) == typeof(r)
end
end
@testset "UnitRange/StepRange" begin
for r in (1:4, UnitRange(1.0, 2.0),
1:1:4, false:true:true)
z = zero(r)
@test r + z == r
end
end
end
end

@testset "Misc" begin
Expand Down

0 comments on commit bf20340

Please sign in to comment.