| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: C64 BASIC - what`s faster INT() or %? Plus benefits of DEF FN A() |
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 | FidoUsenet Gateway (3:770/3) SEEN-BY: 57/0 116/102 153/150 250 226/20 317/2 3 393/68 633/267 280 640/384 SEEN-BY: 712/620 848 770/0 1 3 100 340 772/0 1 210 500 @PATH: 770/3 1 712/848 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.