Coverage Report

Created: 2025-10-12 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
0
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
30
31
/** Evaluates to true if a + b would overflow for int32 */
32
4.57k
static inline bool ADD_INT32S_OVERFLOWS(int32_t a, int32_t b) {
33
4.57k
    if (a > 0) {
34
1.88k
        return INT32_MAX - a < b;
35
2.68k
    } else {
36
2.68k
        return INT32_MIN - a > b;
37
2.68k
    }
38
4.57k
}
39
40
/** Evaluates to true if a - b would overflow for int32 */
41
2.16k
static inline bool SUB_INT32S_OVERFLOWS(int32_t a, int32_t b) {
42
2.16k
    if (a >= 0) {
43
1.44k
        return INT32_MIN + a >= b;
44
1.44k
    } else {
45
        return INT32_MAX + a + 1 < b;
46
720
    }
47
2.16k
}
48
49
// Internal functions
50
int64_t _ipow(int64_t base, int64_t exp);
51
52
#endif