[Rd] Complex numbers and negative zeroes
Antoine Fabri
@nto|ne@|@br| @end|ng |rom gm@||@com
Sat Apr 26 11:10:00 CEST 2025
Dear r-devel,
In R `sign(0)` and `sign(-0)` both return `0` but negative zeroes do exist
in the sense that dividing by them gives `-Inf`
Complex numbers behave oddly with negative 0s, see below:
``` r
1 / Re(0 + 0i)
#> [1] Inf
1 / Im(0 + 0i)
#> [1] Inf
1 / Re(0 - 0i)
#> [1] Inf
1 / Im(0 - 0i) # negating the imaginary part alone does nothing
#> [1] Inf
1 / Re(-0 + 0i) # negating the real part alone does nothing
#> [1] Inf
1 / Im(-0 + 0i)
#> [1] Inf
1 / Re(-0 - 0i) # negating both parts works on the real part
#> [1] -Inf
1 / Im(-0 - 0i) # but not on the imaginary part
#> [1] Inf
1 / Im(0i)
#> [1] Inf
1 / Re(0i)
#> [1] Inf
1 / Re(-0i) # negating the imaginary part without explicitly providing the
real part negates the real part
#> [1] -Inf
1 / Im(-0i) # and the imaginary part too
#> [1] -Inf
``` r
Defined with `complex()` it seems to work ok
``` r
1 / Re(complex(real = 0, imaginary = 0))
#> [1] Inf
1 / Im(complex(real = 0, imaginary = 0))
#> [1] Inf
1 / Re(complex(real = -0, imaginary = 0))
#> [1] -Inf
1 / Im(complex(real = -0, imaginary = 0))
#> [1] Inf
1 / Re(complex(real = 0, imaginary = -0))
#> [1] Inf
1 / Im(complex(real = 0, imaginary = -0))
#> [1] -Inf
1 / Re(complex(real = -0, imaginary = -0))
#> [1] -Inf
1 / Im(complex(real = -0, imaginary = -0))
#> [1] -Inf
```
Thanks,
Antoine
[[alternative HTML version deleted]]
More information about the R-devel
mailing list