Re: storing an integer in a double precision



Lynn McGuire <lmc@xxxxxxxxxx> wrote:

(snip)
Just a lack of understanding of conversion between integers and
double precision on my part. Back when we were primarily single
precision, we had to be very careful, using "ii = xx + 0.1" to
ensure that we did not loose the whole number value of a
incomplete conversion of 12,000 which was stored in the float
as 11.9999.

Well, that is a different question. One hopes that converting
an integer to floating point gives the exact value, and the
conversion back also.

Other than that, there is no guarantee that one gets the exact
value, and many cases where it is unlikely or at least even
odds.

xx = 1./3.
yy = xx * 3
j = yy

Has fairly good odds of not giving 1 for j.

I have noticed lately that I have gotten lazy since we converted
the entire program to double precision and don't add the 0.1
conversion factor anymore as we don't seem to need it anymore.

Not so obvious to me. Though IEEE has some rounding requirements
that others don't, which might increase the odds.

-- glen
.



Relevant Pages

  • Re: Change real numbers to complex numbers, very easy question
    ... to double precision and I know of no requirement for that conversion ... conversion and I don't see where the standard requires that to be exact. ...
    (comp.lang.fortran)
  • Re: storing an integer in a double precision
    ... double precision on my part. ... conversion factor anymore as we don't seem to need it anymore. ... allegedly because of some bad experience in a compiler from ...
    (comp.lang.fortran)
  • Re: Can I force precision loss?
    ... > Casting long to int doesn't affect precsision, ... > conversion is exact or the result is completely different. ... The compiler is issuing you with an error because your type conversion loses ... you acknowledge the "loss of precision" ...
    (comp.lang.java.programmer)
  • Re: storing an integer in a double precision
    ... that were converted but without roundoff? ... double precision on my part. ... conversion factor anymore as we don't seem to need it anymore. ...
    (comp.lang.fortran)
  • Re: storing an integer in a double precision
    ... that were converted but without roundoff? ... double precision on my part. ... conversion factor anymore as we don't seem to need it anymore. ...
    (comp.lang.fortran)