>>102788999
>>102789013
>>102789067
Bro, no. I think you are confused.
#include <stdio.h>
#include <stdint.h>
void float_to_binary(float f, char* buffer)
{
uint32_t binary_value = *(uint32_t*)&f;
for (int i = 31; i >= 0; i--)
buffer[31 - i] = (binary_value & (1U << i)) ? '1' : '0';
buffer[32] = '\0';
}
float lerp(float x, float y, float l)
{
return (1.0f - l) * x + l * y;
}
int main()
{
char x_buffer[33];
char y_buffer[33];
char l_buffer[33];
char lerp_buffer[33];
const float x = 1.0f;
const float y = 2.0f;
float_to_binary(x, x_buffer);
float_to_binary(y, y_buffer);
float l = 0.0f;
float lrp = lerp(x, y, l);
float_to_binary(l, l_buffer);
float_to_binary(lrp, lerp_buffer);
printf("x: %f (%s), y: %f (%s), l: %f (%s), lerp: %f (%s)\n", x, x_buffer, y, y_buffer, l, l_buffer, lrp, lerp_buffer);
l = 0.5f;
lrp = lerp(x, y, l);
float_to_binary(l, l_buffer);
float_to_binary(lrp, lerp_buffer);
printf("x: %f (%s), y: %f (%s), l: %f (%s), lerp: %f (%s)\n", x, x_buffer, y, y_buffer, l, l_buffer, lrp, lerp_buffer);
l = 1.0f;
lrp = lerp(x, y, l);
float_to_binary(l, l_buffer);
float_to_binary(lrp, lerp_buffer);
printf("x: %f (%s), y: %f (%s), l: %f (%s), lerp: %f (%s)\n", x, x_buffer, y, y_buffer, l, l_buffer, lrp, lerp_buffer);
return 0;
}
x: 1.000000 (00111111100000000000000000000000), y: 2.000000 (01000000000000000000000000000000), l: 0.000000 (00000000000000000000000000000000), lerp: 1.000000 (00111111100000000000000000000000)
x: 1.000000 (00111111100000000000000000000000), y: 2.000000 (01000000000000000000000000000000), l: 0.500000 (00111111000000000000000000000000), lerp: 1.500000 (00111111110000000000000000000000)
x: 1.000000 (00111111100000000000000000000000), y: 2.000000 (01000000000000000000000000000000), l: 1.000000 (00111111100000000000000000000000), lerp: 2.000000 (01000000000000000000000000000000)