ABS function failing in Delphi

Viewed 2744

In Delphi6 or in Delphi 2010, declare two variables of type Currency (vtemp1,vtemp2) and feed them a value of 0.09. Embed one of the variables with the ABS function and compare it to the other. You would expect for the comparison to yield a positive result as the compiler watch reveals the same value for abs(vtemp1) and vtemp2. Oddly the if statement fails!!!

Notes: -This problem is experienced only when dealing with the number 0.09 (trying several other near values revealed normal results) -Declaring the variable as Double instead of currency, the problem ceases to exist.

3 Answers

I have just found out the hard way that Delphi XE2 Abs function does not overload the currency type.

See the Delphi XE2 docwiki

these are the only types supported by abs

  • function Abs(X: ): Real; overload;
  • function Abs(X: ): Int64; overload;
  • function Abs(X: ): Integer; overload;
Related