Re: Singles to Doubles
- From: dpb <none@xxxxxxx>
- Date: Mon, 16 Jul 2007 16:37:15 -0500
Rick Rothstein (MVP - VB) wrote:
Here is my guess... and it is only a GUESS as I have never been one to "get under the hood" of VB. I'm guessing that VB calculates its Singles and Doubles using some kind of power series expansion...
What "calculation" do you think is going on, here Rick?
It's simply the promotion of a Single precision IEEE float to Double.
The internal i/o routines that parse the source file do the conversion from the external ASCII base 10 representation to the internal binary representation. There is the same problem in binary representing a floating point value in binary as there is in decimal, just for a different set of values.
You're comfortable w/ 1/3 --> 0.3333... in the decimal system while 1/4 --> 0.25. It's the same thing internally except the divisor is in decreasing powers of 2, not 10. So, the internal representation is something like 1/2 + 0/2^2 + 1/2^3 + ... until the last power of two is less than the number of significant bits in the mantissa (28 for Single, 53 for Double).
When promoting from Single to Double, there is _NO_ information about what the trailing numerators are or should be for the powers of 2 from the 29th to the 53rd bit so, as someone else noted, lacking that information they're set to 0 as the most accurate value _ON AVERAGE_.
What then looks like "garbage" in external representation is, in fact what the continuing fraction w/ all numerators zero is.
When, on the other hand, it is known that the remaining _DECIMAL_ digits are, in fact, zero, that creates a totally different _BINARY_ expansion of those coefficients.
That help?
--
.
- Follow-Ups:
- Re: Singles to Doubles
- From: dpb
- Re: Singles to Doubles
- References:
- Singles to Doubles
- From: Karl E. Peterson
- Re: Singles to Doubles
- From: Bob Butler
- Re: Singles to Doubles
- From: Karl E. Peterson
- Re: Singles to Doubles
- From: Rick Rothstein \(MVP - VB\)
- Singles to Doubles
- Prev by Date: vb6 WebBrowser control on Vista
- Next by Date: Re: Singles to Doubles
- Previous by thread: Re: Singles to Doubles
- Next by thread: Re: Singles to Doubles
- Index(es):
Relevant Pages
|