MCPcopy Create free account
hub / github.com/numpy/numpy / safe_mul

Function safe_mul

numpy/core/src/common/npy_extint128.h:40–57  ·  view source on GitHub ↗

Integer multiplication with overflow checking */

Source from the content-addressed store, hash-verified

38
39/* Integer multiplication with overflow checking */
40static inline npy_int64
41safe_mul(npy_int64 a, npy_int64 b, char *overflow_flag)
42{
43 if (a > 0) {
44 if (b > NPY_MAX_INT64 / a || b < NPY_MIN_INT64 / a) {
45 *overflow_flag = 1;
46 }
47 }
48 else if (a < 0) {
49 if (b > 0 && a < NPY_MIN_INT64 / b) {
50 *overflow_flag = 1;
51 }
52 else if (b < 0 && a < NPY_MAX_INT64 / b) {
53 *overflow_flag = 1;
54 }
55 }
56 return a * b;
57}
58
59
60/* Long integer init */

Callers 3

diophantine_precomputeFunction · 0.85
diophantine_dfsFunction · 0.85
solve_diophantineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected