GCC Code Coverage Report


Directory: ./
File: lib/geogram/basic/numeric.cpp
Date: 2026-09-07 02:28:19
Exec Total Coverage
Lines: 14 22 63.6%
Functions: 5 7 71.4%
Branches: 5 16 31.2%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40 #include <geogram/basic/numeric.h>
41 #include <geogram/basic/command_line.h>
42 #include <stdlib.h>
43
44 #include <random>
45
46 #ifdef GEO_COMPILER_EMSCRIPTEN
47 #pragma GCC diagnostic ignored "-Wc++11-long-long"
48 #endif
49
50 namespace GEO {
51
52 namespace Numeric {
53
54 static std::mt19937_64 random_engine;
55
56 bool is_nan(float32 x) {
57 #ifdef GEO_COMPILER_MSVC
58 return _isnan(x) || !_finite(x);
59 #else
60 return std::isnan(x) || !std::isfinite(x);
61 #endif
62 }
63
64 629211037 bool is_nan(float64 x) {
65 #ifdef GEO_COMPILER_MSVC
66 return _isnan(x) || !_finite(x);
67 #else
68
2/4
✓ Branch 0 taken 629211037 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 629211037 times.
629211037 return std::isnan(x) || !std::isfinite(x);
69 #endif
70 }
71
72 28 void random_reset() {
73
2/4
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 28 times.
✗ Branch 6 not taken.
28 random_reset(CmdLine::get_arg_int("algo:random_seed"));
74 28 }
75
76 266 void random_reset(int random_seed) {
77
1/2
✓ Branch 0 taken 266 times.
✗ Branch 1 not taken.
266 if(random_seed == -1) {
78 266 random_engine = std::mt19937_64();
79 } else if(random_seed == -2) {
80 std::random_device rnd;
81 random_engine = std::mt19937_64(rnd());
82 } else {
83 random_engine = std::mt19937_64(Numeric::uint64(random_seed));
84 }
85 266 }
86
87 6346140 int32 random_int32() {
88 6346140 return std::uniform_int_distribution<int32>(
89 0, std::numeric_limits<int32>::max()
90 6346140 )(random_engine);
91 }
92
93 float32 random_float32() {
94 return std::uniform_real_distribution<float32>(0, 1)(random_engine);
95 }
96
97 2693688 float64 random_float64() {
98 2693688 return std::uniform_real_distribution<float64>(0, 1)(random_engine);
99 }
100 }
101 }
102