home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.sys.cbm      Discussion about Commodore micros      53,866 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 52,257 of 53,866   
   Charles Richmond to Holger   
   Re: C64 BASIC - what's faster INT() or %   
   07 May 18 14:06:45   
   
   From: numerist@aquaporin4.com   
      
   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: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca