Shop OBEX P1 Docs P2 Docs Learn Events
math help needed — Parallax Forums

math help needed

ionion Posts: 101
edited 2004-09-01 16:00 in BASIC Stamp
hi ,
i have a math problem and need some help to solve it
i have two numbers :
a=90000000 and b=75000000
both of the numbers are divided in high· and low like
a= 9000 high and 0000 low. the same for b.
i have also a limit level like c=1567
b it will increment if an event happen
i would like to monitor b in a such way that when a-b=c to get an output or alarm or a conditional branch to do something.
thanks
ion
·

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2004-09-01 07:06
    Ion -

    Thanks to Tracy Allen, here is a tutorial on how to do double precision (32 bit) math with the Basic Stamp:
    http://www.emesystems.com/BS2math6.htm

    Regards,

    Bruce Bates
  • Tracy AllenTracy Allen Posts: 6,657
    edited 2004-09-01 07:55
      a0 VAR Word
      a1 VAR Word
      b0 VAR Word
      b1 VAR Word
      c1 VAR Word
      c0  VAR Word
    
      a1 = 9000 : a0 = 0000
      b1 = 7500 : b0 = 0000
      DO
         b0=b0+1
         IF b0 >= 10000 THEN b0 = b0-10000 : b1= b1+1  ' carry
         c0 = a0 - b0
         IF c0.bit15 THEN c0 = c0 + 10000 : c1 = c1-1  ' borrow
         IF c0 = 1567 AND c1=0 THEN DEBUG "wowzer!"
      LOOP
    



    If you let that loop run, it should print "wowzer" on your screen after a wait of about 12 hours!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • ionion Posts: 101
    edited 2004-09-01 10:30
    Thank you very much Bruce and Tracy.
    Iwill go to that site and do my home work. You save me a lot of headeche
    Thank again
    ion
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-01 14:18
    Note of caution: the variables B0 and B1 conflict with internal variable names.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Tracy AllenTracy Allen Posts: 6,657
    edited 2004-09-01 16:00
    Jon is right--We have to keep one another on our toes!--If you try the above program, the compiler v2.1 will come back with a message "Symbol is already defined". Change b0 and b1 to x0 and x1 (or whatever).

    The symbols b0 and b1 would point to the same space in the RAM as a0.byte0 and a1.byte1.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.