From aee89904a8818221fcc78474060e283bdca1a55e Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 12 Oct 2023 11:38:40 +0100 Subject: [PATCH] ECC-1701: Compile-time initialisation of IBM/IEEE float tables --- src/grib_ibmfloat.h | 20 +++++++++----------- src/grib_ieeefloat.cc | 12 +----------- src/grib_ieeefloat.h | 16 ++++++++-------- 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/grib_ibmfloat.h b/src/grib_ibmfloat.h index a15736331..e979d4e9b 100644 --- a/src/grib_ibmfloat.h +++ b/src/grib_ibmfloat.h @@ -10,19 +10,17 @@ #pragma once -#include "grib_api_internal.h" #include "grib_scaling.h" #include #include #include - /** .. _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: diff --git a/src/grib_ieeefloat.cc b/src/grib_ieeefloat.cc index a8bfd557a..5c8ffbb18 100644 --- a/src/grib_ieeefloat.cc +++ b/src/grib_ieeefloat.cc @@ -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; diff --git a/src/grib_ieeefloat.h b/src/grib_ieeefloat.h index b81ec7b21..29e1011ad 100644 --- a/src/grib_ieeefloat.h +++ b/src/grib_ieeefloat.h @@ -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: