# Incorrect results for sinpi and cospi when using fastmath mode?

**URL:** <https://discourse.julialang.org/t/incorrect-results-for-sinpi-and-cospi-when-using-fastmath-mode/17662>\
**Category:** Numerics\
**Tags:** fast-math\
**Created:** [November 18, 2018, 12:00am UTC](https://discourse.julialang.org/t/incorrect-results-for-sinpi-and-cospi-when-using-fastmath-mode/17662 "2018-11-18T00:00:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [November 18, 2018, 12:00am UTC](https://discourse.julialang.org/t/incorrect-results-for-sinpi-and-cospi-when-using-fastmath-mode/17662/1 "2018-11-18T00:00:13Z")

</div>

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
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
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

```

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [November 18, 2018, 12:20am UTC](https://discourse.julialang.org/t/incorrect-results-for-sinpi-and-cospi-when-using-fastmath-mode/17662/2 "2018-11-18T00:20:39Z")

</div>

Seems like a bug to me.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 18, 2018, 7:20am UTC](https://discourse.julialang.org/t/incorrect-results-for-sinpi-and-cospi-when-using-fastmath-mode/17662/3 "2018-11-18T07:20:22Z")

</div>

I can reproduce this, please open an issue.

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [November 18, 2018, 12:19pm UTC](https://discourse.julialang.org/t/incorrect-results-for-sinpi-and-cospi-when-using-fastmath-mode/17662/4 "2018-11-18T12:19:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [November 18, 2018, 3:35pm UTC](https://discourse.julialang.org/t/incorrect-results-for-sinpi-and-cospi-when-using-fastmath-mode/17662/5 "2018-11-18T15:35:25Z")

</div>

Done, [sinpi and cospi return incorrect results when using `--math-mode=fast` · Issue #30073 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/30073#issue-381971132)

Thank you.
