Coverage Report

Created: 2026-06-30 08:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/frmts/grib/degrib/g2clib/rdieee.c
Line
Count
Source
1
#include "grib2.h"
2
3
void rdieee(g2int *rieee,g2float *a,g2int num)
4
//$$$  SUBPROGRAM DOCUMENTATION BLOCK
5
//                .      .    .                                       .
6
// SUBPROGRAM:    rdieee
7
//   PRGMMR: Gilbert         ORG: W/NP11    DATE: 2002-10-25
8
//
9
// ABSTRACT: This subroutine reads a list of real values in
10
//   32-bit IEEE floating point format.
11
//
12
// PROGRAM HISTORY LOG:
13
// 2002-10-25  Gilbert
14
//
15
// USAGE:    void rdieee(g2int *rieee,g2float *a,g2int num)
16
//   INPUT ARGUMENT LIST:
17
//     rieee    - g2int array of floating point values in 32-bit IEEE format.
18
//     num      - Number of floating point values to convert.
19
//
20
//   OUTPUT ARGUMENT LIST:
21
//     a        - float array of real values.  a must be allocated with at
22
//                least 4*num bytes of memory before calling this function.
23
//
24
// REMARKS: None
25
//
26
// ATTRIBUTES:
27
//   LANGUAGE: C
28
//   MACHINE:  IBM SP
29
//
30
//$$$
31
9.54k
{
32
33
9.54k
      g2int  j;
34
9.54k
      g2int  isign,iexp,imant;
35
36
9.54k
      g2float  sign,temp;
37
9.54k
      static const double two23 = 1.1920928955078125e-07; // pow(2,-23)
38
9.54k
      static const double two126 = 1.1754943508222875e-38; // pow(2,-126)
39
40
41
9.54k
      g2intu msk1=0x80000000;        // 10000000000000000000000000000000 binary
42
9.54k
      g2int msk2=0x7F800000;         // 01111111100000000000000000000000 binary
43
9.54k
      g2int msk3=0x007FFFFF;         // 00000000011111111111111111111111 binary
44
45
38.8M
      for (j=0;j<num;j++) {
46
//
47
//  Extract sign bit, exponent, and mantissa
48
//
49
38.8M
        isign=(rieee[j]&msk1)>>31;
50
38.8M
        iexp=(rieee[j]&msk2)>>23;
51
38.8M
        imant=(rieee[j]&msk3);
52
        //printf("SAGieee= %ld %ld %ld\n",isign,iexp,imant);
53
54
38.8M
        sign=1.0;
55
38.8M
        if (isign == 1) sign=-1.0;
56
57
38.8M
        if ( (iexp > 0) && (iexp < 255) ) {
58
18.9k
          temp=(g2float)int_power(2.0,(iexp-127));
59
18.9k
          a[j]=(float)(sign*temp*(1.0+(two23*(g2float)imant)));
60
18.9k
        }
61
38.7M
        else if ( iexp == 0 ) {
62
38.7M
          if ( imant != 0 )
63
9.98k
            a[j]=(float)(sign*two126*two23*(g2float)imant);
64
38.7M
          else
65
38.7M
            a[j]=(float)(sign*0.0);
66
67
38.7M
        }
68
5
        else if ( iexp == 255 )
69
5
           a[j]=(float)(sign*(1E+37));
70
71
72
38.8M
      }
73
74
9.54k
}