Re: Singles to Doubles



Karl E. Peterson wrote:
Hi Bob --

What the heck? Seems silly to have to convert it to a String first, then
to a Double. But, it is more accurate. Anyone know of a less ugly way to
accurately replicate a Single with a Double, or this the best it gets?
Isn't it mainly that the Single isn't representing the value as accurately?

I guess, yeah. But how is it that a *String* seems to do so even more accurately?

No "guess" involved... :) "Yes".

The String conversion uses the i/o library and "cleans" up the representation for you that happens to be what you want in this case.

As a philosophy of promotion from Single to Double, except in the specific case such as you show here where it is known a priori (and from outside information) that the trailing digits of the value are, in fact, zeroes, the extension from single to double as done is, on the average, the more accurate representation of machine precision.

--
.


Loading