Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libstdc++] Update avr libstdc++ submodule to C++20 version #535

Merged
merged 7 commits into from
Jan 10, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions src/modm/platform/i2c/at90_tiny_mega/i2c_master.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public:

// calculate the fractional prescaler value
constexpr float pre_part_raw = float(SystemClock::I2c) / ( 2 * baudrate );
constexpr float pre_raw = std::floorf(pre_part_raw) < 8 ? 0 : (pre_part_raw - 8) / pre;
constexpr float pre_raw = std::floor(pre_part_raw) < 8 ? 0 : (pre_part_raw - 8) / pre;
// respect the prescaler range of 0 to 255
constexpr uint32_t pre_ceil = std::min(uint32_t(std::ceilf(pre_raw)), 255ul);
constexpr uint32_t pre_floor = std::floorf(pre_raw);
constexpr uint32_t pre_ceil = std::min(uint32_t(std::ceil(pre_raw)), 255ul);
constexpr uint32_t pre_floor = std::floor(pre_raw);

// calculate the possible baudrates above and below the requested baudrate
constexpr uint32_t baud_lower = SystemClock::I2c / ( 16 + 2 * pre_ceil * pre );
Expand Down
2 changes: 1 addition & 1 deletion src/modm/ui/animation/interpolation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class FastRamp
float delta = (static_cast<float>(end) - begin);
deltaValue = delta / steps;
if (deltaValue == 0)
deltaValue = std::copysignf(std::numeric_limits<float>::epsilon(), delta);
deltaValue = std::copysign(std::numeric_limits<float>::epsilon(), delta);
accumulatedValue = static_cast<float>(begin) + deltaValue / 2;
}

Expand Down
2 changes: 1 addition & 1 deletion test/config/mega-2560-pro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<modules>
<module>modm-test:test:architecture</module>
<module>modm-test:test:communication:sab</module>
<!-- <module>modm-test:test:communication:sab</module> -->


<!-- <module>modm-test:test:communication:xpcc</module> -->
Expand Down
118 changes: 118 additions & 0 deletions test/stdc++/math/math_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright (c) 2021, Christopher Durand
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include "math_test.hpp"
#include <cmath>

// non-const value to enforce use of avr-libm runtime implementations
float one = 1.0f;

void
MathTest::testMathFunctions()
{
// cos
TEST_ASSERT_EQUALS_FLOAT(std::cos(one * M_PI), -1);
// sin
TEST_ASSERT_EQUALS_FLOAT(std::sin(one * M_PI/2), 1);
// tan
TEST_ASSERT_EQUALS_FLOAT(std::tan(one * M_PI/4), 1);

// fabs
TEST_ASSERT_EQUALS_FLOAT(std::fabs(one / 2), 0.5);

// fmod
TEST_ASSERT_EQUALS_FLOAT(std::fmod(one * 5, 2), 1);

// modf
float integralPart = 0;
float fractionalPart = std::modf(one * 1.5, &integralPart);
TEST_ASSERT_EQUALS_FLOAT(integralPart, 1);
TEST_ASSERT_EQUALS_FLOAT(fractionalPart, 0.5);

// cbrt
TEST_ASSERT_EQUALS_FLOAT(std::cbrt(one * 27), 3);

// hypot, sqrt
TEST_ASSERT_EQUALS_FLOAT(std::hypot(one * 2, one * 3), std::sqrt(one * 13));

// floor
TEST_ASSERT_EQUALS_FLOAT(std::floor(one * 3.2), 3.0);
// ceil
TEST_ASSERT_EQUALS_FLOAT(std::ceil(one * 3.2), 4.0);

// frexp
// 96 = 0.75 * 2^7
int power = 0;
TEST_ASSERT_EQUALS_FLOAT(std::frexp(one * 96, &power), 0.75);
TEST_ASSERT_EQUALS(power, 7);
// ldexp
TEST_ASSERT_EQUALS_FLOAT(std::ldexp(one * 3, 5), 96);
// exp
TEST_ASSERT_EQUALS_FLOAT(std::exp(one), M_E);

constexpr float sinh1 = (std::exp(1.0)-std::exp(-1.0))/2;
constexpr float cosh1 = (std::exp(1.0)+std::exp(-1.0))/2;
// cosh
TEST_ASSERT_EQUALS_FLOAT(std::cosh(one), cosh1);
// sinh
TEST_ASSERT_EQUALS_FLOAT(std::sinh(one), sinh1);
// tanh
TEST_ASSERT_EQUALS_FLOAT(std::tanh(one), sinh1 / cosh1);

// acos
TEST_ASSERT_EQUALS_FLOAT(std::acos(-one), M_PI);
// asin
TEST_ASSERT_EQUALS_FLOAT(std::asin(one), M_PI/2);
// atan
TEST_ASSERT_EQUALS_FLOAT(std::atan(one), M_PI/4);
// atan2
TEST_ASSERT_EQUALS_FLOAT(std::atan2(one, 1), M_PI/4);

// log
TEST_ASSERT_EQUALS_FLOAT(std::log(std::exp(one * 3)), 3.0);
// log10
TEST_ASSERT_EQUALS_FLOAT(std::log10(100 * one), 2);

// powf
TEST_ASSERT_EQUALS_FLOAT(std::pow(2 * one, 3), 8);

// isnan
TEST_ASSERT_TRUE(std::isnan(NAN*one));
// isinf
TEST_ASSERT_FALSE(std::isinf(one));
// isfinite
TEST_ASSERT_TRUE(std::isfinite(one));

// copysign
TEST_ASSERT_TRUE(std::copysign(1.0f,-2*one) < 0);
// signbit
TEST_ASSERT_TRUE(std::signbit(-2*one));

// fdim
TEST_ASSERT_EQUALS_FLOAT(std::fdim(one * 5, one * 2), 3);

// fma
TEST_ASSERT_EQUALS_FLOAT(std::fma(one * 2, one * 2, one), 5);

// fmax
TEST_ASSERT_EQUALS_FLOAT(std::fmax(one * 5, one * 2), 5);
// fmin
TEST_ASSERT_EQUALS_FLOAT(std::fmin(one * 5, one * 2), 2);

// trunc
TEST_ASSERT_EQUALS_FLOAT(std::trunc(one * 2.7), 2);
// round
TEST_ASSERT_EQUALS_FLOAT(std::round(one * 2.7), 3);
// lround
TEST_ASSERT_EQUALS(std::lround(one * 2.7), 3);
// lrint
TEST_ASSERT_EQUALS(std::lrint(one * 1.8), 2);
}
20 changes: 20 additions & 0 deletions test/stdc++/math/math_test.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2021, Christopher Durand
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include <unittest/testsuite.hpp>

/// @ingroup modm_test_test_stdc++
class MathTest : public unittest::TestSuite
{
public:
void
testMathFunctions();
};
6 changes: 5 additions & 1 deletion test/stdc++/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ def init(module):

def prepare(module, options):
module.depends(":stdc++")
target = options[":target"]
if target.identifier.platform != "avr":
return False

return True


def build(env):
env.outbasepath = "modm/test/stdc++"
env.outbasepath = "modm-test/src/stdc++"
env.copy('.')
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
*/
// ----------------------------------------------------------------------------

#include "vector_test.hpp"
#include "std_vector_test.hpp"
#include <vector>
#include <iterator>
#include <algorithm>

void
VectorTest::testInsertion()
StdVectorTest::testInsertion()
{
std::vector<int> vec;

Expand All @@ -32,7 +32,7 @@ VectorTest::testInsertion()
}

void
VectorTest::testIteration()
StdVectorTest::testIteration()
{
uint8_t data[] = {1,2,5,6,100};
std::vector<int> vec{1,2,5,6,100};
Expand All @@ -47,7 +47,7 @@ VectorTest::testIteration()
}

void
VectorTest::testEmplace()
StdVectorTest::testEmplace()
{
struct NonCopyable
{
Expand All @@ -72,7 +72,7 @@ VectorTest::testEmplace()
}

void
VectorTest::testRemove()
StdVectorTest::testRemove()
{
std::vector<int> vec{2,3,4,5,6,7};
auto it = vec.begin() + 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <unittest/testsuite.hpp>

/// @ingroup modm_test_test_stdc++
class VectorTest : public unittest::TestSuite
class StdVectorTest : public unittest::TestSuite
{
public:
void
Expand Down