FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
portable_utils.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2006-2008 Marc Brooker and Michael Inggs
4// Copyright (c) 2008-present FERS Contributors (see AUTHORS.md).
5//
6// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
7
8/**
9 * @file portable_utils.h
10 * @brief Utility functions for mathematical and system operations.
11 */
12
13#pragma once
14
15#include <cmath>
16#include <thread>
17
18#include "config.h"
19
20namespace core
21{
22 /**
23 * @brief Computes the Bessel function of the first kind (order 1) for a given value.
24 *
25 * @param x The value for which the Bessel function is to be computed.
26 * @return The computed value of the Bessel function of the first kind (order 1).
27 */
28 inline RealType besselJ1(const RealType x) noexcept
29 {
30#ifdef _MSC_VER
31 return _j1(x);
32#else
33 return j1(x);
34#endif
35 }
36
37 /**
38 * @brief Detects the number of CPUs on the machine.
39 *
40 * @return The number of CPUs detected, or 1 if detection fails.
41 */
42 inline unsigned countProcessors() noexcept
43 {
44 if (const unsigned hardware_threads = std::thread::hardware_concurrency(); hardware_threads > 0)
45 {
46 return hardware_threads;
47 }
48 LOG(logging::Level::ERROR, "Unable to get CPU count, assuming 1.");
49 return 1;
50 }
51}
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
#define LOG(level,...)
Definition logging.h:19
unsigned countProcessors() noexcept
Detects the number of CPUs on the machine.
RealType besselJ1(const RealType x) noexcept
Computes the Bessel function of the first kind (order 1) for a given value.
@ ERROR
Error level for error events.