Re: Singles to Doubles
- From: dpb <none@xxxxxxx>
- Date: Wed, 18 Jul 2007 08:48:58 -0500
Michael C wrote:
"dpb" <none@xxxxxxx> wrote in message news:f7k4fe$vv8$1@xxxxxxxxxxxIf, after all this you still want more, do a google on "What Every Computer Scientist...Floating Point" and you'll be led quickly to a very fine paper on all the details of floating point. I thought I had a bookmark, but can't seem to find it at present and I'm plumb tuckered out, sorry... :)
What you say makes sense although I'm still trying to get my head fully around it. A binary number such as 1.11 should be converted to 1.1100 as these 2 values are equal. *If* we assume the number came from a base 10 number then we could provide some optimisation to the binary conversion to make some sort of guess as to what information was lost converting it to binary. But what we have is a binary number which could have been obtained from any source and might not have been a base 10 number at some stage. Therefore to assume base 10 could be faulty.
I'm confused by your nomenclature but let me see if I can paraphrase and add and get us closer...
A "binary number 1.11 should be converted to 1.1100 as they are equal".
If you're saying an internal representation of 1.11 (decimal) should be displayed as 1.1100 externally under all circumstances, that can't be unless it is one of the set of reals than can be represented exactly (and I didn't check for sure). In that case it _will_ be preserved both in i/o and in promotion.
If otoh it can't be represented exactly as a Single, then the likelihood that it can in Double isn't zero, but the problem of translation to/from the external representation arises, as does that of promotion. The VB i/o rtl is in a way a culprit in masking these problems because Print (and friends) _do_ incorporate logic in them to try their darnedest to make "ugly" values "pretty" because, just as in Karl's case, that's what is often wanted. Consequently, when the "problem" does appear, as this thread has amply demonstrated, it is more confusing than it might otherwise be in a more rigorous (in some sense) language such as C or Fortran where "what you see is what you get" makes the internal representations a little more visible.
The part about assuming whether the number came from base 10 or was possibly from somewhere else I don't understand at all. In the context of VB, all external representations are base 10 unless explicitly coded as Hex$ or Oct$ in which case the base is also known and explicit. There is no assumption of base ever required, the only "assumptions" in what I was trying to describe had to do with what one is to assume trailing digits are for added precision when there isn't any information
providing them.
I'm repeating myself, but that's the situation w/ promotion or translation. In both cases the course of action that is followed is to extend w/ zeros, but that leads to two different results, depending on whether one is extending zeros in the external or internal representation.
To see what is going on internally, find Tony's post and paste his code in and look at the actual bit patterns and it will probably become much more clear. Or, google on "floating point conversion" or similar and amongst the zillion of hits pretty early on there will be sites that have floating point calculators that you can type numbers into and see their internal representations.
Again, I heartily recommend at least reading through Goldberg's paper even if you don't study it in depth...
http://docs.sun.com/source/806-3568/ncg_goldberg.html
--
.
- Follow-Ups:
- Re: Singles to Doubles
- From: Michael C
- Re: Singles to Doubles
- From: Ralph
- 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: Jim Mack
- Re: Singles to Doubles
- From: Michael C
- Re: Singles to Doubles
- From: dpb
- Re: Singles to Doubles
- From: Michael C
- Re: Singles to Doubles
- From: dpb
- Re: Singles to Doubles
- From: Michael C
- Re: Singles to Doubles
- From: dpb
- Re: Singles to Doubles
- From: dpb
- Re: Singles to Doubles
- From: Michael C
- Singles to Doubles
- Prev by Date: Re: Problem changing Attributes of a file
- 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
|