B
Brian
Hello.
Consider this code.
float
baz(float f)
{
if(sizeof(float) ^ sizeof(int)){
/* use slow ordinary FP operations */
}else{
int i = *(int *)&f;
/* do clever bit-twiddling to implement FP operation */
}
}
It attempts to detect whether the type punning will cause undefined
behavior on the implementation at hand, and if so it avoids that branch.
Obviously it's not 100% guaranteed probably, but do you agree this is a
useful way to maximize portability?
Best
Brian
Consider this code.
float
baz(float f)
{
if(sizeof(float) ^ sizeof(int)){
/* use slow ordinary FP operations */
}else{
int i = *(int *)&f;
/* do clever bit-twiddling to implement FP operation */
}
}
It attempts to detect whether the type punning will cause undefined
behavior on the implementation at hand, and if so it avoids that branch.
Obviously it's not 100% guaranteed probably, but do you agree this is a
useful way to maximize portability?
Best
Brian