|
Macaulay2 Engine
|
Overflow-checked integer arithmetic for monomial exponents and degree sums. More...
Go to the source code of this file.
Namespaces | |
| namespace | safe |
Macros | |
| #define | HAS_BUILTIN(x) |
| #define | expect_false(x) |
| #define | expect_true(x) |
Functions | |
| void | safe::ov (const char *msg) |
| static int32_t | safe::fits_7 (int32_t x, const char *msg) |
| static int32_t | safe::fits_15 (int32_t x, const char *msg) |
| static int32_t | safe::fits_31 (int32_t x, const char *msg) |
| static int32_t | safe::fits_7 (int32_t x) |
| static int32_t | safe::fits_15 (int32_t x) |
| static int32_t | safe::fits_31 (int32_t x) |
| static int32_t | safe::over_1 (int32_t x) |
| static int32_t | safe::over_2 (int32_t x) |
| static int32_t | safe::over_4 (int32_t x) |
| static int32_t | safe::add (int32_t x, int32_t y, const char *msg) |
| static int32_t | safe::add (int32_t x, int32_t y) |
| static int32_t | safe::add_to (int32_t &x, int32_t y, const char *msg) |
| static int32_t | safe::add_to (int32_t &x, int32_t y) |
| static int32_t | safe::sub (int32_t x, int32_t y, const char *msg) |
| static int32_t | safe::sub (int32_t x, int32_t y) |
| static int32_t | safe::sub_from (int32_t &x, int32_t y, const char *msg) |
| static int32_t | safe::sub_from (int32_t &x, int32_t y) |
| static int32_t | safe::sub_pos (int32_t x, int32_t y, const char *msg) |
| static int32_t | safe::sub_pos (int32_t x, int32_t y) |
| static int32_t | safe::minus (int32_t x, const char *msg) |
| static int32_t | safe::minus (int32_t x) |
| static int32_t | safe::pos_add (int32_t x, int32_t y, const char *msg) |
| static int32_t | safe::pos_add (int32_t x, int32_t y) |
| static int32_t | safe::pos_add_2 (int32_t x, int32_t y, const char *msg) |
| static int32_t | safe::pos_add_2 (int32_t x, int32_t y) |
| static int32_t | safe::pos_add_4 (int32_t x, int32_t y, const char *msg) |
| static int32_t | safe::pos_add_4 (int32_t x, int32_t y) |
| static int32_t | safe::mult (int32_t x, int32_t y, const char *msg) |
| static int32_t | safe::mult (int32_t x, int32_t y) |
| static int32_t | safe::mult_by (int32_t &x, int32_t y, const char *msg) |
| static int32_t | safe::mult_by (int32_t &x, int32_t y) |
| static int32_t | safe::div (int32_t x, int32_t y, const char *msg) |
| static int32_t | safe::div (int32_t x, int32_t y) |
| static int32_t | safe::div_by (int32_t &x, int32_t y, const char *msg) |
| static int32_t | safe::div_by (int32_t &x, int32_t y) |
Overflow-checked integer arithmetic for monomial exponents and degree sums.
Provides the safe:: arithmetic helpers (add, add_to, sub, sub_from, sub_pos, pos_add) and the bit-width predicates fits_7 / fits_15 / ... that monomial-arithmetic paths in the engine route through. Exponents are stored as int32_t; a silent wraparound in e + e' would not just produce a wrong answer but would put the result below either input, breaking the monomial-order invariant and potentially making a Groebner basis loop forever or reduce to a non-zero canonical form. Each helper performs the operation, checks the bound, and on failure calls safe::ov(msg) — which (in overflow.cpp) throws exc::overflow_exception.
The bound checks are bit-pattern tests against a high-bit mask (e.g. ((uint32_t)x & ~0x7f) != 0), not compiler overflow intrinsics; the header pulls in __has_builtin only to wire expect_false / expect_true macros around the bad path via __builtin_expect, so the success path stays branch-predicted. Callers include the aring-* family, the GB variants, the resolution engines, and the monoid / monomial-order machinery.
Definition in file overflow.hpp.