Subj : Re: C64 BASIC - what's faster INT() or %? Plus benefits of DEF FN A() To : Holger From : Charles Richmond Date : Mon May 07 2018 14:06:45 On 4/19/2018 6:21 AM, 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. > I am *not* sue about CBM, but C=64 BASIC does all its arithmetic in floating point. That means if you have a line like: 120 X% = A% * B% ....this forces the interpreter to *convert* A% and B% to floating point, then do the multiplication using the floating point routines, then convert the answer back to an integer and store the answer in X%. Not very efficient to do... -- numerist at aquaporin4 dot com --- SoupGate-Win32 v1.05 * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3) .