Subj : Re: C64 BASIC - what's faster INT() or %? Plus benefits of DEF FN A() To : Holger From : Shaun Bebbington Date : Thu Apr 19 2018 12:53:27 On Thursday, 19 April 2018 12:21:32 UTC+1, Holger wrote: > Am 17.04.2018 um 04:46 schrieb John H. Guillory: > > SB> For clarification, which is faster? > > SB> 10 X=INT(64*RND(0)+1) > > SB> or > > SB> 10 X%=64*RND(0)+1 > > > > Just guessing, I'd say the second one, or 10 X%=64*RND(0)+1 > > because in the first, your converting 64*RNND(0)+1 to an integer, then > > converting back to a single precision decimal point value. > > > Effectively, calculations always happen in floating point, and INT() > returns a FP value in the floating point accu. Conversion will take > place on assignment to the destination variable. The INT() operation is > similar to the truncation operation to fit the FP accu value into X%. > In fact, the major difference is that the first line has to copy 5 bytes > into a variable space and the second will copy 2 bytes. > > There isn't even an advantage in space requirement for the variable; > both need 7 bytes, i.e. 2 bytes for the name (like A1 or B2% or C3$) and > 5 for the value; an integer variable just wastes 3 bytes for the value. > It is different for integer vs. float arrays; in this case a % value is > indeed packed into 2 bytes. > > -hl Thanks for the information, but using X% still saves two bytes and some processor time if used correctly. I'm looking for optimised BASIC as in speed where possible, rather than technically perfect BASIC which could never be achieved anyway. I get enough performance from Blitz to be happy :-) Regards, Shaun. --- SoupGate-Win32 v1.05 * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3) .