PDA

View Full Version : StarSlash in Propeller

Newzed
10-22-2006, 09:05 PM
As far as I know, there is no equivalent of the PBasic·' */· '·operator in Spin.· If there is, this is wasted effort.

Here is a method that lets you multiply a number by a decimal:

PUB starslash(n,i,f)····
·· z := n*i + ((n*f)/1000)

"n" is your number, "i" is the integer portion of the multiplier and "f" is the decimal portion of the multiplier without the decimal point.· "z" is a LONG global variable.

If you want to multiply 77 by 3.375 you would call:

··· starslash(77,3,375)·· ' 0.3 percent error

If you want to multiply 77 by 0.375 you would call:

··· starslash(77,0,375)·· '· 3 percent error

The error percentage decreases sharply with larger results for "z".· For example:

··· starslash(475,3 375)

has an error of .007 percent.

Hope this helps someone.

Sid

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?

Newzed@aol.com (mailto:Module?Newzed@aol.com)
·

Tracy Allen
10-23-2006, 12:17 AM
However, there is the ** operator, which returns the upper 32 bits of a 32x32 multiply. That makes a very accurate fractional multiplaction, a 32 bit binary fraction.

f := 1610612736 ' 0.375 = 1610612736/(2^32), the 32 bit binary fraction representing 0.375. Very accurate
' ....
PUB star4star(n,i,f) ' multiplicand, integer part of multiplier, fractional part of multiplier.
z := (n * i) + (n ** f)

You can make your method more accurate by including more decimal digits in the multiplier, e.g. f/100000 = 37567/100000, so long as n*f does not overflow 32 bits. Or use binary long division to approximate the fraction by a ** multiplier, e.g. 37567 / 100000 = 1613490364/(2^32).

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com (http://www.emesystems.com)

Dennis Ferron
10-26-2006, 10:55 AM

Would you mind if I use the name "StarSlash" for a real Propeller video game?

Newzed
10-26-2006, 06:56 PM
Be my guest, Dennis.

Sid

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?

Newzed@aol.com (mailto:Module?Newzed@aol.com)
·