Last change
on this file since 1 was
1,
checked in by lfita, 10 years ago
|
- -- --- Opening of the WRF+LMDZ coupling repository --- -- -
WRF: version v3.3
LMDZ: version v1818
More details in:
|
File size:
738 bytes
|
Line | |
---|
1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | |
---|
4 | /* ibm2flt wesley ebisuzaki |
---|
5 | * |
---|
6 | * v1.1 .. faster |
---|
7 | * v1.1 .. if mant == 0 -> quick return |
---|
8 | * |
---|
9 | */ |
---|
10 | |
---|
11 | |
---|
12 | double ibm2flt(unsigned char *ibm) { |
---|
13 | |
---|
14 | int positive, power; |
---|
15 | unsigned int abspower; |
---|
16 | long int mant; |
---|
17 | double value, exp; |
---|
18 | |
---|
19 | mant = (ibm[1] << 16) + (ibm[2] << 8) + ibm[3]; |
---|
20 | if (mant == 0) return 0.0; |
---|
21 | |
---|
22 | positive = (ibm[0] & 0x80) == 0; |
---|
23 | power = (int) (ibm[0] & 0x7f) - 64; |
---|
24 | abspower = power > 0 ? power : -power; |
---|
25 | |
---|
26 | |
---|
27 | /* calc exp */ |
---|
28 | exp = 16.0; |
---|
29 | value = 1.0; |
---|
30 | while (abspower) { |
---|
31 | if (abspower & 1) { |
---|
32 | value *= exp; |
---|
33 | } |
---|
34 | exp = exp * exp; |
---|
35 | abspower >>= 1; |
---|
36 | } |
---|
37 | |
---|
38 | if (power < 0) value = 1.0 / value; |
---|
39 | value = value * mant / 16777216.0; |
---|
40 | if (positive == 0) value = -value; |
---|
41 | return value; |
---|
42 | } |
---|
43 | |
---|
Note: See
TracBrowser
for help on using the repository browser.