Skip to content

Commit

Permalink
when x is NaN in trig functions return x rather than NaN (#49285
Browse files Browse the repository at this point in the history
)

* when x is NaN in trig functions return x rather than NaN

* prefer `isnan(x) | isnan(y)`

---------

Co-authored-by: mikmoore <95002244+mikmoore@users.noreply.github.com>
  • Loading branch information
oscardssmith and mikmoore authored Apr 11, 2023
1 parent 8fbef6e commit 1aa65c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion base/special/hyperbolic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function asinh(x::T) where T <: Union{Float32, Float64}
# return sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1)))
# d) |x| >= 2^28
# return sign(x)*(log(x)+ln2))
if isnan(x) || isinf(x)
if !isfinite(x)
return x
end
absx = abs(x)
Expand Down
16 changes: 8 additions & 8 deletions base/special/trig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function sin(x::T) where T<:Union{Float32, Float64}
end
return sin_kernel(x)
elseif isnan(x)
return T(NaN)
return x
elseif isinf(x)
sin_domain_error(x)
end
Expand Down Expand Up @@ -103,7 +103,7 @@ function cos(x::T) where T<:Union{Float32, Float64}
end
return cos_kernel(x)
elseif isnan(x)
return T(NaN)
return x
elseif isinf(x)
cos_domain_error(x)
else
Expand Down Expand Up @@ -179,7 +179,7 @@ function sincos(x::T) where T<:Union{Float32, Float64}
end
return sincos_kernel(x)
elseif isnan(x)
return T(NaN), T(NaN)
return x, x
elseif isinf(x)
sincos_domain_error(x)
end
Expand Down Expand Up @@ -221,7 +221,7 @@ function tan(x::T) where T<:Union{Float32, Float64}
end
return tan_kernel(x)
elseif isnan(x)
return T(NaN)
return x
elseif isinf(x)
tan_domain_error(x)
end
Expand Down Expand Up @@ -582,8 +582,8 @@ function atan(y::T, x::T) where T<:Union{Float32, Float64}
# S8) ATAN2(+-INF,+INF ) is +-pi/4 ;
# S9) ATAN2(+-INF,-INF ) is +-3pi/4;
# S10) ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2;
if isnan(x) || isnan(y) # S1 or S2
return T(NaN)
if isnan(x) | isnan(y) # S1 or S2
return isnan(x) ? x : y
end

if x == T(1.0) # then y/x = y and x > 0, see M2
Expand Down Expand Up @@ -1191,7 +1191,7 @@ function sind(x::Real)
if isinf(x)
return throw(DomainError(x, "`x` cannot be infinite."))
elseif isnan(x)
return oftype(x,NaN)
return x
end

rx = copysign(float(rem(x,360)),x)
Expand Down Expand Up @@ -1222,7 +1222,7 @@ function cosd(x::Real)
if isinf(x)
return throw(DomainError(x, "`x` cannot be infinite."))
elseif isnan(x)
return oftype(x,NaN)
return x
end

rx = abs(float(rem(x,360)))
Expand Down

4 comments on commit 1aa65c3

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible new issues were detected.
A full report can be found here.

@vtjnash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here.

Please sign in to comment.