I am trying to read a binary file that stores some __float128
variables from other C project using Python.
I've been looking in the numpy.float128
but it seems that it is implemented in a different way to the __float128
in C.
Using the code below to read the same binary file gives me different number.
Python
import sys
import numpy as np
inFile = open(sys.argv[1], 'rb')
a1 = np.fromfile(inFile, dtype=np.float128)
print(a1)
inFile.close()
C
#include <quadmath.h>
#include <stdio.h>
int main(int argc, char *argv[]){
FILE *infile = fopen(argv[1], "r");
__float128 in_data;
fread(&in_data, sizeof(__float128), 1, infile);
printf("%g", in_data);
printf("\n");
return 0;
}