Code: Select all
Define val1.d=ValD("83.23195000000001")
Define val2.d=ValD("83.23195")
Debug StrD(val1,4) ; 83.2320
Debug StrD(val2,4) ; 83.2319
Debug FormatNumber(val1,4) ; 83.2320
Debug FormatNumber(val2,4) ; 83.2319
Code: Select all
Define val1.d=ValD("83.23195000000001")
Define val2.d=ValD("83.23195")
Debug StrD(val1,4) ; 83.2320
Debug StrD(val2,4) ; 83.2319
Debug FormatNumber(val1,4) ; 83.2320
Debug FormatNumber(val2,4) ; 83.2319
No, they shouldn't. No bug!
Code: Select all
Define val1.d=ValD("83.23195000000001")
Define val2.d=ValD("83.23195")
Debug StrD(val1,16) ; 83.2319500000000120
Debug StrD(val2,16) ; 83.2319499999999980
Debug StrD(val1,4) ; 83.2320
Debug StrD(val2,4) ; 83.2319
Code: Select all
Define val1.d=ValD("83.23195000000001")
Define val2.d=ValD("83.23195")
Debug StrD(val1+0.00005,4) ; 83.2320
Debug StrD(val2+0.00005,4) ; 83.2319
Debug FormatNumber(val1+0.00005,4) ; 83.2320
Debug FormatNumber(val2+0.00005,4) ; 83.2319
Wrong. You don't apply rounding recursively from the least significant to most significant digit.Cyllceaux wrote: Tue Feb 20, 2024 3:20 pm And... 0.049 should still rounding up. 49 -> 5 and 5 is rounding up
What kind of flag do you mean?
Code: Select all
Define Val.d = 83.03125
Debug StrD(Val, 4)
Code: Select all
Define Val.d = 0.4
For n = 1 To 35
Debug StrD(Val)
Val = 3*Val - 0.8 ; 3*0.4 - 0.8 = 1.2 - 0.8 = 0.4
Next
Code: Select all
#ML_SF = 10000
Define.i i
Define.d v = 0.4
Define.d vx = 0.8
Define.q vi = 0.4 * #ML_SF
Define.q vxi = 0.8 * #ML_SF
Debug "-- doubles --"
For i = 1 To 32
Debug Str(i) + ", " + StrD(v)
v = 3*v - vx ; 3*0.4 - 0.8 = 1.2 - 0.8 = 0.4
Next i
Debug StrD(v)
Debug "-- scaled --"
For i = 1 To 32
Debug Str(i) + ", " + StrD(vi)
vi = 3*vi - vxi ; 3*0.4 - 0.8 = 1.2 - 0.8 = 0.4
Next i
Debug StrD(vi/#ML_SF)
They haven't?Cyllceaux wrote: Wed Feb 21, 2024 12:16 pm My problem is... the "old" systems (Delphi, python and java) don't have problems with double.
[...]
@skywalk and STARGATE: thx for the clearing. My problem is, the old systems have no problems with converting and Math-Rounding. And the new Software has the have the same results. So yeah, I will try to build something.
Code: Select all
val = 83.23195
print(val)
print(format(val, ".4f"))
print(round(val, 4))
Also the Pure Basic community has published some includes and modules for math with fixed-point-numbers or for currency values.83.23195
83.2319
83.2319
STARGÅTE wrote: Tue Feb 20, 2024 9:09 pmThe calculation drifts away, because 0.4 as well as 0.8 cannot be represented in binary format and the error potentiates each time.Code: Select all
Define Val.d = 0.4 For n = 1 To 35 Debug StrD(Val) Val = 3*Val - 0.8 ; 3*0.4 - 0.8 = 1.2 - 0.8 = 0.4 Next