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.

<quote>
The constant has base, scale, mode, and precision attributes. It converts to the attributes of the target when they are independent of the source attributes, as in the case of assignment. 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 (N,0) had appeared in place of the string. (This allows the compiler to generate code to handle all cases, regardless of the attributes of the contained constant.) Consequently, any fractional portion of the constant might be lost.
</quote>

http://publibfp.boulder.ibm.com/cgi-bin/bookmgr/BOOKS/c1472851/5.6?DT=20110908013800

On 12/22/2011 2:37 AM, Robin Vowels wrote:
Hi,
I'm puzzled about the following conversion via ROUND.
Any ideas?
_________________

test: procedure options (main);

declare d fixed (10,5);

d = '1234.567';

put skip data (d);

d = round('1234.567', 2);

put skip data (d);

end test;

Output:

D= 1234.56700;
D= 1234.00000;

.



Relevant Pages

  • 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: 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)
  • 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)