mirror of https://github.com/ecmwf/eccodes.git
ECC-1701: Compile-time initialisation of IBM/IEEE float tables
This commit is contained in:
parent
9250c83cb6
commit
aee89904a8
|
@ -10,19 +10,17 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "grib_api_internal.h"
|
|
||||||
#include "grib_scaling.h"
|
#include "grib_scaling.h"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
.. _init_ieee_table:
|
.. _init_ieee_table:
|
||||||
|
|
||||||
Init IBM Floats 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.
|
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:
|
The table layout is as follows:
|
||||||
|
|
||||||
+-------+----------------+----------------------+
|
+-------+----------------+------------------------+
|
||||||
| idx (i) | multiplier (e) | value (v = mmin * e) |
|
| idx (i) | multiplier (e) | value (v = mmin * e) |
|
||||||
+-------+----------------+----------------------+
|
+-------+----------------+------------------------+
|
||||||
| 0 | 16^(-70) | 0x100000 * 2^(-70) |
|
| 0 | 16^(-70) | 0x100000 * 2^(-70) |
|
||||||
| 1 | 16^(-69) | 0x100000 * 2^(-69) |
|
| 1 | 16^(-69) | 0x100000 * 2^(-69) |
|
||||||
| ... | ... | ... |
|
| ... | ... | ... |
|
||||||
| 126 | 16^56 | 0x100000 * 2^56 |
|
| 126 | 16^56 | 0x100000 * 2^56 |
|
||||||
| 127 | 16^57 | 0x100000 * 2^57 |
|
| 127 | 16^57 | 0x100000 * 2^57 |
|
||||||
+-------+----------------+----------------------+
|
+-------+----------------+------------------------+
|
||||||
|
|
||||||
The vmin and vmax boundaries are defined as:
|
The vmin and vmax boundaries are defined as:
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,6 @@
|
||||||
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/***************************************************************************
|
|
||||||
* Enrico Fucile - 06.01.2009 *
|
|
||||||
***************************************************************************/
|
|
||||||
#include "grib_ieeefloat.h"
|
#include "grib_ieeefloat.h"
|
||||||
|
|
||||||
/* See old implementation in src/deprecated/grib_ieeefloat.c */
|
/* See old implementation in src/deprecated/grib_ieeefloat.c */
|
||||||
|
@ -100,8 +97,6 @@ double grib_ieeefloat_error(double x)
|
||||||
{
|
{
|
||||||
unsigned long e = 0;
|
unsigned long e = 0;
|
||||||
|
|
||||||
//init_table_if_needed();
|
|
||||||
|
|
||||||
if (x < 0)
|
if (x < 0)
|
||||||
x = -x;
|
x = -x;
|
||||||
|
|
||||||
|
@ -135,7 +130,6 @@ double grib_long_to_ieee(unsigned long x)
|
||||||
Assert(0);
|
Assert(0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
//init_table_if_needed();
|
|
||||||
|
|
||||||
if (c == 0 && m == 0)
|
if (c == 0 && m == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -167,8 +161,6 @@ unsigned long grib_ieee_nearest_smaller_to_long(double x)
|
||||||
if (x == 0)
|
if (x == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
//init_table_if_needed();
|
|
||||||
|
|
||||||
l = grib_ieee_to_long(x);
|
l = grib_ieee_to_long(x);
|
||||||
y = grib_long_to_ieee(l);
|
y = grib_long_to_ieee(l);
|
||||||
|
|
||||||
|
@ -213,10 +205,8 @@ int grib_nearest_smaller_ieee_float(double a, double* ret)
|
||||||
{
|
{
|
||||||
unsigned long l = 0;
|
unsigned long l = 0;
|
||||||
|
|
||||||
//init_table_if_needed();
|
|
||||||
|
|
||||||
if (a > ieee_table.vmax) {
|
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,
|
grib_context_log(c, GRIB_LOG_ERROR,
|
||||||
"Number is too large: x=%e > xmax=%e (IEEE float)", a, ieee_table.vmax);
|
"Number is too large: x=%e > xmax=%e (IEEE float)", a, ieee_table.vmax);
|
||||||
return GRIB_INTERNAL_ERROR;
|
return GRIB_INTERNAL_ERROR;
|
||||||
|
|
|
@ -32,15 +32,15 @@ Details
|
||||||
|
|
||||||
The table layout is as follows:
|
The table layout is as follows:
|
||||||
|
|
||||||
+-------+----------------+----------------------+
|
+-------+----------------+------------------------+
|
||||||
| idx (i) | multiplier (e) | value (v = mmin * e) |
|
| idx (i) | multiplier (e) | value (v = mmin * e) |
|
||||||
+-------+----------------+----------------------+
|
+-------+----------------+------------------------+
|
||||||
| 1 | 2^(-149) | 0x800000 * 2^(-149) |
|
| 1 | 2^(-149) | 0x800000 * 2^(-149) |
|
||||||
| 2 | 2^(-148) | 0x800000 * 2^(-148) |
|
| 2 | 2^(-148) | 0x800000 * 2^(-148) |
|
||||||
| ... | ... | ... |
|
| ... | ... | ... |
|
||||||
| 253 | 2^103 | 0x800000 * 2^103 |
|
| 253 | 2^103 | 0x800000 * 2^103 |
|
||||||
| 254 | 2^104 | 0x800000 * 2^104 |
|
| 254 | 2^104 | 0x800000 * 2^104 |
|
||||||
+-------+----------------+----------------------+
|
+-------+----------------+------------------------+
|
||||||
|
|
||||||
The vmin and vmax boundaries are defined as:
|
The vmin and vmax boundaries are defined as:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue