Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
pi.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MATH_PI_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MATH_PI_HPP_
7
8// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
9#include "arene/base/compiler_support/attributes.hpp"
10#include "arene/base/constraints/constraints.hpp"
11#include "arene/base/stdlib_choice/enable_if.hpp"
12#include "arene/base/stdlib_choice/is_same.hpp"
13// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
14
15// parasoft-begin-suppress AUTOSAR-A7_1_5-a-2 "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
16
17namespace arene {
18namespace base {
19namespace numbers {
20
21namespace pi_detail {
22/// @brief Undefined function used in the primary definition of @c pi_v to trigger an error if a type other than @c
23/// float or @c double is used to instantiate it, without an explicit specialization
24/// @tparam Type The type used to instantiate @c pi_v
25/// @return This function is declared to return a value of the specified type, but no definition is provided, so nothing
26/// is actually returned
27template <typename Type>
28auto instantiation_of_unspecialized_value() -> Type;
29
30/// @brief The value of Pi, in the specified floating point type. @c Type must be @c float or @c double , or a type for
31/// which an explicit specialization of @c pi_v has been made
32/// @tparam Type The chosen type
33template <typename Type, typename = constraints<>>
34extern constexpr Type pi_v{pi_detail::instantiation_of_unspecialized_value<Type>()};
35
36/// @brief The value of Pi as a @c float
37template <typename Type>
38extern constexpr float pi_v<Type, constraints<std::enable_if_t<std::is_same<Type, float>::value>>>{
39 3.141592653589793238462643383279F
40};
41
42/// @brief The value of Pi as a @c double
43template <typename Type>
44extern constexpr double pi_v<Type, constraints<std::enable_if_t<std::is_same<Type, double>::value>>>{
45 3.141592653589793238462643383279
46};
47
48} // namespace pi_detail
49
50/// @brief The value of Pi, in the specified floating point type. @c Type must be @c float or @c double , or a type for
51/// which an explicit specialization of @c pi_v has been made
52/// @tparam Type The chosen type
53template <typename Type>
54extern constexpr Type pi_v{pi_detail::pi_v<Type>};
55
56// parasoft-begin-suppress AUTOSAR-M7_3_3-a CERT_CPP-DCL59-a "Per-TU references all refer to the same object"
57namespace {
58// parasoft-begin-suppress CERT_CPP-DCL56-a "False positive: pi_v is initialized"
59/// @brief The value of Pi as a @c double
60// NOLINTNEXTLINE(readability-identifier-length)
61ARENE_MAYBE_UNUSED constexpr double const& pi{pi_v<double>};
62// parasoft-end-suppress CERT_CPP-DCL56-a
63} // namespace
64 // parasoft-end-suppress AUTOSAR-M7_3_3-a CERT_CPP-DCL59-a
65 //
66} // namespace numbers
67} // namespace base
68} // namespace arene
69
70#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_MATH_PI_HPP_
Definition arithmetic_identities.hpp:13
constexpr Type pi_v
The value of Pi, in the specified floating point type. Type must be float or double ,...
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10