Commit a2d52e1
authored
Change the implementation of
The current implementation of `rotate!(x, y, c, s)` overwrites `x` with
`c*x + s*y` and `y` with `-conj(s)*x + c*y`. There exists this edge case
of `rotate!([NaN], [NaN], false, false)`
```julia
julia> rotate!([NaN], [NaN], false, false)
([0.0], [NaN])
```
The new `x` becomes `0.0`, because `false` acts as a ["strong zero" in
Julia](https://docs.julialang.org/en/v1/manual/mathematical-operations/#Arithmetic-Operators)
(so `false * NaN == 0.0`). When calculating the new `y`, the code
executes `-conj(false)*NaN + false*NaN`. However, the unary minus, `-`,
turns the `false::Bool` to `0::Int`, which is no longer a strong zero,
and thus, we get `NaN`. This is inconsistent with
```julia
julia> reflect!([NaN], [NaN], false, false)
([0.0], [0.0])
```
This PR changes `-conj(s)*x + c*y` to `c*y - conj(s)*x` to avoid unary
minus, so that
```julia
julia> rotate!([NaN], [NaN], false, false) # This PR
([0.0], [0.0])
```
I noted this from
JuliaGPU/CUDA.jl#2607 (comment).
More discussion in
https://discourse.julialang.org/t/negative-false-no-longer-acts-as-a-strong-zero/128506/1rotate! to avoid unary minus (#1323)1 parent c9b6456 commit a2d52e1
1 file changed
+3
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1726 | 1726 | | |
1727 | 1727 | | |
1728 | 1728 | | |
1729 | | - | |
| 1729 | + | |
1730 | 1730 | | |
1731 | 1731 | | |
1732 | 1732 | | |
| |||
1741 | 1741 | | |
1742 | 1742 | | |
1743 | 1743 | | |
1744 | | - | |
1745 | | - | |
| 1744 | + | |
| 1745 | + | |
1746 | 1746 | | |
1747 | 1747 | | |
1748 | 1748 | | |
| |||
0 commit comments