I am writing float values from Blender using python, then read in C.
For some values I get 0.
If I replace that values with numbers like 2.3 or other random numbers It works.
I am using struct.pack("<ffff")
to write them.
Here is example value which doesn't work:
-8.881784197001252e-16, -1.700029006457271e-15, 6.106226635438361e-16, 1.0
When I opened file in hex editor I found correct number written -8.88178E-16
How can I read correct value?
Here is python sample:
#!/usr/bin/python
import struct
f = open("test.f", "wb")
f.write(struct.pack("<f", -8.881784197001252e-16))
f.write(struct.pack("<f", 123.0324))
Then here is C:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *file = fopen("test.f", "rb");
float test = 0;
fread(&test, sizeof(float), 1, file);
printf("a ='%f'\n", test);
fread(&test, sizeof(float), 1, file);
printf("b ='%f'\n", test);
return 0;
}
C output that I get is:
a ='-0.000000'
b ='123.032402'