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