Code: Select all
test.f=0.15
For x=1 To 5
z.f = x
If test = z*0.05: MessageRequester("", "OK"): endif
next x
end
Code: Select all
test.f=0.15
For x=1 To 5
z.f = x
z*0.05
If test = z: MessageRequester("", "OK"): endif
next x
end
Code: Select all
test.f=0.15
For x=1 To 5
z.f = x
If test = z*0.05: MessageRequester("", "OK"): endif
next x
end
Code: Select all
test.f=0.15
For x=1 To 5
z.f = x
z*0.05
If test = z: MessageRequester("", "OK"): endif
next x
end
Try like thisStoring numbers such as 0.11 are more difficult and may be stored as a number such as 0.10999999. You can try to display to only a limited range of digits, but do not be surprised if the number displays different from what you would expect!
Code: Select all
x.f = 0.11
debug f
Code: Select all
test.f = 0.15
For x = 1 To 5
z.f = x
If test = z*0.05
Debug "OK"
Else
If cmp(z*0.05, test)
Debug "OK in procedure?"
EndIf
EndIf
Next
I suppose that's one for the wishlist, then.Fred wrote:You can not compare the result of an expression (stored in 80 bits float precision) with the result already casted to float (32 bits precision) as it will be probably a bit rounded. Equalities with float are not accurate.
Code: Select all
Procedure.f Float(a.f)
ProcedureReturn a
EndProcedure
test.f=0.15
For x=1 To 5
z.f = x
If test = Float(z*0.05): MessageRequester("", "OK"): EndIf
Next x
End
Code: Select all
void main()
{
float float1 = 0.15;
float float2 = 1;
if (float1 == float2*0.15)
printf("OK1\n");
if (float1 == (float)(float2*0.15))
printf("OK2\n");
}