Page 2 of 2
Posted: Fri Mar 17, 2006 4:12 am
by Dare2
Howdy jack!
Interesting.
From time to time there are small variations in the float (show as hex) between various implementations (not just Pure to other, but other to other as well). It seems these make little difference to the end result, and floats are a best approximation anyway.
So, my guess is that to all intents and purposes PureBasic is as accurate as anything else. Is that your call as well?
Posted: Fri Mar 17, 2006 12:23 pm
by jack
Dare2, i have not tested PB enough in that regard, but one area you might look into is the PB conversion from string to double and from double to string, because the arithmetic itself is done by the FPU, so it should be OK

Posted: Fri Mar 17, 2006 1:59 pm
by Dare2
Thanks jack.
Posted: Sat Mar 18, 2006 1:20 am
by Xombie
I think you were right, jack. I messed around with some simple rounding functions got the behavior like I wanted. I'm guessing the F64 library was similar in several ways but just had a neater double to string function and such. Thanks for the info! It really helped me get my project at work moving again ^_^
Posted: Thu Mar 23, 2006 8:24 pm
by Xombie
Incidentally, if anyone cares, here is the quick and dirty solution I made for doing a few decimal things for doubles.
Code: Select all
Procedure.d RoundTwo(Value.d)
;
Define.s HoldValue
;
Define.l HoldLength
;
HoldValue = StrD(Value, 4)
;
HoldLength = Len(HoldValue)
;
If Val(Mid(HoldValue, HoldLength - 1, 1)) >= 5
;
ProcedureReturn ValD(Left(HoldValue, HoldLength - 2)) + 0.01
;
Else
;
ProcedureReturn ValD(Left(HoldValue, HoldLength - 2))
;
EndIf
;
EndProcedure
Procedure.s TruncateD(Value.d)
;
Define.s HoldValue : HoldValue = StrD(Value, 4)
;
Define.l HoldLength : HoldLength = Len(HoldValue)
;
If Val(Right(HoldValue, 4)) = 0 : ProcedureReturn Left(HoldValue, HoldLength - 5) : Else : ProcedureReturn Left(HoldValue, HoldLength - 2) : EndIf
;
EndProcedure
Procedure.s CommaDouble(Value.d)
;
Define.s HoldValue
;
Define.s HoldString
;
Define.l HasDecimal
;
Define.l *Position
;
Define.b iCount
;
HoldValue = TruncateD(Value)
;
HasDecimal = FindString(HoldValue, ".", 1)
;
*Position = @HoldValue + Len(HoldValue) - 1
;
While *Position > @HoldValue - 1
;
If (HasDecimal And *Position - @HoldValue < HasDecimal - 1) Or HasDecimal = #False
;
If iCount = 3 : HoldString = "," + HoldString : iCount = 0 : EndIf
;
iCount + 1
;
EndIf
;
HoldString = PeekS(*Position, 1) + HoldString
;
*Position - 1
;
Wend
;
ProcedureReturn HoldString
;
EndProcedure