J
jacob navia
Consider this code:
< code >
#include <complex.h>
int main(void)
{
double complex c = 0.4+2.9I;
c = ~c;
}
< end code >
Is this legal?
The standard says about the ~ operator:
<quote>
6.5.5.3
The result of the ~ operator is the bitwise complement of its (promoted)
operand (that is, each bit in the result is set if and only if the
corresponding bit in the converted operand is not set). The integer
promotions are performed on the operand, and the result has the
promoted type. If the promoted type is an unsigned type, the expression
~E is equivalent to the maximum value representable in that type minus
E.
< end quote>
This means that I should "promote" the complex to double,
ignoring the imaginary part, then converting the resulting double
to integer, NOT to unsigned integer.
0.4 + 2.9I --> 0.4 --> 0
THEN I should apply ~ to that, resulting into the integer -1. Then,
I should convert that -1 to double, then to double complex.
This looks quite hairy. Did I get it right?
Thanks in advance for your time.
< code >
#include <complex.h>
int main(void)
{
double complex c = 0.4+2.9I;
c = ~c;
}
< end code >
Is this legal?
The standard says about the ~ operator:
<quote>
6.5.5.3
The result of the ~ operator is the bitwise complement of its (promoted)
operand (that is, each bit in the result is set if and only if the
corresponding bit in the converted operand is not set). The integer
promotions are performed on the operand, and the result has the
promoted type. If the promoted type is an unsigned type, the expression
~E is equivalent to the maximum value representable in that type minus
E.
< end quote>
This means that I should "promote" the complex to double,
ignoring the imaginary part, then converting the resulting double
to integer, NOT to unsigned integer.
0.4 + 2.9I --> 0.4 --> 0
THEN I should apply ~ to that, resulting into the integer -1. Then,
I should convert that -1 to double, then to double complex.
This looks quite hairy. Did I get it right?
Thanks in advance for your time.