Double inacurracy

Everything else that doesn't fall into one of the other PB categories.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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?
@}--`--,-- A rose by any other name ..
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post 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 :)
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Thanks jack.
@}--`--,-- A rose by any other name ..
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post 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 ^_^
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post 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
Post Reply