diff options
Diffstat (limited to 'lib/round.h')
| -rw-r--r-- | lib/round.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/round.h b/lib/round.h new file mode 100644 index 0000000..3aa6642 --- /dev/null +++ b/lib/round.h | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | #ifndef __LIB_ROUND_H | ||
| 2 | #define __LIB_ROUND_H | ||
| 3 | |||
| 4 | /* Yields X rounded up to the nearest multiple of STEP. | ||
| 5 | For X >= 0, STEP >= 1 only. */ | ||
| 6 | #define ROUND_UP(X, STEP) (((X) + (STEP) - 1) / (STEP) * (STEP)) | ||
| 7 | |||
| 8 | /* Yields X divided by STEP, rounded up. | ||
| 9 | For X >= 0, STEP >= 1 only. */ | ||
| 10 | #define DIV_ROUND_UP(X, STEP) (((X) + (STEP) - 1) / (STEP)) | ||
| 11 | |||
| 12 | /* Yields X rounded down to the nearest multiple of STEP. | ||
| 13 | For X >= 0, STEP >= 1 only. */ | ||
| 14 | #define ROUND_DOWN(X, STEP) ((X) / (STEP) * (STEP)) | ||
| 15 | |||
| 16 | /* There is no DIV_ROUND_DOWN. It would be simply X / STEP. */ | ||
| 17 | |||
| 18 | #endif /* lib/round.h */ | ||
