It got me wondering if there was some sort of bit hack I could use on floating point numbers to achieve the same effect.
My initial thoughts on the matter are no, there is no easy way to do it. But it's so tempting to try to find a way when you know that there's an exponent as part of the float, and you know that it's using base 2. All you'd have to do is increment the exponent by one.
Here is my initial code:
float myDouble(float num)
{
assert(sizeof(float) == 4);
int maskS = 0x80000000;
int maskE = 0x7F800000;
int maskM = 0x007FFFFF;
int* i = (int*)#
int sign = *i & maskS;
int expo = *i & maskE;
int mant = *i & maskM;
expo = ((expo >> 23) + 1) << 23; // The actual double operation
sign |= expo | mant;
float* newNum = (float*)&sign;
printf("%f %f\n", num, *newNum);
return *newNum;
}
There's also a lot of seemingly unnecessary stuff in there, but it is necessary! You can't use these bitwise operations on a float, and the addition would literally add about 8 million to the value.
What I have not yet explored is what can be done in assembly. However, I'm not so hopeful as I am fairly sure that floats get stored in floating point registers that prevent you from doing silly stuff like this.