Shop OBEX P1 Docs P2 Docs Learn Events
Another Dang code problem.... — Parallax Forums

Another Dang code problem....

Sniper KingSniper King Posts: 221
edited 2008-05-30 22:56 in Propeller 1
Trouble wth the Fp.Pow cmd in Float32Full

Here is the code (Bold/Red at the problem):

pub convert2Radians(quad,sPtr) : rads | i,fractPartPtr,c,dd,mm,mmmm,NM,miles,feet,degs,p
'' sPtr is a pointer to a latitude/longitude string in ddmm.mmmm or dddmm.mmmm format
'' returns the equivalent value in floating point radians (use fs.FloatToString(rads) to display value)
····
··· bytefill(@buf,0,20)································ 'clear buffer
··· bytemove(@buf,sPtr,strsize(sPtr))·················· 'Make a copy to mess with
··
··· i := 0
·····
··· repeat············································· 'Locate the '.' (decimal point)·
····· c:=buf[noparse][[/noparse] i++ ]
··· until c == "."
·······
··· buf[noparse][[/noparse] --i ] := 0···································· 'split into 2 strings by replacing '.' with null
···
··· fractPartPtr := @buf[noparse][[/noparse] i+1 ]························ 'Fractional part is what was after the '.'
··· i-=2··············································· 'back up 2 bytes to get the minutes
··· bytemove(@minPart[noparse][[/noparse] 0 ],@buf[noparse][[/noparse] i ],2)················ 'copy the mm part
··· minPart[noparse][[/noparse] 2 ] := 0·································· 'null terminate the mm part

···
··· dd·· := Format.atoi(@buf)/100······················ 'Remove mm part (divide by 100) and convert to number
··· mm·· := Format.atoi(@minPart)
··· mmmm := Format.atoi(fractPartPtr)
··
··· i := strsize(fractPartPtr)
·······
··· i := ff.ffloat(i)
····
··· p := fp.pow(10.0,i)··· 'Code·hangs Here!!!!!!!



··· dd·· := fp.ffloat(dd)
··· mm·· := fp.ffloat(mm)······························ 'Convert to floating point number
··· mmmm := fp.fdiv(fp.ffloat(mmmm),p)
····
··· degs := fp.fadd(fp.fdiv(fp.fadd(mm, mmmm),60.0),dd) 'Convert to decimal degrees


··· if strcomp(quad, string("S"))
····· degs := fp.fneg(degs)

··· if strcomp(quad, string("W"))
····· degs := fp.fneg(degs)

··· rads := fp.radians(degs)··························· 'Convert to radians
···
··· return rads


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·- Was it pin 11 or 26?· Hmmm....··I think the smell of smoke tells the whole story.· Must be 26.



Michael King
Application Engineer
R&D
Digital Technology Group

Comments

  • TreeLabTreeLab Posts: 138
    edited 2008-05-30 22:21
    a) Is the use of ff.ffloat(i) in the line just above the 'problem line' correct, or did you intend to use fp.ffloat(i)?

    b) Have you printed out the integer then float values of i prior to the call to fpower call?

    c) Would the function fp.Exp10(i) be as appropriate ?

    Cheers!

    PR
  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-30 22:29
    Why are you using ff. in one place and fp. everywhere else? There is an FFloat routine in both the Float32Full object and the Float32 object. I suggest you use an array of powers of 10 like
    DAT
    powers LONG 1.0, 10.0, 100.0, 1_000.0, 10_000.0, 100_000.0, 1_000_000.0, 10_000_000.0
    


    Then you'd use "powers[noparse][[/noparse] i ]" where "i" is a value from 0 to 7.
  • Chuck RiceChuck Rice Posts: 210
    edited 2008-05-30 22:56
    Mike Green said...
    I suggest you use an array of powers of 10 like
    DAT
    powers LONG 1.0, 10.0, 100.0, 1_000.0, 10_000.0, 100_000.0, 1_000_000.0, 10_000_000.0
    


    Then you'd use "powers[noparse][[/noparse] i ]" where "i" is a value from 0 to 7.

    Good idea Mike! I updated my version too.
Sign In or Register to comment.