equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
24 */ |
24 */ |
25 |
25 |
26 #ifndef __SAFE_MATH_H__ |
26 #ifndef __SAFE_MATH_H__ |
27 #define __SAFE_MATH_H__ |
27 #define __SAFE_MATH_H__ |
28 |
28 |
|
29 #include "mlib_types.h" |
|
30 |
29 #define SAFE_TO_MULT(a, b) \ |
31 #define SAFE_TO_MULT(a, b) \ |
30 (((a) > 0) && ((b) >= 0) && ((0x7fffffff / (a)) > (b))) |
32 (((a) > 0) && ((b) >= 0) && ((0x7fffffff / (a)) > (b))) |
31 |
33 |
32 #define SAFE_TO_ADD(a, b) \ |
34 #define SAFE_TO_ADD(a, b) \ |
33 (((a) >= 0) && ((b) >= 0) && ((0x7fffffff - (a)) > (b))) |
35 (((a) >= 0) && ((b) >= 0) && ((0x7fffffff - (a)) > (b))) |
34 |
36 |
|
37 #define IS_FINITE(a) \ |
|
38 (((a) >= MLIB_D64_MIN) && ((a) <= MLIB_D64_MAX)) |
|
39 |
35 #endif // __SAFE_MATH_H__ |
40 #endif // __SAFE_MATH_H__ |