I am currently making an application that is required to save an array of float values to a binary file in C# and then open that same binary and retrieve the values in a C program.
I am using a BinaryWriter in C#
binaryWriter.Write(myFloatVar);
And I am using fread in C
fread(&myfloat, sizeof(float), 1, file);
For the majority it works fine, but when trying to fread a particular value the output comes out strange. The input is 0.6045232 on the C# side as found through debuging, but when it is retrieved on the C program side it appears as 6.961e-041#DEN
I know the DEN means that it is a denormalised number, but I am unsure how this has happened or how to fix it. Any help would be appreciated.
floats - and then the rest.floatas text has its failure modes too. IEEE FP formats are extremely well defined, not so with textual FP ones. Just start looking as C# text of Infinity, de-normal, and insufficient and decimal wobbling precision. Typically the best text is for binary FP to write in a textual binary FP format, like with%a. Assuming C# and C (on the same computer) use the same binary format is not a bad assumption. The exchange file could specify the FP format. Many factors go into the determining what is best.