About */ for PropBASIC
caskaz
Posts: 957
Hi, everybody.
I need help about operator "*/".
value is 58.
$0180 = 1.5
Is this correct?
Where is it wrong?
Post Edited (caskaz) : 5/15/2010 1:20:53 PM GMT
I need help about operator "*/".
value1 VAR long value VAR long value1= 10000 value = value1 */ $0180
value is 58.
$0180 = 1.5
Is this correct?
Where is it wrong?
Post Edited (caskaz) : 5/15/2010 1:20:53 PM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
Post Edited (JonnyMac) : 5/15/2010 3:44:39 PM GMT
The */ operator can be used to multiply by mixed values up to about 4095.996.
· */ can be used for values just under 65536 (not 4096).
· Use */ to multiply by fractional values from just under 65536 to 1 by multipling by 65536.
· Use ** to multiply by values less than 1 by multipling by 65536*65536.
So to do multiply by 1.5 you take 1.5 * 65536 = 98304. So value */ 98304 = value * 1.5
To multiply by 0.5 you take 0.5 * 65536 * 65536 = 2147483648. So value ** 2147483648 = value * 0.5.
To get the most resolution, you can use ** only for the fractional part and use a normal "*" for the whole part.
' value = value * 5000.01
temp = value ** 42949673·· ' temp = value * 0.01
value = value * 5000
value = value + temp
* All of this works because PropBasic does a 32bit*32bit=64bit multiply. So with a 64 bit result, you can shift the result to divide it by 65536 or (65536*65536).
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
Post Edited (Bean) : 5/15/2010 4:13:01 PM GMT
100 x 53.6870912 and this should equal 5368.70912
The attached test_math.pbas yields 5268 !! Can someone show me what I am
doing wrong ? thanks for your help
You need to add "value" to "value_dec" after the ** operation.
value_dec = value ** 2951034233
value_dec = value_dec + value
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
Post Edited (Bean) : 6/17/2010 4:59:28 PM GMT
How can you tell if a number is negative ?
thanks again for your help
So for the ** operator if the decimal is 0.5 or higher, the result will be negative.
For your example, could you just use */ 3518437 ?
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There are two rules in life:
· 1) Never divulge all information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]