/src/h3/src/h3lib/include/mathExtensions.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2017-2018, 2022 Uber Technologies, Inc. |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | * you may not use this file except in compliance with the License. |
6 | | * You may obtain a copy of the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | /** @file mathExtensions.h |
17 | | * @brief Math functions that should've been in math.h but aren't |
18 | | */ |
19 | | |
20 | | #ifndef MATHEXTENSIONS_H |
21 | | #define MATHEXTENSIONS_H |
22 | | |
23 | | #include <stdbool.h> |
24 | | #include <stdint.h> |
25 | | |
26 | | /** |
27 | | * MAX returns the maximum of two values. |
28 | | */ |
29 | 4.29k | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) |
30 | | |
31 | | /** Evaluates to true if a + b would overflow for int32 */ |
32 | 4.67G | static inline bool ADD_INT32S_OVERFLOWS(int32_t a, int32_t b) { |
33 | 4.67G | if (a > 0) { |
34 | 944M | return INT32_MAX - a < b; |
35 | 3.73G | } else { |
36 | 3.73G | return INT32_MIN - a > b; |
37 | 3.73G | } |
38 | 4.67G | } Unexecuted instantiation: localij.c:ADD_INT32S_OVERFLOWS coordijk.c:ADD_INT32S_OVERFLOWS Line | Count | Source | 32 | 4.67G | static inline bool ADD_INT32S_OVERFLOWS(int32_t a, int32_t b) { | 33 | 4.67G | if (a > 0) { | 34 | 944M | return INT32_MAX - a < b; | 35 | 3.73G | } else { | 36 | | return INT32_MIN - a > b; | 37 | 3.73G | } | 38 | 4.67G | } |
Unexecuted instantiation: h3Index.c:ADD_INT32S_OVERFLOWS Unexecuted instantiation: mathExtensions.c:ADD_INT32S_OVERFLOWS Unexecuted instantiation: latLng.c:ADD_INT32S_OVERFLOWS |
39 | | |
40 | | /** Evaluates to true if a - b would overflow for int32 */ |
41 | 2.73G | static inline bool SUB_INT32S_OVERFLOWS(int32_t a, int32_t b) { |
42 | 2.73G | if (a >= 0) { |
43 | 1.41G | return INT32_MIN + a >= b; |
44 | 1.41G | } else { |
45 | | return INT32_MAX + a + 1 < b; |
46 | 1.31G | } |
47 | 2.73G | } Unexecuted instantiation: localij.c:SUB_INT32S_OVERFLOWS coordijk.c:SUB_INT32S_OVERFLOWS Line | Count | Source | 41 | 2.73G | static inline bool SUB_INT32S_OVERFLOWS(int32_t a, int32_t b) { | 42 | 2.73G | if (a >= 0) { | 43 | 1.41G | return INT32_MIN + a >= b; | 44 | 1.41G | } else { | 45 | | return INT32_MAX + a + 1 < b; | 46 | 1.31G | } | 47 | 2.73G | } |
Unexecuted instantiation: h3Index.c:SUB_INT32S_OVERFLOWS Unexecuted instantiation: mathExtensions.c:SUB_INT32S_OVERFLOWS Unexecuted instantiation: latLng.c:SUB_INT32S_OVERFLOWS |
48 | | |
49 | | // Internal functions |
50 | | int64_t _ipow(int64_t base, int64_t exp); |
51 | | |
52 | | #endif |