Fix gamma.h on i386 (#1136)

Add tests for gamma decode
This commit is contained in:
rolandreichweinmusic 2025-06-25 19:09:37 +02:00 committed by GitHub
parent 185557db59
commit 0f408a43ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 2 deletions

View File

@ -63,7 +63,10 @@ namespace etl
//*********************************
TInput operator ()(TInput value) const
{
return TInput(TInput(maximum * pow(double(value) / maximum, one_over_gamma)));
// Calculate intermediate result because rounding + optimization
// lead to wrong values when returning directly (test on i386)
const double result = maximum * pow(double(value) / maximum, one_over_gamma);
return TInput(result);
}
private:
@ -95,7 +98,10 @@ namespace etl
//*********************************
TInput operator ()(TInput value) const
{
return TInput(TInput(maximum * pow(double(value) / maximum, gamma)));
// Calculate intermediate result because rounding + optimization
// lead to wrong values when returning directly (test on i386)
const double result = maximum * pow(double(value) / maximum, gamma);
return TInput(result);
}
private:

View File

@ -41,6 +41,7 @@ namespace
using IntGammaEncode = etl::gamma_encode<int>;
using DoubleGammaEncode = etl::gamma_encode<double>;
using IntGammaDecode = etl::gamma_decode<int>;
using DoubleGammaDecode = etl::gamma_decode<double>;
struct Compare
@ -62,6 +63,16 @@ namespace
0, 0, 0, 1, 1, 2, 4, 5, 7, 9
};
const std::array<int, Size> input1b =
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
};
const std::array<int, Size> result1b =
{
0, 3, 4, 5, 6, 6, 7, 7, 8, 9
};
std::array<int, Size> output1;
//***********************************
@ -100,6 +111,17 @@ namespace
CHECK(isEqual);
}
//*************************************************************************
TEST(test_int_gamma_decode)
{
IntGammaDecode gamma(0.5, 9);
std::transform(input1b.begin(), input1b.end(), output1.begin(), gamma);
bool isEqual = std::equal(output1.begin(), output1.end(), result1b.begin());
CHECK(isEqual);
}
//*************************************************************************
TEST(test_double_gamma_encode)
{