Sorry for the less-than-precise subject, but...
I'm reading a binary data file created with VB6 using the normal
PUT statements. The file contains test data, stored in single-precision
format. I sometimes need to export this data file to plain-text
format, so I wrote a utility in PB6 to do this. The core of this
utility is just a simple loop:
The problem is that when I look at the text data file, there's
way too many digits; here's what the data looks like:
-16.6229248046875,10.6029329299927
-9.305419921875, 7.90202713012695
-7.869873046875, 6.12179470062256
-6.3330078125, 5.09605121612549
-5.333251953125, 4.58390331268311
This is too many digits for a single-precision float. So I ported
the PB app to VB6
and here's the data it converted:
-16.62292, 10.60293
-9.30542, 7.902027
-7.869873, 6.121795
-6.333008, 5.096051
-5.333252, 4.583903
Which is what I'd expect for single-precision float.
So, what's up? Looking at the PB docs for the Format$
function it appears that using it without a formatting string
does output a lot of trailing digits when used with a real number.
My concern is that the Format$ function is showing more
data than is really there, at least according to IEEE-754. It
seems like Format$ is converting values to Doubles first
and then formatting the output.
------------------
Mark Newman
I'm reading a binary data file created with VB6 using the normal
PUT statements. The file contains test data, stored in single-precision
format. I sometimes need to export this data file to plain-text
format, so I wrote a utility in PB6 to do this. The core of this
utility is just a simple loop:
Code:
' Read the data For I = 1 To lNumPoints ' Read the data from the binary file, single-precision float Get #hFileInput, , fAverage Get #hFileInput, , fOneSigma ' Save the data to the text file Print #hFileOutput, Format$(fAverage) & "," & Format$(fOneSigma) Next
way too many digits; here's what the data looks like:
-16.6229248046875,10.6029329299927
-9.305419921875, 7.90202713012695
-7.869873046875, 6.12179470062256
-6.3330078125, 5.09605121612549
-5.333251953125, 4.58390331268311
This is too many digits for a single-precision float. So I ported
the PB app to VB6

-16.62292, 10.60293
-9.30542, 7.902027
-7.869873, 6.121795
-6.333008, 5.096051
-5.333252, 4.583903
Which is what I'd expect for single-precision float.
So, what's up? Looking at the PB docs for the Format$
function it appears that using it without a formatting string
does output a lot of trailing digits when used with a real number.
My concern is that the Format$ function is showing more
data than is really there, at least according to IEEE-754. It
seems like Format$ is converting values to Doubles first
and then formatting the output.
------------------
Mark Newman
Comment