You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix precision in fixed-pt conversion to avoid overflow
The previous implementation used ((angle * TWIN_ANGLE_360) >> 15) which
caused integer overflow when angle values reached their maximum range of
[-9092, 9092]. The multiplication 9092 * 4096 results in 37,240,832,
exceeding the 16-bit signed integer limit.
This commit simplifies the expression by factoring out the constants:
- Original: angle * TWIN_ANGLE_360 / 32768
- Since TWIN_ANGLE_360 = 2^12 and 32768 = 2^15
- Simplified: angle * 2^12 / 2^15 = angle / 8
Use integer division (not right shift) to match original truncate-towards-zero
behavior for negative values. Right shift would round towards negative infinity,
causing precision errors for ~87.5% of negative angle values (all non-multiples
of 8).
Benefits:
1. Eliminates integer overflow risk
2. Avoids incorrect double-precision cast
3. Removes floating-point operations
4. Preserves exact precision for all angle values
Addresses review comments from @jouae and @weihsinyeh in PR #110.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
0 commit comments