mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
parent
185557db59
commit
0f408a43ba
@ -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:
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user