round.h 587 B

123456789101112131415161718192021222324252627
  1. /* Copyright 2013 Google Inc. All Rights Reserved.
  2. Distributed under MIT license.
  3. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
  4. */
  5. /* Helper for rounding */
  6. #ifndef WOFF2_ROUND_H_
  7. #define WOFF2_ROUND_H_
  8. #include <limits>
  9. namespace woff2 {
  10. // Round a value up to the nearest multiple of 4. Don't round the value in the
  11. // case that rounding up overflows.
  12. template<typename T> T Round4(T value) {
  13. if (std::numeric_limits<T>::max() - value < 3) {
  14. return value;
  15. }
  16. return (value + 3) & ~3;
  17. }
  18. } // namespace woff2
  19. #endif // WOFF2_ROUND_H_