Skip to content

Commit

Permalink
Remove unnecessary complexity from the code
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaraldi committed Aug 9, 2023
1 parent 9fcc63f commit 85bb8f6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
16 changes: 4 additions & 12 deletions base/special/trig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -796,9 +796,7 @@ function sinpi(_x::T) where T<:IEEEFloat
throw(DomainError(x, "`x` cannot be infinite."))
end
# For large x, answers are all 1 or zero.
if T <: AbstractFloat
x >= maxintfloat(T) && return copysign(zero(T), _x)
end
x >= maxintfloat(T) && return copysign(zero(T), _x)

# reduce to interval [0, 0.5]
n = round(2*x)
Expand Down Expand Up @@ -827,9 +825,7 @@ function cospi(x::T) where T<:IEEEFloat
throw(DomainError(x, "`x` cannot be infinite."))
end
# For large x, answers are all 1 or zero.
if T <: AbstractFloat
x >= maxintfloat(T) && return one(T)
end
x >= maxintfloat(T) && return one(T)

# reduce to interval [0, 0.5]
n = round(2*x)
Expand Down Expand Up @@ -863,9 +859,7 @@ function sincospi(_x::T) where T<:IEEEFloat
throw(DomainError(x, "`x` cannot be infinite."))
end
# For large x, answers are all 1 or zero.
if T <: AbstractFloat
x >= maxintfloat(T) && return (copysign(zero(T), _x), one(T))
end
x >= maxintfloat(T) && return (copysign(zero(T), _x), one(T))

# reduce to interval [0, 0.5]
n = round(2*x)
Expand Down Expand Up @@ -905,9 +899,7 @@ function tanpi(_x::T) where T<:IEEEFloat
end
# For large x, answers are all zero.
# All integer values for floats larger than maxintfloat are even.
if T <: AbstractFloat
x >= maxintfloat(T) && return copysign(zero(T), _x)
end
x >= maxintfloat(T) && return copysign(zero(T), _x)

# reduce to interval [0, 0.5]
n = round(2*x)
Expand Down
33 changes: 33 additions & 0 deletions test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

using Random: seed!
seed!(1)

abstract type Cell end

struct CellA<:Cell
a::Ref{Int}
end

struct CellB<:Cell
b::String
end

function fillcells!(mc::Array{Cell})
for ind in eachindex(mc)
mc[ind] = ifelse(rand() > 0.5, CellA(ind), CellB(string(ind)))
end
return mc
end

function work(size)
mcells = Array{Cell}(undef, size, size)
mc = fillcells!(mcells)
end

function run(maxsize)
Threads.@threads for i in 1:maxsize
work(i*1000)
end
end

@time run(8)

0 comments on commit 85bb8f6

Please sign in to comment.