On 16 Dec 2006, at 17:01, Laurence W Reeves wrote:

> P Witte wrote:
>> Marcel Kilgus writes:
>>
>>
>>> Wolfgang Lenerz wrote:
>>>
>>>>> On an ordinary QL I can type
>>>>>
>>>>> f%=-32768/1
>>>>>
>>>>> and find that f% now contains -32768.
>>>>>
>>>>>
>>>> Well that must be a nice bug.
>>>>
>>>> unless I'm mistaken, 32768/1 = 32768
>>>>
>>>> and 32768 just doesn't fit in an integer.
>>>>
>>> Yes, but -32768 does. Notice the minus ;-)
>>>
>>
>> Ah, but  the rub is that "f%=-32768/1" is within range and shouldnt
>> overflow.
> Hi all..
>
> This strikes me as a *very* serious bug.
>
> The comment that "32768/1" doesn't fit in an integer is totally  
> irrelevent, as the use of the "/", rather than "DIV", means the  
> calculation will always be done in floating point.
>
> The result, in any case, is "-32768" which is a perfectly valid  
> integer.
>
> What actually happens with "f%=-32768/1" (at least in Minerva) is  
> that the line is parsed to give tokens for "f%", "=", "-32768",  
> "/", "1" and end-of-line. At run time, the two integer values are  
> each converted to floating point and the division is performed (or  
> rather not performed by Minnie, as it notices the division by  
> unity, and ignores it!). The resultant floating point "-32768.0" is  
> then converted back to an integer for the assignment.
>
> Syntactically, the minus sign in "f%=0-32768/1" (mentioned in the  
> original post from George) is no longer the prefix monadic operator  
> (which can be legitimately be combined with the 32768 to form an  
> integer token), but is now the infix dyadic operator. The  
> tokenisation will now use floating point for the "32768" (saving  
> one int->fp conversion!).
>
> Yet other variants of writing the code could look like "f%=- 
> +327.68E2/+100E-2". Offhand, I'm not sure what happens with these.  
> I'm fairly sure Minerva tends lose the cruddy bits during (re-) 
> tokenisation... it's like that.
>
> Bugs aside, the question I'd ask is why someone is using "/"  
> instead of "DIV" when they are apparent intend to do integer  
> calculations. (A challenge... find a genuine *practical* reason for  
> "/" versus "DIV", other than saving typing.)
>

"/" does save the fingers as opposed to DIV. However

f%=-32768 DIV 1

works with SMSQE.

You might like to know that

f%=-32768/1

works if you compile it with Turbo and then run the compiled program.

George
>
_______________________________________________
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm

Reply via email to