Coverage Report

Created: 2025-08-03 06:03

/src/h3/src/h3lib/include/mathExtensions.h
Line
Count
Source (jump to first uncovered line)
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
0
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
30
31
/** Evaluates to true if a + b would overflow for int32 */
32
0
static inline bool ADD_INT32S_OVERFLOWS(int32_t a, int32_t b) {
33
0
    if (a > 0) {
34
0
        return INT32_MAX - a < b;
35
0
    } else {
36
0
        return INT32_MIN - a > b;
37
0
    }
38
0
}
Unexecuted instantiation: coordijk.c:ADD_INT32S_OVERFLOWS
Unexecuted instantiation: h3Index.c:ADD_INT32S_OVERFLOWS
Unexecuted instantiation: latLng.c:ADD_INT32S_OVERFLOWS
Unexecuted instantiation: mathExtensions.c:ADD_INT32S_OVERFLOWS
39
40
/** Evaluates to true if a - b would overflow for int32 */
41
0
static inline bool SUB_INT32S_OVERFLOWS(int32_t a, int32_t b) {
42
0
    if (a >= 0) {
43
0
        return INT32_MIN + a >= b;
44
0
    } else {
45
0
        return INT32_MAX + a + 1 < b;
46
0
    }
47
0
}
Unexecuted instantiation: coordijk.c:SUB_INT32S_OVERFLOWS
Unexecuted instantiation: h3Index.c:SUB_INT32S_OVERFLOWS
Unexecuted instantiation: latLng.c:SUB_INT32S_OVERFLOWS
Unexecuted instantiation: mathExtensions.c:SUB_INT32S_OVERFLOWS
48
49
// Internal functions
50
int64_t _ipow(int64_t base, int64_t exp);
51
52
#endif