Skip to content

Commit a1bee0a

Browse files
committed
Fix a severe bug in abs()
1 parent aee3d95 commit a1bee0a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fix32.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// ZEPTO-8 — Fantasy console emulator
33
//
4-
// Copyright © 2016–2023 Sam Hocevar <[email protected]>
4+
// Copyright © 2016–2024 Sam Hocevar <[email protected]>
55
//
66
// This program is free software. It comes without any warranty, to
77
// the extent permitted by applicable law. You can redistribute it
@@ -172,7 +172,7 @@ struct fix32
172172
// Free functions
173173

174174
// PICO-8 0.2.3 changelog: abs(0x8000) should be 0x7fff.ffff
175-
static inline fix32 abs(fix32 a) { return a.m_bits > 0 ? a : -a.m_bits > 0 ? ~a : -a; }
175+
static inline fix32 abs(fix32 a) { return a.m_bits >= 0 ? a : a.m_bits << 1 == 0 ? ~a : -a; }
176176

177177
static inline fix32 min(fix32 a, fix32 b) { return a < b ? a : b; }
178178
static inline fix32 max(fix32 a, fix32 b) { return a > b ? a : b; }

0 commit comments

Comments
 (0)