Shop OBEX P1 Docs P2 Docs Learn Events
Repeat loop using floating point number — Parallax Forums

Repeat loop using floating point number

grasshoppergrasshopper Posts: 438
edited 2008-12-05 20:13 in Propeller 1
I am using a repeat loop that counts from 1 to 250 but 250 is in a floating point data type. I can say that it runs fine now, but will this cause problems on various propellers or any future problems that I may get hung up on?

Thanks

Comments

  • cgraceycgracey Posts: 14,133
    edited 2008-12-05 19:00
    The REPEAT loop works with integers only. The value 250 encoded as floating point is $437A0000, or 1,132,068,864 -- which would be a lot of loops.

    It sounds like you just assigned the integer value 250 to a variable and used that for·the REPEAT, which would work fine.

    To specify a floating point value, you must use a decimal point·or 'e' for exponent. For example, the floating-point value 250 would have to be specified as 250.0, or 2.5e2, or 25e1.

    Such floating point values can only be manipulated at run-time by using routines designed to handle that data type, such as those in floatmath.spin and floatstring.spin.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-05 19:02
    What do you mean by "floating point data type". There is no floating point data type in Spin or Propeller assembly language. You can write floating point constants which are converted to IEEE754 floating point representation, but these are treated as 32 bit integer values outside of constant expressions. You can write a repeat loop that uses the floating point function library to do its arithmetic, but a "for x = 1.0 to 250.0" doesn't work as you might expect.

    The intention is for existing software to work the same (allbeit faster) on the Prop II as much as possible. Since the Prop II design is still in flux, noone can say for sure whether there will be changes required to the floating point library other than improvements using the new features (like hardware multiply).
  • grasshoppergrasshopper Posts: 438
    edited 2008-12-05 19:54
    Well I mean "Floating Point" as in below

    
       Nub1 := math.Ffloat(250)                             
       Temp1 := 0
       Temp2 := 0
       Temp3 := 0 
     
         
      Repeat X from 1 to Nub1                              ' Get temp 250 times loop // here i float the number 250
       
             /Getting data in here for Temp1
            Temp1 := Temp1+ Temp2                    ' Add it up
             
        Temp2 := Math.Ffloat(Temp1)                            
        Temp3 := Math.Fdiv(Temp2, Nub1)
    
    
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-05 20:13
    Like I said, "Repeat X from 1 to Nub1" won't do what you expect it to do. math.Ffloat(250) converts the 250 (which is $FA in hex) to IEEE754 format which comes out to something like $43FD0000 in hex. The REPEAT works out to "Repeat X from 1 to $43FD0000" since that's all done using integer arithmetic.

    If you're interested in how floating point works, read en.wikipedia.org/wiki/IEEE_754-2008 and www.validlab.com/goldberg/paper.ps
Sign In or Register to comment.