PDA

View Full Version : About */ for PropBASIC



caskaz
05-15-2010, 09:15 PM
Hi, everybody.

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

JonnyMac
05-15-2010, 11:38 PM
You're using an 8-bit value (BS2-style) -- PropBASIC uses a 16-bit [fractional] value so 1.5 x 65536 = 98304 ($1_8000).

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA

Post Edited (JonnyMac) : 5/15/2010 3:44:39 PM GMT

caskaz
05-15-2010, 11:40 PM
Jonny, Thanks.

The */ operator can be used to multiply by mixed values up to about 4095.996.

Bean
05-16-2010, 12:04 AM
caskaz,
· */ 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. [RUSH - Freewill]

Post Edited (Bean) : 5/15/2010 4:13:01 PM GMT

camelot2
06-17-2010, 11:15 PM
hi, I am trying to use Bean's multipication code to multiply the following:
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

Bean
06-17-2010, 11:46 PM
The problem is that 2951034233 is actually a negative number on the Propeller.
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. [RUSH - Freewill]

Post Edited (Bean) : 6/17/2010 4:59:28 PM GMT

camelot2
06-18-2010, 01:53 AM
I'm sorry but I am a newbie.

How can you tell if a number is negative ?

thanks again for your help

Bean
06-18-2010, 01:57 AM
Numbers over 2_147_483_647 will be considered negative.

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. [RUSH - Freewill]