Commit 036fc1f
fix: implement integer abs in integer arithmetic, not via af_abs
af_abs promotes all integer inputs to f32 internally (complex.cpp uses
implicit(in_type, f32) which returns f32 for every integer dtype), so
any value with |x| > 2^24 gets rounded. For example abs(16777217)
returned 16777216.
Fix: dispatch abs in the Num (Array a) instance on the element dtype:
- signed integers (s16/s32/s64): select (x < 0) (0 - x) x
- unsigned / boolean (u8/u16/u32/u64/b8): identity (already >= 0)
- float / complex (f32/f64/c32/c64): delegate to A.abs as before
Also restrict Arbitrary CBool to {0, 1} — AF's b8 type normalises
non-zero floats to 1 on cast-back, so CBool 2 produced abs(2) = 1.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 07ef715 commit 036fc1f
2 files changed
Lines changed: 18 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
69 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
70 | 80 | | |
71 | 81 | | |
72 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
123 | 124 | | |
124 | 125 | | |
125 | 126 | | |
0 commit comments