Skip to content

Commit

Permalink
Fixed floating point support for etl::unaligned_type
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wellbelove committed Aug 9, 2024
1 parent 344f1b2 commit af03b44
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 105 deletions.
50 changes: 0 additions & 50 deletions include/etl/unaligned_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,56 +291,6 @@ namespace etl
return *this;
}

//*************************************************************************
/// Equality operator
//*************************************************************************
friend ETL_CONSTEXPR14 bool operator ==(const unaligned_type& lhs, const unaligned_type& rhs)
{
return etl::equal(lhs.data(), lhs.data() + lhs.Size, rhs.data());
}

//*************************************************************************
/// Equality operator
//*************************************************************************
friend ETL_CONSTEXPR14 bool operator ==(const unaligned_type& lhs, T rhs)
{
T lhs_value = lhs;
return (lhs_value == rhs);
}

//*************************************************************************
/// Equality operator
//*************************************************************************
friend ETL_CONSTEXPR14 bool operator ==(T lhs, const unaligned_type& rhs)
{
T rhs_value = rhs;
return (lhs == rhs_value);
}

//*************************************************************************
/// Inequality operator
//*************************************************************************
friend ETL_CONSTEXPR14 bool operator !=(const unaligned_type& lhs, T rhs)
{
return !(lhs == rhs);
}

//*************************************************************************
/// Inequality operator
//*************************************************************************
friend ETL_CONSTEXPR14 bool operator !=(const unaligned_type& lhs, const unaligned_type& rhs)
{
return !(lhs == rhs);
}

//*************************************************************************
/// Inequality operator
//*************************************************************************
friend ETL_CONSTEXPR14 bool operator !=(T lhs, const unaligned_type& rhs)
{
return !(lhs == rhs);
}

//*************************************************************************
/// Conversion operator
//*************************************************************************
Expand Down
110 changes: 55 additions & 55 deletions test/test_unaligned_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,19 +329,19 @@ namespace
}

// float
CHECK(etl::le_float_t(3.1415927f) == etl::le_float_t(3.1415927f));
CHECK(3.1415927f == etl::le_float_t(3.1415927f));
CHECK(etl::le_float_t(3.1415927f) == 3.1415927f);
CHECK_FLOAT_SAME(etl::le_float_t(3.1415927f), etl::le_float_t(3.1415927f));
CHECK_FLOAT_SAME(3.1415927f, etl::le_float_t(3.1415927f));
CHECK_FLOAT_SAME(etl::le_float_t(3.1415927f), 3.1415927f);

// double
CHECK(etl::le_double_t(3.1415927) == etl::le_double_t(3.1415927));
CHECK(3.1415927 == etl::le_double_t(3.1415927));
CHECK(etl::le_double_t(3.1415927) == 3.1415927);
CHECK_FLOAT_SAME(etl::le_double_t(3.1415927), etl::le_double_t(3.1415927));
CHECK_FLOAT_SAME(3.1415927, etl::le_double_t(3.1415927));
CHECK_FLOAT_SAME(etl::le_double_t(3.1415927), 3.1415927);

// long double
CHECK(etl::le_long_double_t(3.1415927L) == etl::le_long_double_t(3.1415927L));
CHECK(3.1415927L == etl::le_long_double_t(3.1415927L));
CHECK(etl::le_long_double_t(3.1415927L) == 3.1415927L);
CHECK_FLOAT_SAME(etl::le_long_double_t(3.1415927L), etl::le_long_double_t(3.1415927L));
CHECK_FLOAT_SAME(3.1415927L, etl::le_long_double_t(3.1415927L));
CHECK_FLOAT_SAME(etl::le_long_double_t(3.1415927L), 3.1415927L);
}

//*************************************************************************
Expand Down Expand Up @@ -394,7 +394,7 @@ namespace
{
// long long
CHECK(etl::le_long_long_t(0x0123456789ABCDEF) != etl::le_long_long_t(0x0223456789ABCDEF));
CHECK((long long)(0x0123456789ABCDEF) != etl::le_long_long_t(0x0223456789ABCDEF));
CHECK((long long)(0x0123456789ABCDEF) != etl::le_long_long_t(0x0223456789ABCDEF));
CHECK(etl::le_long_long_t(0x0123456789ABCDEF) != (long long)(0x0223456789ABCDEF));

CHECK(etl::le_ulong_long_t(0x0123456789ABCDEFU) != etl::le_ulong_long_t(0x0223456789ABCDEFU));
Expand All @@ -403,19 +403,19 @@ namespace
}

// float
CHECK(etl::le_float_t(3.1415927f) != etl::le_float_t(2.7182818f));
CHECK(3.1415927f != etl::le_float_t(2.7182818f));
CHECK(etl::le_float_t(3.1415927f) != 2.7182818f);
CHECK_FLOAT_DIFFERENT(etl::le_float_t(3.1415927f), etl::le_float_t(2.7182818f));
CHECK_FLOAT_DIFFERENT(3.1415927f, etl::le_float_t(2.7182818f));
CHECK_FLOAT_DIFFERENT(etl::le_float_t(3.1415927f), 2.7182818f);

// double
CHECK(etl::le_double_t(3.1415927) != etl::le_double_t(2.7182818));
CHECK(3.1415927 != etl::le_double_t(2.7182818));
CHECK(etl::le_double_t(3.1415927) != 2.7182818);
CHECK_FLOAT_DIFFERENT(etl::le_double_t(3.1415927), etl::le_double_t(2.7182818));
CHECK_FLOAT_DIFFERENT(3.1415927, etl::le_double_t(2.7182818));
CHECK_FLOAT_DIFFERENT(etl::le_double_t(3.1415927), 2.7182818);

// long double
CHECK(etl::le_long_double_t(3.1415927L) != etl::le_long_double_t(2.7182818L));
CHECK(3.1415927L != etl::le_long_double_t(2.7182818L));
CHECK(etl::le_long_double_t(3.1415927L) != 2.7182818L);
CHECK_FLOAT_DIFFERENT(etl::le_long_double_t(3.1415927L), etl::le_long_double_t(2.7182818L));
CHECK_FLOAT_DIFFERENT(3.1415927L, etl::le_long_double_t(2.7182818L));
CHECK_FLOAT_DIFFERENT(etl::le_long_double_t(3.1415927L), 2.7182818L);
}

//*************************************************************************
Expand Down Expand Up @@ -477,19 +477,19 @@ namespace
}

// float
CHECK(etl::be_float_t(3.1415927f) == etl::be_float_t(3.1415927f));
CHECK(3.1415927f == etl::be_float_t(3.1415927f));
CHECK(etl::be_float_t(3.1415927f) == 3.1415927f);
CHECK_FLOAT_SAME(etl::be_float_t(3.1415927f), etl::be_float_t(3.1415927f));
CHECK_FLOAT_SAME(3.1415927f, etl::be_float_t(3.1415927f));
CHECK_FLOAT_SAME(etl::be_float_t(3.1415927f), 3.1415927f);

// double
CHECK(etl::be_double_t(3.1415927) == etl::be_double_t(3.1415927));
CHECK(3.1415927 == etl::be_double_t(3.1415927));
CHECK(etl::be_double_t(3.1415927) == 3.1415927);
CHECK_FLOAT_SAME(etl::be_double_t(3.1415927), etl::be_double_t(3.1415927));
CHECK_FLOAT_SAME(3.1415927, etl::be_double_t(3.1415927));
CHECK_FLOAT_SAME(etl::be_double_t(3.1415927), 3.1415927);

// long double
CHECK(etl::be_long_double_t(3.1415927L) == etl::be_long_double_t(3.1415927L));
CHECK(3.1415927L == etl::be_long_double_t(3.1415927L));
CHECK(etl::be_long_double_t(3.1415927L) == 3.1415927L);
CHECK_FLOAT_SAME(etl::be_long_double_t(3.1415927L), etl::be_long_double_t(3.1415927L));
CHECK_FLOAT_SAME(3.1415927L, etl::be_long_double_t(3.1415927L));
CHECK_FLOAT_SAME(etl::be_long_double_t(3.1415927L), 3.1415927L);
}

//*************************************************************************
Expand Down Expand Up @@ -551,19 +551,19 @@ namespace
}

// float
CHECK(etl::be_float_t(3.1415927f) != etl::be_float_t(2.7182818f));
CHECK(3.1415927f != etl::be_float_t(2.7182818f));
CHECK(etl::be_float_t(3.1415927f) != 2.7182818f);
CHECK_FLOAT_DIFFERENT(etl::be_float_t(3.1415927f), etl::be_float_t(2.7182818f));
CHECK_FLOAT_DIFFERENT(3.1415927f, etl::be_float_t(2.7182818f));
CHECK_FLOAT_DIFFERENT(etl::be_float_t(3.1415927f), 2.7182818f);

// double
CHECK(etl::be_double_t(3.1415927) != etl::be_double_t(2.7182818));
CHECK(3.1415927 != etl::be_double_t(2.7182818));
CHECK(etl::be_double_t(3.1415927) != 2.7182818);
CHECK_FLOAT_DIFFERENT(etl::be_double_t(3.1415927), etl::be_double_t(2.7182818));
CHECK_FLOAT_DIFFERENT(3.1415927, etl::be_double_t(2.7182818));
CHECK_FLOAT_DIFFERENT(etl::be_double_t(3.1415927), 2.7182818);

// long double
CHECK(etl::be_long_double_t(3.1415927L) != etl::be_long_double_t(2.7182818L));
CHECK(3.1415927L != etl::be_long_double_t(2.7182818L));
CHECK(etl::be_long_double_t(3.1415927L) != 2.7182818L);
CHECK_FLOAT_DIFFERENT(etl::be_long_double_t(3.1415927L), etl::be_long_double_t(2.7182818L));
CHECK_FLOAT_DIFFERENT(3.1415927L, etl::be_long_double_t(2.7182818L));
CHECK_FLOAT_DIFFERENT(etl::be_long_double_t(3.1415927L), 2.7182818L);
}

//*************************************************************************
Expand Down Expand Up @@ -622,17 +622,17 @@ namespace
// float
etl::le_float_t le_float;
le_float = 3.1415927f;
CHECK(3.1415927f == le_float);
CHECK_FLOAT_SAME(3.1415927f, le_float);

// double
etl::le_double_t le_double;
le_double = 3.1415927;
CHECK(3.1415927 == le_double);
CHECK_FLOAT_SAME(3.1415927, le_double);

// long double
etl::le_long_double_t le_long_double;
le_long_double = 3.1415927L;
CHECK(3.1415927L == le_long_double);
CHECK_FLOAT_SAME(3.1415927L, le_long_double);
}

//*************************************************************************
Expand Down Expand Up @@ -691,17 +691,17 @@ namespace
// float
etl::be_float_t be_float;
be_float = 3.1415927f;
CHECK(3.1415927f == be_float);
CHECK_FLOAT_SAME(3.1415927f, be_float);

// double
etl::be_double_t be_double;
be_double = 3.1415927;
CHECK(3.1415927 == be_double);
CHECK_FLOAT_SAME(3.1415927, be_double);

// long double
etl::be_long_double_t be_long_double;
be_long_double = 3.1415927L;
CHECK(3.1415927L == be_long_double);
CHECK_FLOAT_SAME(3.1415927L, be_long_double);
}

//*************************************************************************
Expand Down Expand Up @@ -740,10 +740,10 @@ namespace
le_v3 = be_v1; // Assign le from be.
be_v3 = le_v1; // Assign be from le.

CHECK_EQUAL(3.1415927f, le_v2);
CHECK_EQUAL(3.1415927f, be_v2);
CHECK_EQUAL(3.1415927f, le_v3);
CHECK_EQUAL(3.1415927f, be_v3);
CHECK_FLOAT_SAME(3.1415927f, le_v2);
CHECK_FLOAT_SAME(3.1415927f, be_v2);
CHECK_FLOAT_SAME(3.1415927f, le_v3);
CHECK_FLOAT_SAME(3.1415927f, be_v3);
}

//*************************************************************************
Expand All @@ -761,10 +761,10 @@ namespace
le_v3 = be_v1; // Assign le from be.
be_v3 = le_v1; // Assign be from le.

CHECK_EQUAL(3.1415927, le_v2);
CHECK_EQUAL(3.1415927, be_v2);
CHECK_EQUAL(3.1415927, le_v3);
CHECK_EQUAL(3.1415927, be_v3);
CHECK_FLOAT_SAME(3.1415927, le_v2);
CHECK_FLOAT_SAME(3.1415927, be_v2);
CHECK_FLOAT_SAME(3.1415927, le_v3);
CHECK_FLOAT_SAME(3.1415927, be_v3);
}

//*************************************************************************
Expand All @@ -782,10 +782,10 @@ namespace
le_v3 = be_v1; // Assign le from be.
be_v3 = le_v1; // Assign be from le.

CHECK_EQUAL(3.1415927L, le_v2);
CHECK_EQUAL(3.1415927L, be_v2);
CHECK_EQUAL(3.1415927L, le_v3);
CHECK_EQUAL(3.1415927L, be_v3);
CHECK_FLOAT_SAME(3.1415927L, le_v2);
CHECK_FLOAT_SAME(3.1415927L, be_v2);
CHECK_FLOAT_SAME(3.1415927L, le_v3);
CHECK_FLOAT_SAME(3.1415927L, be_v3);
}

//*************************************************************************
Expand Down

0 comments on commit af03b44

Please sign in to comment.