NCEPLIBS-g2c  1.8.0
rdieee.c
Go to the documentation of this file.
1 
6 #include "grib2_int.h"
7 
20 void
21 rdieee(g2int *rieee, float *a, g2int num)
22 {
23 
24  g2int j;
25  g2int isign,iexp,imant;
26 
27  float sign,temp;
28  static float two23,two126;
29  static g2int test = 0;
30  uint64_t msk1 = 0x80000000; /* 10000000000000000000000000000000 binary */
31  g2int msk2 = 0x7F800000; /* 01111111100000000000000000000000 binary */
32  g2int msk3 = 0x007FFFFF; /* 00000000011111111111111111111111 binary */
33 
34  if (test == 0)
35  {
36  two23 = (float)int_power(2.0,-23);
37  two126 = (float)int_power(2.0,-126);
38  test = 1;
39  }
40 
41  for (j = 0; j < num; j++)
42  {
43  /* Extract sign bit, exponent, and mantissa */
44  isign = (rieee[j]&msk1)>>31;
45  iexp = (rieee[j]&msk2)>>23;
46  imant = (rieee[j]&msk3);
47  /*printf("SAGieee= %ld %ld %ld\n",isign,iexp,imant); */
48 
49  sign = 1.0;
50  if (isign == 1)
51  sign = -1.0;
52 
53  if ((iexp > 0) && (iexp < 255))
54  {
55  temp = (float)int_power(2.0, (iexp - 127));
56  a[j] = sign * temp * (1.0 + (two23 * (float)imant));
57  }
58  else if (iexp == 0)
59  {
60  if (imant != 0)
61  a[j] = sign * two126 * two23 * (float)imant;
62  else
63  a[j] = sign * 0.0;
64 
65  }
66  else if (iexp == 255)
67  a[j] = sign * (1E+37);
68 
69  }
70 }
int64_t g2int
Long integer type.
Definition: grib2.h:33
Header file with internal function prototypes NCEPLIBS-g2c library.
double int_power(double x, g2int y)
Function similar to C pow() power function.
Definition: int_power.c:18
void rdieee(g2int *rieee, float *a, g2int num)
This subroutine reads a list of real values in 32-bit IEEE floating point format.
Definition: rdieee.c:21