Skip to content

Commit a9faf0e

Browse files
committed
Add comment to docs and tune example
1 parent 0dfca04 commit a9faf0e

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ The widths depend on the compiler command line options `-mdouble=32`
265265
`std::exp()` and the like will, therefore, have input and output
266266
widths according to these command line options.
267267

268+
- **`<cmath>`:** In compiler versions of `avr-gcc` 11 and higher,
269+
slight discrepancies in the signatures of functions like
270+
`isnan()`, `isinf()`, etc. seem to be in the process of being corrected.
271+
Future patches of math function signatures in `<cmath>`
272+
may be needed as the `<math.h>` header continues to evolve.
273+
268274
## C++20 `constexpr` support
269275

270276
The following is a rather advanced, highly useful topic.

examples/cmath/cmath.cpp

+20-15
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@ namespace local {
1717

1818
namespace detail {
1919

20-
template<typename real_value_type, typename real_function_type>
20+
template<typename RealValueType, typename RealFunctionType>
2121
auto integral
2222
(
23-
const real_value_type& a,
24-
const real_value_type& b,
25-
const real_value_type& tol,
26-
real_function_type real_function
27-
) noexcept -> real_value_type
23+
const RealValueType& a,
24+
const RealValueType& b,
25+
const RealValueType& tol,
26+
RealFunctionType real_function
27+
) noexcept -> RealValueType
2828
{
29+
using real_value_type = RealValueType;
30+
using real_function_type = RealFunctionType;
31+
2932
std::uint_fast32_t n2(1);
3033

3134
real_value_type step = ((b - a) / 2U);
@@ -75,11 +78,13 @@ auto is_close_fraction
7578
const FloatingPointType tol = FloatingPointType(std::numeric_limits<FloatingPointType>::epsilon() * FloatingPointType(100))
7679
) noexcept -> bool
7780
{
81+
using floating_point_type = FloatingPointType;
82+
7883
using std::fabs;
7984

80-
const FloatingPointType ratio = fabs(FloatingPointType((FloatingPointType(1) * a) / b));
85+
const floating_point_type ratio = fabs(floating_point_type((floating_point_type(1) * a) / b));
8186

82-
const FloatingPointType closeness = fabs(FloatingPointType(1 - ratio));
87+
const floating_point_type closeness = fabs(floating_point_type(1 - ratio));
8388

8489
return (closeness < tol);
8590
}
@@ -96,9 +101,9 @@ template<> constexpr long double pi_v<long doub
96101
template<typename FloatingPointType>
97102
auto cyl_bessel_j(const std::uint_fast8_t n, const FloatingPointType& x) noexcept -> FloatingPointType
98103
{
99-
using local_float_type = FloatingPointType;
104+
using floating_point_type = FloatingPointType;
100105

101-
constexpr local_float_type epsilon = std::numeric_limits<local_float_type>::epsilon();
106+
constexpr floating_point_type epsilon = std::numeric_limits<floating_point_type>::epsilon();
102107

103108
using std::cos;
104109
using std::sin;
@@ -109,15 +114,15 @@ auto cyl_bessel_j(const std::uint_fast8_t n, const FloatingPointType& x) noexcep
109114
const auto integration_result =
110115
detail::integral
111116
(
112-
static_cast<local_float_type>(0),
113-
detail::pi_v<local_float_type>,
117+
static_cast<floating_point_type>(0),
118+
detail::pi_v<floating_point_type>,
114119
tol,
115-
[&x, &n](const local_float_type& t) noexcept -> local_float_type
120+
[&x, &n](const floating_point_type& t) noexcept -> floating_point_type
116121
{
117-
return cos(x * sin(t) - (t * static_cast<local_float_type>(n)));
122+
return cos(x * sin(t) - (t * static_cast<floating_point_type>(n)));
118123
});
119124

120-
const auto jn = static_cast<local_float_type>(integration_result / detail::pi_v<local_float_type>);
125+
const auto jn = static_cast<floating_point_type>(integration_result / detail::pi_v<floating_point_type>);
121126

122127
return jn;
123128
}

0 commit comments

Comments
 (0)