Shop OBEX P1 Docs P2 Docs Learn Events
how to declare the variable for a real number? — Parallax Forums

how to declare the variable for a real number?

stevenoostevenoo Posts: 4
edited 2006-09-13 03:13 in BASIC Stamp
· hi,
····
····· if I want to do this arithmetic:·· 2.5 * 3.1 = 7.71

In basic stamp editor, I wrote like this

····· x·· var byte
····· y·· var byte
···· ans var byte

· main :
·········· x=2.5
·········· y=3.1
········· ans = x*y
········· debug ans
· end

·but it give me some error, anyone can help?

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-09-12 15:06
    Hello,

    ·· The BASIC Stamp cannot do floating point math directly, only integer math.· You would either have to calculate the values differently or get a floating-point co-processor.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-09-12 16:27
    x var byte
    y var byte
    ans var word
    x=25  ' represents 2.5
    y=31  ' represents 3.1
    ans=x*y
    debug DEC ans/100, ".", DEC2 ans, CR ' show 7.75
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • bytor95bytor95 Posts: 53
    edited 2006-09-12 16:42
    I've had tremdous success using the um-fpu floating point coprocessor. It took a couple of nights to get used to but now I'm manipulating numbers (div, mul, add, sub, cos, etc) using a basic stamp and am displaying the results on an lcd. The um-fpu coprocessor that you can buy for cheap off the parallax site does every single thing I asked for but it has it's own language that you will have to get used to.

    Here it is:
    http://www.parallax.com/detail.asp?product_id=604-00030



    Neil Peart=54 today.

    Engin
  • bytor95bytor95 Posts: 53
    edited 2006-09-12 18:58
    Or better yet, do what tracy just showed.

    Engin
  • stevenoostevenoo Posts: 4
    edited 2006-09-13 03:13
    hi,

    ··· it is very helpful to me, many thanks friends.smile.gif
Sign In or Register to comment.