Skip to content

Commit e2b6a8e

Browse files
committed
pbio/int_math: Document truncation for mult_then_div.
This can lead to small (non-accumalative) rounding errors in user-getter functions, like robot.angle(). This is generally not an issue, but helpful to be aware of.
1 parent fddeecf commit e2b6a8e

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/pbio/src/angle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int32_t pbio_angle_to_low_res(const pbio_angle_t *a, int32_t scale) {
132132
return 0;
133133
}
134134

135-
// Scale down rotations component.
135+
// Scale down rotations component. NB: Truncates, does not round.
136136
int32_t rotations_component = pbio_int_math_mult_then_div(a->rotations, MDEG_PER_ROT, scale);
137137

138138
// Scale down millidegree component, rounded to nearest ouput unit.

lib/pbio/src/int_math.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ int32_t pbio_int_math_atan2(int32_t y, int32_t x) {
257257
* The product of @p a and @p b must not exceed 2**47, and the result after
258258
* division must not exceed 2**31. @p c must not exceed 2**16.
259259
*
260+
* Truncates the result as conventional with integer division.
261+
*
260262
* Adapted from https://stackoverflow.com/a/57727180, CC BY-SA 4.0
261263
*
262264
* @param [in] a Positive or negative number.

0 commit comments

Comments
 (0)