0 and 0i are parsed as constants with 'positive zero' real and imaginary parts,
whereas <uop>0, <uop>0i, and <uop>0<bop>0i are parsed as *calls*:
<uop>0 ~ <uop>( 0 )
<uop>0i ~ <uop>( 0i)
<uop>0<bop>0i ~ <bop>(<uop>(0), 0i)
Keeping in mind R's usual arithmetic conversions and the IEEE 754 standard which
defines exactly how arithmetic on signed zeros should work, I see nothing odd in
your output.
Mikael
Date: Sat, 26 Apr 2025 11:10:00 +0200
From: Antoine Fabri<[email protected]>
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]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel