Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/trig.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,15 @@ static twin_angle_t twin_atan2_first_quadrant(twin_fixed_t y, twin_fixed_t x)
}
}

return (twin_angle_t) (double) angle / (32768.0) * TWIN_ANGLE_360;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this commit also aim to fix the incorrect casting of the variable angle from twin_angle_t to double?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this commit also aim to fix the incorrect casting of the variable angle from twin_angle_t to double?

Yes, intentionally.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then, why didn't you write this purpose on this commit log ?

/* Fixed-point conversion: angle / 32768 * TWIN_ANGLE_360
* 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
* non-multiples of 8. Avoids overflow since no intermediate multiplication
* required.
*/
return (twin_angle_t) (angle / 8);
}

twin_angle_t twin_atan2(twin_fixed_t y, twin_fixed_t x)
Expand Down