Shop OBEX P1 Docs P2 Docs Learn Events
About */ for PropBASIC — Parallax Forums

About */ for PropBASIC

caskazcaskaz Posts: 957
edited 2010-06-17 17:57 in Propeller 1
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

Comments

  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-05-15 15:38
    You're using an 8-bit value (BS2-style) -- PropBASIC uses a 16-bit [noparse][[/noparse]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
  • caskazcaskaz Posts: 957
    edited 2010-05-15 15:40
    Jonny, Thanks.

    The */ operator can be used to multiply by mixed values up to about 4095.996.
  • BeanBean Posts: 8,129
    edited 2010-05-15 16:04
    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. [noparse][[/noparse]RUSH - Freewill]

    Post Edited (Bean) : 5/15/2010 4:13:01 PM GMT
  • camelot2camelot2 Posts: 54
    edited 2010-06-17 15:15
    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
  • BeanBean Posts: 8,129
    edited 2010-06-17 15:46
    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. [noparse][[/noparse]RUSH - Freewill]

    Post Edited (Bean) : 6/17/2010 4:59:28 PM GMT
  • camelot2camelot2 Posts: 54
    edited 2010-06-17 17:53
    I'm sorry but I am a newbie.

    How can you tell if a number is negative ?

    thanks again for your help
  • BeanBean Posts: 8,129
    edited 2010-06-17 17:57
    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. [noparse][[/noparse]RUSH - Freewill]
Sign In or Register to comment.