Incorrect results for sinpi and cospi when using fastmath mode?


#1

When firing up Julia with the --math-mode=fast option, I get incorrect results for sinpi and cospi functions. Is this a bug or am I missing something?

With the default math mode:

julia> a = rand(5)
5-element Array{Float64,1}:
 0.5897641978923696
 0.2459464145866952
 0.06373272357797632
 0.26244049804714087
 0.7254898186800567

julia> cospi.(a)
5-element Array{Float64,1}:
 -0.27827964958957724
  0.7160540045153001
  0.9800223981473272
  0.6789380012385138
 -0.650617399829044

julia> sinpi.(a)
5-element Array{Float64,1}:
 0.9605000971495538
 0.6980448858186719
 0.19888715174581242
 0.7341956077737403
 0.7594056880480248

while with fastmath mode:

julia> cospi.(a)
5-element Array{Float64,1}:
 1.0
 1.0
 1.0
 1.0
 1.0

julia> sinpi.(a)
5-element Array{Float64,1}:
 0.0
 0.0
 0.0
 0.0
 0.0

#2

Seems like a bug to me.


#3

I can reproduce this, please open an issue.


#4

It works with @fastmath but not with --math-mode=fast option. @code_llvm cos(...) shows constant result of 1.0. Also, using inline=no makes it go away.


#5

Done, https://github.com/JuliaLang/julia/issues/30073#issue-381971132

Thank you.