Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/compile_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
unittests-linux-generic:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
container:
image: ghcr.io/modm-ext/modm-build-avr:latest

Expand All @@ -19,7 +19,7 @@ jobs:

steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Check environment
run: |
Expand Down
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,6 @@ The widths depend on the compiler command line options `-mdouble=32`
`std::exp()` and the like will, therefore, have input and output
widths according to these command line options.

- **`<cmath>`:** In compiler versions of `avr-gcc` 11 and higher,
slight discrepancies in the signatures of functions like
`isnan()`, `isinf()`, etc. seem to be in the process of being corrected.
Future patches of math function signatures in `<cmath>`
may be needed as the `<math.h>` header continues to evolve.

## C++20 `constexpr` support

The following is a rather advanced, highly useful topic.
Expand Down Expand Up @@ -342,8 +336,8 @@ in the [./examples/numeric](./examples/numeric) directory.
## Additional details

`avr-libstdcpp` is intended for a modern `avr-gcc`
such as the 11.2 port available in the [modm-io project](https://github.com/modm-io/avr-gcc)
repository. Tests show usability also for `avr-gcc` 10 through 13 (and beyond).
such as the port available in the [modm-io project](https://github.com/modm-io/avr-gcc)
repository. Tests show usability also for `avr-gcc` 7 through 14 (and beyond).

Using the port way back to `avr-gcc` 5, however, does not work
at the moment with today's form of the checked-in library,
Expand All @@ -357,6 +351,6 @@ and the library include files in [`include/` and its subfolders](./include/)
(with two exceptions for the sources, as mentioned below)
are licensed under [GNU General Public License Version 3](./COPYING3) or higher.

The [example codes](./examples/) and two library source files
All of the [example codes](./examples/) and also two library source files
(namely `functexcept.cc` and `math.cc` in [`src/`](./src/))
are subject to the terms of the [Mozilla Public License Version 2.0](./COPYING.MPLv2).
35 changes: 26 additions & 9 deletions examples/cmath/cmath.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Christopher Kormanyos
* Copyright (c) 2022, 2025, Christopher Kormanyos
*
* This file is part of the modm project.
*
Expand Down Expand Up @@ -33,7 +33,7 @@ auto integral
real_value_type step = ((b - a) / 2U);
real_value_type result = (real_function(a) + real_function(b)) * step;

const std::uint_fast8_t k_max = UINT8_C(32);
constexpr std::uint_fast8_t k_max { UINT8_C(32) };

for(std::uint_fast8_t k = UINT8_C(0); k < k_max; ++k)
{
Expand Down Expand Up @@ -80,12 +80,29 @@ auto is_close_fraction
using floating_point_type = FloatingPointType;

using std::fabs;
using std::fpclassify;

const floating_point_type ratio = fabs(floating_point_type((floating_point_type(1) * a) / b));
const int fpc_a { fpclassify(a) };
const int fpc_b { fpclassify(b) };

const floating_point_type closeness = fabs(floating_point_type(1 - ratio));
bool result_is_ok { };

return (closeness < tol);
if(fpc_b == FP_ZERO)
{
const floating_point_type closeness { (fpc_a == FP_ZERO) ? floating_point_type { 0 } : fabs(a - b) };

result_is_ok = (closeness < tol);
}
else
{
const floating_point_type ratio = fabs(floating_point_type((floating_point_type(1) * a) / b));

const floating_point_type closeness = fabs(floating_point_type(1 - ratio));

result_is_ok = (closeness < tol);
}

return result_is_ok;
}

// N[Pi, 51]
Expand All @@ -108,7 +125,7 @@ auto cyl_bessel_j(const std::uint_fast8_t n, const FloatingPointType& x) noexcep
using std::sin;
using std::sqrt;

const auto tol = sqrt(epsilon);
const floating_point_type tol { sqrt(epsilon) };

const auto integration_result =
detail::integral
Expand All @@ -121,7 +138,7 @@ auto cyl_bessel_j(const std::uint_fast8_t n, const FloatingPointType& x) noexcep
return cos(x * sin(t) - (t * static_cast<floating_point_type>(n)));
});

const auto jn = static_cast<floating_point_type>(integration_result / detail::pi_v<floating_point_type>);
const floating_point_type jn { static_cast<floating_point_type>(integration_result / detail::pi_v<floating_point_type>) };

return jn;
}
Expand All @@ -130,9 +147,9 @@ auto cyl_bessel_j(const std::uint_fast8_t n, const FloatingPointType& x) noexcep

auto main() -> int
{
using my_float_type = long double;
using my_float_type = std::float_t;

static_assert((std::numeric_limits<my_float_type>::digits >= 24), "Error: Incorrect my_float_type type definition");
static_assert((std::numeric_limits<my_float_type>::digits == 24), "Error: Incorrect my_float_type type definition");

constexpr my_float_type my_tol =
static_cast<my_float_type>
Expand Down
16 changes: 15 additions & 1 deletion include/cmath
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
#endif

#else
#if !defined(FP_NAN)
#define FP_NAN 0
#endif
#if !defined(FP_INFINITE)
#define FP_INFINITE 1
#endif
#if !defined(FP_ZERO)
#define FP_ZERO 2
#endif
#if !defined(FP_SUBNORMAL)
#define FP_SUBNORMAL 3
#endif
#if !defined(FP_NORMAL)
#define FP_NORMAL 4
#endif

template<typename _Tp>
inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value,
Expand Down