ECC-1701: Compile-time initialisation of IBM/IEEE float tables

This commit is contained in:
Shahram Najm 2023-10-12 11:38:40 +01:00
parent 9250c83cb6
commit aee89904a8
3 changed files with 18 additions and 30 deletions

View File

@ -10,19 +10,17 @@
#pragma once
#include "grib_api_internal.h"
#include "grib_scaling.h"
#include <array>
#include <type_traits>
#include <cstdint>
/**
.. _init_ieee_table:
Init IBM Floats Table
===============
=====================
Initializes the ibm_table with IBM Float values. Nearest smaller values (e.g., reference values for grid_simple) are taken from this table.
@ -31,15 +29,15 @@ Details
The table layout is as follows:
+-------+----------------+----------------------+
+-------+----------------+------------------------+
| idx (i) | multiplier (e) | value (v = mmin * e) |
+-------+----------------+----------------------+
| 0 | 16^(-70) | 0x100000 * 2^(-70) |
| 1 | 16^(-69) | 0x100000 * 2^(-69) |
| ... | ... | ... |
| 126 | 16^56 | 0x100000 * 2^56 |
| 127 | 16^57 | 0x100000 * 2^57 |
+-------+----------------+----------------------+
+-------+----------------+------------------------+
| 0 | 16^(-70) | 0x100000 * 2^(-70) |
| 1 | 16^(-69) | 0x100000 * 2^(-69) |
| ... | ... | ... |
| 126 | 16^56 | 0x100000 * 2^56 |
| 127 | 16^57 | 0x100000 * 2^57 |
+-------+----------------+------------------------+
The vmin and vmax boundaries are defined as:

View File

@ -8,9 +8,6 @@
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
/***************************************************************************
* Enrico Fucile - 06.01.2009 *
***************************************************************************/
#include "grib_ieeefloat.h"
/* See old implementation in src/deprecated/grib_ieeefloat.c */
@ -100,8 +97,6 @@ double grib_ieeefloat_error(double x)
{
unsigned long e = 0;
//init_table_if_needed();
if (x < 0)
x = -x;
@ -135,7 +130,6 @@ double grib_long_to_ieee(unsigned long x)
Assert(0);
}
#endif
//init_table_if_needed();
if (c == 0 && m == 0)
return 0;
@ -167,8 +161,6 @@ unsigned long grib_ieee_nearest_smaller_to_long(double x)
if (x == 0)
return 0;
//init_table_if_needed();
l = grib_ieee_to_long(x);
y = grib_long_to_ieee(l);
@ -213,10 +205,8 @@ int grib_nearest_smaller_ieee_float(double a, double* ret)
{
unsigned long l = 0;
//init_table_if_needed();
if (a > ieee_table.vmax) {
grib_context* c = grib_context_get_default();
const grib_context* c = grib_context_get_default();
grib_context_log(c, GRIB_LOG_ERROR,
"Number is too large: x=%e > xmax=%e (IEEE float)", a, ieee_table.vmax);
return GRIB_INTERNAL_ERROR;

View File

@ -32,15 +32,15 @@ Details
The table layout is as follows:
+-------+----------------+----------------------+
+-------+----------------+------------------------+
| idx (i) | multiplier (e) | value (v = mmin * e) |
+-------+----------------+----------------------+
| 1 | 2^(-149) | 0x800000 * 2^(-149) |
| 2 | 2^(-148) | 0x800000 * 2^(-148) |
| ... | ... | ... |
| 253 | 2^103 | 0x800000 * 2^103 |
| 254 | 2^104 | 0x800000 * 2^104 |
+-------+----------------+----------------------+
+-------+----------------+------------------------+
| 1 | 2^(-149) | 0x800000 * 2^(-149) |
| 2 | 2^(-148) | 0x800000 * 2^(-148) |
| ... | ... | ... |
| 253 | 2^103 | 0x800000 * 2^103 |
| 254 | 2^104 | 0x800000 * 2^104 |
+-------+----------------+------------------------+
The vmin and vmax boundaries are defined as: