Beating a dead horse :) decimal math..
This has been asked a million times ive searched it all but still am lost. First off is there a· beginners faq/ tut/ guide to·math with the prop? Ive·got all my navigation stuff working with float math but need to double buffer the video so i dont have enough memory for the float32 stuff...
Say im using the gps object.. first lets just say we want to work with heading.. (I know the decimal isnt that important but for use as an example)
x := gps.heading······ gets a string of say 352.5
First. I think im supposed to just treat that as just 3525 but i dont even know how to "treat" that as 3525 in spin.·Ie convert it from the string.
Then what about BIG numbers like a latitude
so easy with teh float objects[noparse]:)[/noparse]
thanks for some tips
embarrassed
Jesse
Say im using the gps object.. first lets just say we want to work with heading.. (I know the decimal isnt that important but for use as an example)
x := gps.heading······ gets a string of say 352.5
First. I think im supposed to just treat that as just 3525 but i dont even know how to "treat" that as 3525 in spin.·Ie convert it from the string.
Then what about BIG numbers like a latitude
so easy with teh float objects[noparse]:)[/noparse]
thanks for some tips
embarrassed
Jesse

Comments
Try that.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit my site -> [url=Http://www.rawcircuits.com]www.rawcircuits.com[/url]
It is all assembler, though
Ale
In fact ive got my whole gps/waypoint navigation and wayppoint indicators all fully working with stringtofloat, float32 stuff and all the math all working...
I'm tryign to rewrite it all without using any floats and truly learn what im doing rather than just using other peoples objects blindly [noparse]:)[/noparse]
·
here are some routines to do Fixed point math. Its set up for 2 decimal places, but this can be changed with 2 constants:
CON DECPLC = 2 'Number of decimal places FACTOR = 100 '10^DECPLC VAR byte aux[noparse][[/noparse]16] 'Auxiliary string PUB StrToFixed(strptr) : val | i,p,dp,ng p := i := dp := ng := 0 repeat while i<DECPLC case byte[noparse][[/noparse]strptr++] "-": ng := True ".": dp := True "0".."9": val := val*10 + byte[noparse][[/noparse]strptr-1]-"0" if dp i++ other: if dp val*=10 strptr-- i++ else quit ifnot dp val*=FACTOR if ng -val PUB FMul(fxA,fxB) return fxA * fxB / FACTOR PUB FDiv(fxA,fxB) return fxA*FACTOR / fxB PUB FSqr(fxVal) return ^^(fxVal*FACTOR) ' For Add and Sub you use the normal operators (+,-) PUB FixedToString(fxVal) | i,p p~ if fxVal < 0 'Integer to String -FxVal aux[noparse][[/noparse]p++] := "-" i := 1_000_000_000 repeat 10 if FxVal => i aux[noparse][[/noparse]p++] := FxVal / i + "0" FxVal //= i result~~ elseif result or i == 1 aux[noparse][[/noparse]p++] := "0" i /= 10 aux[noparse][[/noparse]p] := 0 i := strsize(@aux)-DECPLC 'insert DecPoint at right place bytemove(@aux+i+1,@aux+i,i+DECPLC+1) aux[noparse][[/noparse] i] := "." return @aux 'return pointer to ResultStringAnd here an Example how to use it:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ tv : "TV_Text" PUB main | a,b tv.start(12) a := StrToFixed(string("99.9")) b := StrToFixed(string("-12.34")) a += b tv.str(FixedToString(a)) tv.out(13) a := StrToFixed(string("10")) b := StrToFixed(string("12.34")) a := FDiv(a,b) tv.str(FixedToString(a)) tv.out(13) a := StrToFixed(string("2.0")) a := FSqr(a) tv.str(FixedToString(a)) repeatHope this help...
Andy
yes thanks this is perfectly what i need.
Extremely helpful! Easy to see whats going on thanks I learned alot from this example
Jesse
·