diff options
author | babenko <babenko@yandex-team.com> | 2024-11-06 13:24:38 +0300 |
---|---|---|
committer | babenko <babenko@yandex-team.com> | 2024-11-06 13:54:01 +0300 |
commit | b60a78031c047a8c8543bf6a3dc4f828d104dd3c (patch) | |
tree | e8ff58e6fe24f57d35a6cc9a91ca61522706d088 /library/cpp/yt/misc/numeric_helpers.h | |
parent | 658682dbe663353ecdf6cb50a846c54b3dd24481 (diff) | |
download | ydb-b60a78031c047a8c8543bf6a3dc4f828d104dd3c.tar.gz |
NaN-safe comparison and hashing
commit_hash:46d59ab3acbd313753d3e46f3a6f10a8ebc424d8
Diffstat (limited to 'library/cpp/yt/misc/numeric_helpers.h')
-rw-r--r-- | library/cpp/yt/misc/numeric_helpers.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/library/cpp/yt/misc/numeric_helpers.h b/library/cpp/yt/misc/numeric_helpers.h new file mode 100644 index 0000000000..20844029c2 --- /dev/null +++ b/library/cpp/yt/misc/numeric_helpers.h @@ -0,0 +1,31 @@ +#pragma once + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + +template <class T> +T DivCeil(const T& numerator, const T& denominator); + +//! A version of division that is a bit less noisy around the situation +//! when numerator is almost divisible by denominator. Round up if the remainder +//! is at least half of denominator, otherwise round down. +template<class T> +T DivRound(const T& numerator, const T& denominator); + +template <class T> +T RoundUp(const T& numerator, const T& denominator); + +template <class T> +T RoundDown(const T& numerator, const T& denominator); + +template <class T> +int GetSign(const T& value); + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT + +#define NUMERIC_HELPERS_INL_H_ +#include "numeric_helpers-inl.h" +#undef NUMERIC_HELPERS_INL_H_ |