Shop OBEX P1 Docs P2 Docs Learn Events
IEEE 754 Converter (Float question) — Parallax Forums

IEEE 754 Converter (Float question)

chenguanyannchenguanyann Posts: 15
edited 2011-09-17 12:16 in Robotics
I know the Calculation process of IEEE754 <---> float
But I try to use float object like FloatMath, Float32Full...etc
I can't calculate like is question on propoller chip...
0.75*3.125 (but 0.25/0.01 is OK)
How could I to do it?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-09-17 12:16
    Spin's use of floating point is a little mysterious for people who have not looked at the documentation for the Floating Point Object (Float32Full particularly). The Spin compiler will do floating point arithmetic on floating point constants, but not variables. In fact, there are really no floating point variables, just 32-bit longs, which are used to hold floating point values. You have to do all floating point arithmetic using function calls. For example, if you want to add two floating point values together, held in longs A and B, and put the result in C, you'd write:

    OBJ flt : "Float32Full"

    .....

    C := flt.fadd( A, B)

    If you want to multiply a floating point value D by the constant 3.125 and put the result into C, you'd write:

    C := flt.fmul( 3.125, D )

    There are other examples in the documentation for the floating point objects.
Sign In or Register to comment.