Skip to content

Commit 46e6bb5

Browse files
committed
Replace FP division with fixed-point shift in atan2
The double-precision division was replaced with bit shift operation in twin_atan2_first_quadrant(), using right shift by 15 bits equivalent to division by 32768.
1 parent bc0c266 commit 46e6bb5

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/trig.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ static twin_angle_t twin_atan2_first_quadrant(twin_fixed_t y, twin_fixed_t x)
148148
}
149149
}
150150

151-
return (twin_angle_t) (double) angle / (32768.0) * TWIN_ANGLE_360;
151+
/* Fixed-point conversion: angle * TWIN_ANGLE_360 / 32768 */
152+
return (twin_angle_t) ((angle * TWIN_ANGLE_360) >> 15);
152153
}
153154

154155
twin_angle_t twin_atan2(twin_fixed_t y, twin_fixed_t x)

0 commit comments

Comments
 (0)