break a float in several parts to be able to analy
Community Forums/General Help/break a float in several parts to be able to analy
| ||
break a float in several parts to be able to analyze each part of a float Hello, :) Here is a simple routine that i have coded to be able to analyze each part of a float (the part which is more than 0 and the parts which are less than 0) This can be useful for a grid based movement with a 1.0 or 0.1 or 0.01 or 0.001 positioning precision... Graphics(640,480,32,2) SeedRnd(MilliSecs()) Global FloatPartsCount% Dim FloatPart%(10) TestFloat# = Rnd(-100.0,100.0) DebugLog("TestFloat = "+TestFloat) MsStart% = MilliSecs() For l% = 1 To 1000 Step 1 BreakFloat(TestFloat) Next MsTime% = MilliSecs() - MsStart For I% = 1 To FloatPartsCount Step 1 DebugLog(FloatPart(I)) Next DebugLog("MsTime = "+Float(MsTime)/1000) WaitKey() End() ;break a float in different parts to be able to analyze each part of the float Function BreakFloat(TFloat#) TString$ = Str(Abs(TFloat)) CharsCount% = Len(TString) FloatPartsCount = 0 TPart$ = "" C% = 0 LoopState = True Repeat C = C + 1 TChar$ = Mid(TString,C,1) If( TChar <> "." ) TPart = TPart + TChar Else If( TChar = "." ) FloatPartsCount = FloatPartsCount + 1 FPI% = FloatPartsCount FloatPart(FPI) = TPart For CC% = C+1 To CharsCount Step 1 FloatPartsCount = FloatPartsCount + 1 FPI% = FloatPartsCount FloatPart(FPI) = Mid(TString,CC,1) Next LoopState = False EndIf Until( C = CharsCount ) Or ( LoopState = False ) End Function This seems fast enough for what i want to do, but i am curious how you would do it ? Thanks, |
| ||
This routine does not work correctly if the float is inferior to 0.001 because Blitz3d returns something like 9.e-004 (for 0.0009)... |