Re: storing an integer in a double precision



Lynn McGuire <lmc@xxxxxxxxxx> wrote:

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.

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.

You won't need it in single precision either. I had a co-worker who used
to do that, allegedly because of some bad experience in a compiler from
long ago. I never did figure out what system that would have been from,
but we are talking before f66. I'm also not at all sure that it ever
actually was a problem; I strongly suspect that he put it there just in
case, without ever having seen a problem.

As noted elsewhere, the standard doesn't actually guarantee this. But
you won't find a compiler that it fails on in either single or double
precision. If you manage to belie me by finding one, I'd be very
interested in being shown the error of that particular one of my ways.

(Finding one doesn't mean recalling what someone thinks was the behavior
of some compiler from 40 years ago; I'm talking about actually finding
one running somewhere. I'll avoid saying who this parenthetical comment
is aimed at. :-))

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
.



Relevant Pages

  • Re: IBM2435I on ROUND(x,-3)
    ... You don't say what compiler and platform, but possible it's due to the conversion of the character constant. ... See the specific target types of coded arithmetic data using the attributes of the constant as the source. ... If an intermediate result is necessary, as in evaluation of an operational expression, the attributes of the intermediate result are the same as if a decimal fixed-point value of precision had appeared in place of the string. ...
    (comp.lang.pl1)
  • Re: IBM2435I on ROUND(x,-3)
    ... At run time the string itself may contain the character representation of any valid coded ... The key point is that at compile time, all that the assumption of FIXED DECIMALis used for is to determine the base, scale, mode, and precision that the value of the string will be converted to at run time. ... For each operation in an arithmetic expression, whether it be a prefix operation, an infix operation, or a builtin or user defined function, the compiler needs to know the base, scale, mode, and precision of each operand. ... Only in the case where a FIXED DECIMALvalue would have required no conversion is the string actually converted to those attributes. ...
    (comp.lang.pl1)
  • Re: increasing width
    ... the compiler will do an automatic conversion of either ... The problem is that zero is correctly ... represented in any precision on any existing machine. ... tell you that the standard allows a compiler ...
    (comp.lang.fortran)
  • Re: IBM2435I on ROUND(x,-3)
    ... fraction. ... If an intermediate result is necessary, as in evaluation of an operational expression, the attributes of the intermediate result are the same as if a decimal fixed-point value of precision had appeared in place of the string. ... In other words, FIXED DECIMALwould be converted to FLOAT DECIMAL, and in the actual conversion process, any fractional part of the constant expressed in character form would influence the exponent of the converted result and the fractional digits would not actually be lost. ... ROUNDreturns the value of the real expression x rounded at a digit specified by n. ...
    (comp.lang.pl1)
  • Re: Numerical accuracy of C++ and Fortran programs on 32 bit machines
    ... >> The lesson is, if in Fortran one wants full double precision, specify it ... the computer's floating-point does the conversion by ... > to X, but when it is printed out to 15 decimal digits, the inexactness ... > compiler should issue a warning, but in my opinion it should not be so ...
    (comp.programming)