Shop OBEX P1 Docs P2 Docs Learn Events
Really dumb question — Parallax Forums

Really dumb question

kq6fkq6f Posts: 5
edited 2006-12-11 18:30 in BASIC Stamp
Am almost afraid to ask, but can the BS2 do fractional math. Suppose I want to divide two numbers and get the result to say 2 or 3 decimal places. How do I do it? All I can find in the manual are references to INTEGER math...

Comments

  • Steve JoblinSteve Joblin Posts: 784
    edited 2006-12-11 18:27
    No such thing as a "dumb" question 'round here...

    Check out http://www.emesystems.com/BS2index.htm... Tracy Allen has some great write ups about this very topic!
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-12-11 18:30
    Technically, the BS2 does not do 'floating point math'. You can get around this, a little, by using "fixed point" math. That's where you assign one or two levels of precision to 10ths and 100dredths.

    As in -- the value "2000" will actually represent "20.00". As long as you 'scale' numbers properly, this can work.

    Now, one additional problem is the BS2 math currently maxes out with "Words" -- or 16-bit quantities. So you can have values from zero to 65535. If you assign two decimal places, that becomes zero to 655.35 -- so that can be limiting.

    There ARE ways of doing 32-bit math -- but it's going to be slow, since you'll have to manipulate the low-Word and high-Word yourself in PBasic code.
Sign In or Register to comment.