-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate arithmetic_operation from arithmetic_files (#3020)
- Loading branch information
Showing
84 changed files
with
2,042 additions
and
2,152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#pragma once | ||
|
||
#include <Common/Exception.h> | ||
#include <common/likely.h> | ||
|
||
namespace DB | ||
{ | ||
namespace ErrorCodes | ||
{ | ||
extern const int ILLEGAL_DIVISION; | ||
} | ||
|
||
#pragma GCC diagnostic push | ||
#pragma GCC diagnostic ignored "-Wsign-compare" | ||
|
||
template <typename A, typename B> | ||
inline void throwIfDivisionLeadsToFPE(A a, B b) | ||
{ | ||
/// Is it better to use siglongjmp instead of checks? | ||
|
||
if (unlikely(b == 0)) | ||
throw Exception("Division by zero", ErrorCodes::ILLEGAL_DIVISION); | ||
|
||
/// http://avva.livejournal.com/2548306.html | ||
if (unlikely(std::is_signed_v<A> && std::is_signed_v<B> && a == std::numeric_limits<A>::min() && b == -1)) | ||
throw Exception("Division of minimal signed number by minus one", ErrorCodes::ILLEGAL_DIVISION); | ||
} | ||
|
||
template <typename A, typename B> | ||
inline bool divisionLeadsToFPE(A a, B b) | ||
{ | ||
if (unlikely(b == 0)) | ||
return true; | ||
|
||
if (unlikely(std::is_signed_v<A> && std::is_signed_v<B> && a == std::numeric_limits<A>::min() && b == -1)) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
|
||
#pragma GCC diagnostic pop | ||
|
||
} // namespace DB |
Oops, something went wrong.