aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chapters/image.adoc4
-rw-r--r--chapters/pseudocode.adoc10
2 files changed, 12 insertions, 2 deletions
diff --git a/chapters/image.adoc b/chapters/image.adoc
index da839f8..59e5ddf 100644
--- a/chapters/image.adoc
+++ b/chapters/image.adoc
@@ -85,8 +85,8 @@ for_each(0 <= n < N, 0 <= oy < OH, 0 <= ox < OW; 0 <= c < C) {
int32_t y = oy * scale_y_d + offset_y;
int32_t x = ox * scale_x_d + offset_x;
- int16_t iy = floor(y / scale_y_n);
- int16_t ix = floor(x / scale_x_n);
+ int16_t iy = idiv_floor(y, scale_y_n);
+ int16_t ix = idiv_floor(x, scale_x_n);
int16_t ry = y - iy * scale_y_n; // (y % scale_y_n)
int16_t rx = x - ix * scale_x_n; // (x % scale_x_n)
diff --git a/chapters/pseudocode.adoc b/chapters/pseudocode.adoc
index 55c35d4..d674c9c 100644
--- a/chapters/pseudocode.adoc
+++ b/chapters/pseudocode.adoc
@@ -477,6 +477,16 @@ int32_t idiv_check(int32_t input1, int32_t input2) {
return input1 / input2; // exact quotient without rounding
}
+// perform an integer division with rounding towards minus infinity
+
+int32_t idiv_floor(int32_t input1, int32_t input2) {
+ int32_t rval = input1 / input2;
+ if (rval * input2 > input1) {
+ rval--;
+ }
+ return rval;
+}
+
int32_t length(in_t input)
return number of elements in input list