[PB4 Beta 4] test values.d failed

Just starting out? Need help? Post your questions and find answers here.
Heis Spiter
User
User
Posts: 41
Joined: Fri Aug 22, 2003 7:10 pm
Location: 76 (FRANCE)
Contact:

[PB4 Beta 4] test values.d failed

Post by Heis Spiter »

I was trying to do a program who tests Intel's processor (Bugs found by Tim Coe (and co :lol:)).
I've done it with float like that and it works.

Code: Select all

OpenConsole()
res.f = 4195835/3145727
PrintN(StrF(res))
If res.f <> 1.3338204491362411
  PrintN("First test failed.")
EndIf
Repeat
  Delay(1)
Until Inkey()
B.f = 4.1 - 1.1
A.f = 699306 * B
Q.f = A/B
PrintN(StrF(Q))
If Q <> 699306
  PrintN("Second test failed.")
EndIf
Repeat
  Delay(1)
Until Inkey()
res.f = 4.999999/14.999999
PrintN(StrF(res))
If res.f <> 0.33333328888888591
  PrintN("Third test failed.")
EndIf
PrintN("End")
Repeat
  Delay(1)
Until Inkey()
CloseConsole()
End
After, I tried to replace, in test 1 and 3, floats by double. To have the good value, I made first the right calcul, and I copy the new result in the code, and I've done it

Code: Select all

OpenConsole()
res.d = 4195835/3145727
PrintN(StrD(res))
If res.d <> 1.3338204491362411
  PrintN("First test failed.")
EndIf
Repeat
  Delay(1)
Until Inkey()
B.f = 4.1 - 1.1
A.f = 699306 * B
Q.f = A/B
PrintN(StrF(Q))
If Q <> 699306
  PrintN("Second test failed.")
EndIf
Repeat
  Delay(1)
Until Inkey()
res.d = 4.999999/14.999999
PrintN(StrD(res))
If res.d <> 0.33333328888888591
  PrintN("Third test failed.")
EndIf
PrintN("End")
Repeat
  Delay(1)
Until Inkey()
CloseConsole()
End
And with this code (and double), tests 1 and 3 doesn't work.

So I've tried a small code :

Code: Select all

res.d = 4195835/3145727
Debug res.d
If res.d = 1.3338204491362411
  Debug 1
Else
  Debug 0
EndIf
;----------------------------
res.d = 4195835/3145727
good.d = 1.3338204491362411
Debug res.d
If res.d = good.d
  Debug 1
Else
  Debug 0
EndIf
It always returns 0, however, the calculates value is as the "constant".
Fred
Administrator
Administrator
Posts: 18161
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

You can't compare for equality float or double with safe, as the result is of an operation isn't always the same than the constant value.
Post Reply