I have two values, one an int and one a float pointed to by void pointers (value1 and value2). They are received from a function call in any order. First the float then the int or vice versa. I would like to typecast the int to a float and then perform floating point math between them.
However if you were to typecast the int* to a float* then dereference it, you would get the bit pattern of the number interpreted as a float and it does not go through the int to float conversion.
So I was wondering if there was a clean way to cast one to the other without having to pass extra data about the types then doing a bunch of if statements.
For example
float x = -1.1;//types can be int on input
int y = 3; //will be float if other is int
void* value1 = &x;
void* value2 = &y;
float z = 0;
void* token = &z;
*((float*)token) = *((float*)value1) - *((float*)value2); //but written to work
I want *((float*)token) to equal -4.1, but currently it would equal -1.1.