mirror of https://github.com/ecmwf/eccodes.git
Fix index in IbmTable
This commit is contained in:
parent
aee89904a8
commit
00cc6dd250
|
@ -48,21 +48,23 @@ The vmin and vmax boundaries are defined as:
|
||||||
struct IbmTable {
|
struct IbmTable {
|
||||||
private:
|
private:
|
||||||
using ValueType = double;
|
using ValueType = double;
|
||||||
static constexpr uint8_t TABLESIZE = 128;
|
static constexpr int TABLESIZE = 128;
|
||||||
static constexpr uint32_t mantissa_min = 0x100000;
|
static constexpr uint32_t mantissa_min = 0x100000;
|
||||||
static constexpr uint32_t mantissa_max = 0xffffff;
|
static constexpr uint32_t mantissa_max = 0xffffff;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr std::array<ValueType, TABLESIZE> e = []() {
|
static constexpr std::array<ValueType, TABLESIZE> e = []() {
|
||||||
std::array<ValueType, TABLESIZE> multiplier{};
|
std::array<ValueType, TABLESIZE> multiplier{};
|
||||||
for (uint8_t i = 1; i < TABLESIZE; ++i) {
|
multiplier[0] = 0;
|
||||||
|
for (int i = 0; i < TABLESIZE; ++i) {
|
||||||
multiplier[i] = codes_power<ValueType>(i - 70, 16);
|
multiplier[i] = codes_power<ValueType>(i - 70, 16);
|
||||||
}
|
}
|
||||||
return multiplier;
|
return multiplier;
|
||||||
}();
|
}();
|
||||||
static constexpr std::array<ValueType, TABLESIZE> v = []() {
|
static constexpr std::array<ValueType, TABLESIZE> v = []() {
|
||||||
std::array<ValueType, TABLESIZE> values{};
|
std::array<ValueType, TABLESIZE> values{};
|
||||||
for (uint8_t i = 0; i < TABLESIZE; ++i) {
|
values[0] = 0;
|
||||||
|
for (int i = 0; i < TABLESIZE; ++i) {
|
||||||
values[i] = e[i] * mantissa_min;
|
values[i] = e[i] * mantissa_min;
|
||||||
}
|
}
|
||||||
return values;
|
return values;
|
||||||
|
|
|
@ -35,6 +35,7 @@ The table layout is as follows:
|
||||||
+-------+----------------+------------------------+
|
+-------+----------------+------------------------+
|
||||||
| idx (i) | multiplier (e) | value (v = mmin * e) |
|
| idx (i) | multiplier (e) | value (v = mmin * e) |
|
||||||
+-------+----------------+------------------------+
|
+-------+----------------+------------------------+
|
||||||
|
| 0 | 0 | 0 |
|
||||||
| 1 | 2^(-149) | 0x800000 * 2^(-149) |
|
| 1 | 2^(-149) | 0x800000 * 2^(-149) |
|
||||||
| 2 | 2^(-148) | 0x800000 * 2^(-148) |
|
| 2 | 2^(-148) | 0x800000 * 2^(-148) |
|
||||||
| ... | ... | ... |
|
| ... | ... | ... |
|
||||||
|
@ -52,21 +53,23 @@ template <typename ValueType>
|
||||||
struct IeeeTable {
|
struct IeeeTable {
|
||||||
private:
|
private:
|
||||||
static_assert(std::is_floating_point<ValueType>::value, "ValueType must be a floating point type");
|
static_assert(std::is_floating_point<ValueType>::value, "ValueType must be a floating point type");
|
||||||
static constexpr uint8_t TABLESIZE = 255;
|
static constexpr int TABLESIZE = 255;
|
||||||
static constexpr uint32_t mantissa_min = 0x800000;
|
static constexpr uint32_t mantissa_min = 0x800000;
|
||||||
static constexpr uint32_t mantissa_max = 0xffffff;
|
static constexpr uint32_t mantissa_max = 0xffffff;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr std::array<ValueType, TABLESIZE> e = []() {
|
static constexpr std::array<ValueType, TABLESIZE> e = []() {
|
||||||
std::array<ValueType, TABLESIZE> multiplier{};
|
std::array<ValueType, TABLESIZE> multiplier{};
|
||||||
for (uint8_t i = 1; i < TABLESIZE; ++i) {
|
multiplier[0] = 0;
|
||||||
|
for (int i = 1; i < TABLESIZE; ++i) {
|
||||||
multiplier[i] = codes_power<ValueType>(i - 150, 2);
|
multiplier[i] = codes_power<ValueType>(i - 150, 2);
|
||||||
}
|
}
|
||||||
return multiplier;
|
return multiplier;
|
||||||
}();
|
}();
|
||||||
static constexpr std::array<ValueType, TABLESIZE> v = []() {
|
static constexpr std::array<ValueType, TABLESIZE> v = []() {
|
||||||
std::array<ValueType, TABLESIZE> values{};
|
std::array<ValueType, TABLESIZE> values{};
|
||||||
for (uint8_t i = 1; i < TABLESIZE; ++i) {
|
values[0] = 0;
|
||||||
|
for (int i = 1; i < TABLESIZE; ++i) {
|
||||||
values[i] = e[i] * mantissa_min;
|
values[i] = e[i] * mantissa_min;
|
||||||
}
|
}
|
||||||
return values;
|
return values;
|
||||||
|
|
Loading…
Reference in New Issue