Code: Select all
i.f = 2047.9
Repeat
Debug i
i + 0.0001
ForEver
End
Code: Select all
i.f = 2047.9
Repeat
Debug i
i + 0.0001
ForEver
End
so, no Bug!I know float limits...
Code: Select all
Procedure.f IncF(Value.f)
Protected *Long.Long = @Value
If Not IsNAN(Value)
If Value > 0
If Not IsInfinity(Value)
*Long\l + 1
EndIf
ElseIf Value < 0
*Long\l - 1
Else
*Long\l = 1
EndIf
EndIf
ProcedureReturn Value
EndProcedure
i.f = 2048
Debug i
Debug IncF(i)
You have to use doubles.djes wrote:Thank you very much for these great codes, STARGÅTE ! Anyway, it hurted me when I saw that I cannot add 0.0001 to 2048 :/ . I'd like to have an example to how to handle this, without using doubles
Don't know why, but I'm sure you'll regret to have spoken so fast.Trond wrote:You have to use doubles.djes wrote:Thank you very much for these great codes, STARGÅTE ! Anyway, it hurted me when I saw that I cannot add 0.0001 to 2048 :/ . I'd like to have an example to how to handle this, without using doubles
Right, I forgot you can use long doubles (10 bytes) with inline asm.djes wrote:Don't know why, but I'm sure you'll regret to have spoken so fast.Trond wrote:You have to use doubles.djes wrote:Thank you very much for these great codes, STARGÅTE ! Anyway, it hurted me when I saw that I cannot add 0.0001 to 2048 :/ . I'd like to have an example to how to handle this, without using doubles
Code: Select all
;****************************************************************************
;*
;* Minimal increment value
;* Show floating point accuracy depending on range
;* djes 12/3/2010
;* based on Regenduft's code
;*
;****************************************************************************
;* IncF by Regenduft
;* http://www.purebasic.fr/german/viewtopic.php?f=8&t=23364
;*
;* >= Value to increment by the minimal floating point possible
;* => incremented value
;*
Procedure.f IncF(Value.f)
Protected *l.Long = @Value
If *l\l & $7F800000 <> $7F800000 Or *l\l & $7FFFFF = 0 ; IsNAN(Value)=0 <- Geschwindigkeitsoptimierung
; positive Float inkrementieren
If Value > 0
If *l\l < $7F800000 ; IsInfinity(Value)=0 <- Geschwindigkeitsoptimierung
*l\l + 1
EndIf
; negative Float inkrementieren
ElseIf Value < 0
*l\l - 1
; Null-Float inkrementieren
Else
*l\l = 1
EndIf
EndIf
ProcedureReturn Value
EndProcedure
;****************************************************************************
;- MAIN
OpenConsole()
EnableGraphicalConsole(1)
MinDiff1.f = 0
MinDiff2.f = 0
ConsoleLine = 1
For u = 0 To $7FFFFFFF Step 1
ConsoleLocate(0, 0)
Print(RSet(Str(u), 10))
i1.f = u
Diff.f = IncF(i1) - i1
If Diff > MinDiff1
MinDiff1 = Diff
ConsoleLocate(0, ConsoleLine)
PrintN("New min increment value found : at " + RSet(Str(i1), 10) + " -> " + RSet(StrF(MinDiff1), 10))
ConsoleLine + 1
EndIf
i2.f = 0-u
Diff.f = IncF(i2) - i2
If Diff > MinDiff2
MinDiff2 = Diff
ConsoleLocate(0, ConsoleLine)
PrintN("New min increment value found : at " + RSet(Str(i2), 10) + " -> " + RSet(StrF(MinDiff2), 10))
ConsoleLine + 1
EndIf
Next u