mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Fix two bugs with RGBASM fixed-point math (#1388)
- Fixed-point formulas are implemented using IEEE-754 floating-point internally, which could give infinity or NaN values whose conversion to fixed-point integer was platform-dependent. - Formatting fixed-point $8000_0000 (INT32_MIN, -2147483648) was not putting the negative sign in front.
This commit is contained in:
@@ -25,6 +25,10 @@ static double fix2double(int32_t i, int32_t q) {
|
||||
}
|
||||
|
||||
static int32_t double2fix(double d, int32_t q) {
|
||||
if (isnan(d))
|
||||
return 0;
|
||||
if (isinf(d))
|
||||
return d < 0 ? INT32_MIN : INT32_MAX;
|
||||
return (int32_t)round(d * pow(2.0, q));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user