StarSlash in Propeller
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
·
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
·
Comments
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
Would you mind if I use the name "StarSlash" for a real Propeller video game?
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·