BCDToInt produces incorrect results
Original Reporter info from Mantis: Milla
-
Reporter name:
Original Reporter info from Mantis: Milla
- Reporter name:
Description:
The BCDToInt function has a number of errors that produce incorrect results:
-
Only the least significant byte of a BCD value is converted to an integer
e.g. BCDToInt ($1234) returns 34 -
Invalid BCD values do not raise an exception - instead they return an incorrect result
e.g. BCDToInt ($A0) returns 100 -
Negative BCD values are not supported.
e.g. BCDToInt ($7D) returns 83 instead of -7
I have attached a patch that addresses the above issues.
Additional information:
The format for negative BCD numbers has been taken from http://en.wikipedia.org/wiki/Binary-coded_decimal#Packed_BCD, where the lower four bits of the lowest byte are used as the sign flag. A value of $B or $D indicates a negative value.
Mantis conversion info:
- Mantis ID: 13512
- Version: 2.2.2
- Fixed in version: 2.4.0
- Fixed in revision: 13052 (#8cae53bb)
- Monitored by: » Milla (Milla)