Loading...
Searching...
No Matches
rdieee.c
Go to the documentation of this file.
#include "grib2_int.h"
void
rdieee(g2int *rieee, float *a, g2int num)
{
g2int j;
g2int isign, iexp, imant;
float sign, temp;
static float two23, two126;
static g2int test = 0;
uint64_t msk1 = 0x80000000; /* 10000000000000000000000000000000 binary */
g2int msk2 = 0x7F800000; /* 01111111100000000000000000000000 binary */
g2int msk3 = 0x007FFFFF; /* 00000000011111111111111111111111 binary */
if (test == 0)
{
two23 = (float)int_power(2.0, -23);
two126 = (float)int_power(2.0, -126);
test = 1;
}
for (j = 0; j < num; j++)
{
/* Extract sign bit, exponent, and mantissa */
isign = (rieee[j] & msk1) >> 31;
iexp = (rieee[j] & msk2) >> 23;
imant = (rieee[j] & msk3);
/*printf("SAGieee= %ld %ld %ld\n",isign,iexp,imant); */
sign = 1.0;
if (isign == 1)
sign = -1.0;
if ((iexp > 0) && (iexp < 255))
{
temp = (float)int_power(2.0, (iexp - 127));
a[j] = sign * temp * (1.0 + (two23 * (float)imant));
}
else if (iexp == 0)
{
if (imant != 0)
a[j] = sign * two126 * two23 * (float)imant;
else
a[j] = sign * 0.0;
}
else if (iexp == 255)
a[j] = sign * (1E+37);
}
}
g2int
int64_t g2int
Long integer type.
Definition grib2.h:32
grib2_int.h
Header file with internal function prototypes NCEPLIBS-g2c library.
int_power
double int_power(double x, g2int y)
Function similar to C pow() power function.
Definition int_power.c:18
rdieee
void rdieee(g2int *rieee, float *a, g2int num)
Read a list of real values in 32-bit IEEE floating point format.
Definition rdieee.c:20