I'm working on a high speed computing problem for a large scale simulation. In order to speed up the process I wish to make a couple of optimizations, one of which is to compute the absolute value of a double in only a couple of cycles without jumps.
My idea was, that 64-Bit double values are represented with a 1-Bit sign Bit, an 11-Bit exponent and a 52-Bit Mantissa. So a double value XOR-ed with a mask: 10000000 00000000 00000000 00000000 would yield the desired result:
double abs(double x) {
double mask = -0.0e0;
return x^mask;
}
Now obviously there are few reason one would need binary operations on doubles, so naturally the compiler throws an error:
error: invalid operands to binary ^ (have ‘double’ and ‘double’)
I was wondering whether there was any way to make this work in a fast fashion, since I didn't wish to convert the whole thing into a char-array and back as was suggested elsewhere. That would sort of defeat the purpose of fast computing.
I'm thankful for all help...