The type of a function is not determined by the function name ending in a $ or 
% sign, but rather by what it returns - You can even write a function STRING% 
that returns a string or a function a$ that returns an integer value. The name 
you give your function is simply a hint to yourselves on what it might return.

What you actually return in your original function is the result of an 
/expression/ - and numerical expressions in S*BASIC are of type floating point. 
If you assign the value to the expression to a LOCal integer value and return 
that, you will actually get your desired result.

1000 DEFine FuNction x% (param)
1010   LOCal x%
1020   x% = param / 10
1025  REMark assign to integer variable x% to make sure INT is returned
1030  RETurn x%
1040 END DEFine x%

Dilwin's proposal /looks/ like it would be doing the right thing, but actually 
isn't. INT in S*BASIC returns a long integer which cannot be properly 
represented in the language, so it's actually converted to a floating point 
value and returned (albeit with the proper value).


> Am 10.08.2017 um 19:22 schrieb Dilwyn Jones via Ql-Users 
> <>:
> The fact that the function name ends in % doesn't seem to make it an integer 
> function (although the QL user guide says that "the type of data returned by 
> the function is indicated by the type appended to the function identifier") 
> any more than  parameter names have no type until they are set, so parameter 
> x% could be float or integer, depending on what it is made when parameters 
> are passed.
> As a workaround, add INT in line 160
> 160 IF INT(x%) < i : RETurn INT(x%) : ELSE return INT(i)
> Dilwyn
> -----Original Message----- From: Michael Bulford via Ql-Users
> Sent: Thursday, August 10, 2017 5:54 PM
> To: ;
> Subject: [Ql-Users] Function type error
> Hi all,
> I've no idea whether this has been mentioned before, but consider this … 100 
> :110 PRINT #0, Min_Int%(330.7, 440.7)120 PAUSE -1130 STOP140 :150 DEFine 
> FuNction Min_Int%(x%,i)160  IF x% < i : RETurn x% : ELSE : RETurn i170  END 
> DEFine The correct result should be 331, sincethis is an integer function.On 
> QPC2, SBASIC gives the result as 330.7QLiberator likewise also gives 330.7 
> Can anything be done? Michael
> _______________________________________________
> QL-Users Mailing List
> ---
> This email has been checked for viruses by AVG.
> _______________________________________________
> QL-Users Mailing List

QL-Users Mailing List

Reply via email to