John W Kennedy wrote:
> On 2011-12-24 10:14:56 +0000, Robin Vowels said:
>
>> On Dec 24, 2:10 am, John W Kennedy <
jwke...@attglobal.net> wrote:
>>> On 2011-12-22 23:32:29 +0000, Robin Vowels said:
>>>
>>>> On Dec 23, 12:56 am, glen herrmannsfeldt <
g...@ugcs.caltech.edu>
>>>> wrote:
>>>
>>>>> I was remembering 36 years ago when I used a CHAR variable as the
>>>>> argument of SQRT. I do remember that the square root was done in double
>>>>> precision floating point, but I didn't remember how it got there.
>>>>> So, after converting to fixed dec(N,0), in the case of SQRT,
>>>
>>>> No it doesn't. It converts to FIXED DEC (M, n), preserving any
>>>> fraction.
>>>
>>> No it doesn't. You have already seen the quote from the manual earlier
>>> in this thread.
>>
>> Yu're wrong.
>> Go look at the immediately preceding post to yours,
>> where the results are shown [here repeated]:
>>
>>> put skip list ( sqrt('9.9'), sqrt(9.90000000000000e0) );
>>
>>> Output:
>>
>>> 3.14642654451045E+0000 3.14642654451045E+0000
>>
>> What do you see?
>
> I see an idiot who thinks that when a compiler doesn't do what the manual says, the manual must be wrong.
>
Gentlemen, please. Instead of calling each other names, let's see if we can't sort this out.
A couple of days ago, I said that the application of the sentence in the manual that is the crux or the matter here
seemed inconsistent. After thinking it over for a couple of days, I believe I can explain the apparent anomaly.
Let us first consider the relevant passage in the manual concerning the conversion of character strings used in expressions:
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 (M,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. See the specific target types of coded
arithmetic data using FIXED DECIMAL as the source.
Note the following:
1. The attributes of the intermediate result are the same as if ...
2. ... any fractional portion of the constant *might* be lost.
3. See the specific target types ... using FIXED DECIMAL as source.
Note also that the functions in question in this discussion are generic in the sense that the behavior of the function
and the attributes of the returned result depend on the attributes of the argument(s).
Now consider the definition of the SQRT builtin function:
SQRT(x) returns a floating-point value that is an approximation of the positive square root of the expression x. It has
the base, mode, and precision of x. If x is real, it must not be less than zero.
From this it is evident that the scale of both the result and the actual argument is float. Therefore the value of the
argument is converted to FLOAT DECIMAL. Moreover the source to target rules for this case state:
FIXED DECIMAL (p1,q1)
The precision of the result is p2=p1. The exponent indicates any fractional part of the value.
In other words, FIXED DECIMAL(M,) would be converted to FLOAT DECIMAL(M), 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.
In short no actual inconsistency.
Finally consider the definition of the ROUND builtin function:
ROUND(x,n) returns the value of the real expression x rounded at a digit specified by n. The result has the mode, base,
and scale of x. If x is negative, the absolute value is rounded and the sign is restored.
n Optionally-signed integer. It specifies the digit at which rounding is to occur. n must conform to the limits of
scaling-factors for FIXED data. If n is greater than 0, rounding occurs at the (n)th digit to the right of the point. If
n is zero or negative, rounding occurs at the (1-n)th digit to the left of the point.
The precision of a fixed-point result is given in the following example where (p,q) is the precision of x, and N is the
maximum number of digits allowed:
(max(1,min(p-q+1+n,N)),n)
Thus, n specifies the scaling factor of the result.
In this case, the mode of the result is REAL, the base is DECIMAL, and the scale id FIXED. A DECIMAL FIXED(M,0) value
would be "converted" to DECIMAL FIXED(M,0). When the actual conversion of the character value happens any fractional
digits will be lost since none are available in the target.
Again no actual inconsistency.