1 /******************************************************************************
2 *
3 * NSSDC/CDF CDF encoding/decoding.
4 *
5 * Version 1.3a, 18-Nov-97, Hughes STX.
6 *
7 * Modification history:
8 *
9 * V1.0 31-Jan-94, J Love Original version.
10 * V1.0a 8-Feb-94, J Love DEC Alpha/OpenVMS port.
11 * V1.1 9-Nov-94, J Love CDF V2.5.
12 * V1.1a 5-Jan-95, J Love Encode/decode changes.
13 * V1.1b 19-Jan-95, J Love IRIX 6.0 (64-bit).
14 * V1.1c 24-Feb-95, J Love Solaris 2.3 IDL i/f.
15 * V1.2 21-Mar-95, J Love POSIX.
16 * V1.2a 18-Apr-95, J Love More POSIX.
17 * V1.3 3-Oct-96, J Love CDF V2.6.
18 * V1.3a 18-Nov-97, J Love Windows NT/Visual C++.
19 * V3.3 10-Jan-09, M Liu Modifed to check input argument for numElems
20 * in ConvertBuffer.
21 *
22 ******************************************************************************/
23
24 #include "cdflib.h"
25
26 #if defined(alphavms) || defined(posixSHELLalpha)
27 #define DYNAMICfpSTRUCTs 1
28 #define STATICfpSTRUCTs 0
29 #else
30 #define STATICfpSTRUCTs 1
31 #define DYNAMICfpSTRUCTs 0
32 #endif
33
34 #if defined(alphavmsD) || defined(posixSHELLalphaD)
35 #define LIMITfp3DOUBLEs 1
36 #else
37 #define LIMITfp3DOUBLEs 0
38 #endif
39
40 /******************************************************************************
41 * Minimums, maximums, and zeros.
42 ******************************************************************************/
43
44 #if defined(FP1cpu)
45 #define FP1ZEROsingle 0x0,0x0,0x0,0x0,0x0,0x0
46 #define FP2ZEROsingle 0x0,0x0,0x0,0x0,0x0,0x0
47 #define FP34ZEROsingle 0x0,0x0,0x0,0x0,0x0,0x0
48 #define FP1ZEROsingleNEG 0x1,0x0,0x0,0x0,0x0,0x0
49 #define FP2ZEROsingleNEG 0x0,0x0,0x0,0x0,0x1,0x0
50 #define FP34MINsingle 0x1,0x0,0x0,0x0,0x0,0x0
51 #define FP34MAXsingle 0x1,0x7F,0x0,0x7F,0xFF,0xFF
52 #define FP1ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
53 #define FP2ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
54 #define FP3ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
55 #define FP4ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
56 #define FP1ZEROdoubleNEG 0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
57 #define FP2ZEROdoubleNEG 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0
58 #define FP3MINdouble 0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
59 #define FP3MAXdouble 0x1,0x7F,0x0,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
60 #define FP4MINdouble 0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
61 #define FP4MAXdouble 0xF,0xF,0x0,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
62 #endif
63
64 #if defined(FP2cpu) || defined(FP3cpu) || defined(FP4cpu)
65 #define FP1ZEROsingle 0x0,0x0,0x0,0x0,0x0,0x0
66 #define FP2ZEROsingle 0x0,0x0,0x0,0x0,0x0,0x0
67 #define FP34ZEROsingle 0x0,0x0,0x0,0x0,0x0,0x0
68 #define FP1ZEROsingleNEG 0x0,0x1,0x0,0x0,0x0,0x0
69 #define FP2ZEROsingleNEG 0x0,0x0,0x0,0x0,0x0,0x1
70 #define FP34MINsingle 0x0,0x1,0x0,0x0,0x0,0x0
71 #define FP34MAXsingle 0x7F,0x1,0x7F,0x0,0xFF,0xFF
72 #define FP1ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
73 #define FP2ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
74 #define FP3ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
75 #define FP4ZEROdouble 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
76 #define FP1ZEROdoubleNEG 0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
77 #define FP2ZEROdoubleNEG 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1
78 #define FP3MINdouble 0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
79 #define FP3MAXdouble 0x7F,0x1,0x7F,0x0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
80 #define FP4MINdouble 0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
81 #define FP4MAXdouble 0xF,0xF,0x7F,0x0,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
82 #endif
83
84 #if STATICfpSTRUCTs
85 static struct fp1struct4 FP1zeroSingle = { FP1ZEROsingle };
86 static struct fp2struct4 FP2zeroSingle = { FP2ZEROsingle };
87 static struct fp34struct4 FP34zeroSingle = { FP34ZEROsingle };
88 static struct fp1struct4 FP1zeroSingleNeg = { FP1ZEROsingleNEG };
89 static struct fp2struct4 FP2zeroSingleNeg = { FP2ZEROsingleNEG };
90 static struct fp34struct4 FP34minSingle = { FP34MINsingle };
91 static struct fp34struct4 FP34maxSingle = { FP34MAXsingle };
92 static struct fp1struct8 FP1zeroDouble = { FP1ZEROdouble };
93 static struct fp2struct8 FP2zeroDouble = { FP2ZEROdouble };
94 static struct fp3struct8 FP3zeroDouble = { FP3ZEROdouble };
95 static struct fp4struct8 FP4zeroDouble = { FP4ZEROdouble };
96 static struct fp1struct8 FP1zeroDoubleNeg = { FP1ZEROdoubleNEG };
97 static struct fp2struct8 FP2zeroDoubleNeg = { FP2ZEROdoubleNEG };
98 static struct fp3struct8 FP3minDouble = { FP3MINdouble };
99 static struct fp3struct8 FP3maxDouble = { FP3MAXdouble };
100 static struct fp4struct8 FP4minDouble = { FP4MINdouble };
101 static struct fp4struct8 FP4maxDouble = { FP4MAXdouble };
102 #endif
103
104 /******************************************************************************
105 * ConvertBuffer.
106 ******************************************************************************/
107
ConvertBuffer(srcEncoding,dstEncoding,negToPosFp0,dataType,numElems,srcBuffer,dstBuffer)108 VISIBLE_PREFIX CDFstatus ConvertBuffer (srcEncoding, dstEncoding, negToPosFp0,
109 dataType, numElems, srcBuffer, dstBuffer)
110 Int32 srcEncoding;
111 Int32 dstEncoding;
112 Logical negToPosFp0;
113 Int32 dataType;
114 Int32 numElems;
115 void *srcBuffer;
116 void *dstBuffer;
117 {
118 Int32 tSrcEncoding = BOO(srcEncoding == HOST_ENCODING,
119 HostEncoding(), srcEncoding);
120 Int32 tDstEncoding = BOO(dstEncoding == HOST_ENCODING,
121 HostEncoding(), dstEncoding);
122
123 CDFstatus pStatus = CDF_OK; /* Pending status code. Note that the status
124 code from a routine is only checked in those
125 cases were NEGATIVE_FP_ZERO may be returned
126 (ie., when converting to a VMSish floating
127 point encoding). */
128
129 if (numElems < 1) return CDF_INTERNAL_ERROR;
130
131 switch (dataType) {
132 /************************************************************************
133 * Bytes/characters - these are the same on all supported computers so no
134 * conversion is necessary.
135 ************************************************************************/
136 case CDF_BYTE:
137 case CDF_INT1:
138 case CDF_UINT1:
139 case CDF_CHAR:
140 case CDF_UCHAR:
141 MEMMOVE (dstBuffer, srcBuffer, (size_t) numElems)
142 break;
143 /************************************************************************
144 * 2-byte integers.
145 ************************************************************************/
146 case CDF_INT2:
147 case CDF_UINT2:
148 if (IntegerOrder(tSrcEncoding) == IntegerOrder(tDstEncoding)) {
149 MEMMOVE (dstBuffer, srcBuffer, (size_t) (2 * numElems));
150 }
151 else {
152 MEMMOVE (dstBuffer, srcBuffer, (size_t) (2 * numElems));
153 Reverse2 (dstBuffer, numElems);
154 }
155 break;
156 /************************************************************************
157 * 4-byte integers.
158 ************************************************************************/
159 case CDF_INT4:
160 case CDF_UINT4:
161 if (IntegerOrder(tSrcEncoding) == IntegerOrder(tDstEncoding)) {
162 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems));
163 }
164 else {
165 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems));
166 Reverse4 (dstBuffer, numElems);
167 }
168 break;
169 /************************************************************************
170 * 4-byte floating-point values.
171 ************************************************************************/
172 case CDF_REAL4:
173 case CDF_FLOAT: {
174 int srcFpType = FpType (tSrcEncoding);
175 int dstFpType = FpType (tDstEncoding);
176 switch (srcFpType) {
177 /********************************************************************
178 * Floating-point/1 source encoding.
179 ********************************************************************/
180 case FP_1:
181 switch (dstFpType) {
182 /****************************************************************
183 * Floating-point/1 destination encoding desired.
184 ****************************************************************/
185 case FP_1:
186 if (negToPosFp0) {
187 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
188 FP1singleNEGtoPOS (dstBuffer, numElems);
189 }
190 else {
191 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
192 }
193 break;
194 /****************************************************************
195 * Floating-point/2 destination encoding desired.
196 ****************************************************************/
197 case FP_2:
198 if (negToPosFp0) {
199 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
200 FP1toFP2singleNEGtoPOS (dstBuffer, numElems);
201 }
202 else {
203 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
204 Reverse4 (dstBuffer, numElems);
205 }
206 break;
207 /****************************************************************
208 * Floating-point/34 destination encoding desired.
209 ****************************************************************/
210 case FP_3:
211 case FP_4:
212 if (negToPosFp0) {
213 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
214 FP1toFP34singleNEGtoPOS (dstBuffer, numElems);
215 }
216 else {
217 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
218 sX (FP1toFP34single(dstBuffer,numElems), &pStatus);
219 }
220 break;
221 }
222 break;
223 /********************************************************************
224 * Floating-point/2 source encoding.
225 ********************************************************************/
226 case FP_2:
227 switch (dstFpType) {
228 /****************************************************************
229 * Floating-point/1 destination encoding desired.
230 ****************************************************************/
231 case FP_1:
232 if (negToPosFp0) {
233 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
234 FP2toFP1singleNEGtoPOS (dstBuffer, numElems);
235 }
236 else {
237 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
238 Reverse4 (dstBuffer, numElems);
239 }
240 break;
241 /****************************************************************
242 * Floating-point/2 destination encoding desired.
243 ****************************************************************/
244 case FP_2:
245 if (negToPosFp0) {
246 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
247 FP2singleNEGtoPOS (dstBuffer, numElems);
248 }
249 else {
250 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
251 }
252 break;
253 /****************************************************************
254 * Floating-point/34 destination encoding desired.
255 ****************************************************************/
256 case FP_3:
257 case FP_4:
258 if (negToPosFp0) {
259 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
260 FP2toFP34singleNEGtoPOS (dstBuffer, numElems);
261 }
262 else {
263 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
264 sX (FP2toFP34single(dstBuffer,numElems), &pStatus);
265 }
266 break;
267 }
268 break;
269 /********************************************************************
270 * Floating-point/34 source encoding.
271 ********************************************************************/
272 case FP_3:
273 case FP_4:
274 switch (dstFpType) {
275 /****************************************************************
276 * Floating-point/1 destination encoding desired.
277 ****************************************************************/
278 case FP_1:
279 if (negToPosFp0) {
280 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
281 FP34toFP1singleNEGtoPOS (dstBuffer, numElems);
282 }
283 else {
284 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
285 FP34toFP1single (dstBuffer, numElems);
286 }
287 break;
288 /****************************************************************
289 * Floating-point/2 destination encoding desired.
290 ****************************************************************/
291 case FP_2:
292 if (negToPosFp0) {
293 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
294 FP34toFP2singleNEGtoPOS (dstBuffer, numElems);
295 }
296 else {
297 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
298 FP34toFP2single (dstBuffer, numElems);
299 }
300 break;
301 /****************************************************************
302 * Floating-point/34 destination encoding desired.
303 ****************************************************************/
304 case FP_3:
305 case FP_4:
306 if (negToPosFp0) {
307 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
308 FP34singleNEGtoPOS (dstBuffer, numElems);
309 }
310 else {
311 MEMMOVE (dstBuffer, srcBuffer, (size_t) (4 * numElems))
312 }
313 break;
314 }
315 break;
316 }
317 break;
318 }
319 /************************************************************************
320 * 8-byte floating-point values.
321 ************************************************************************/
322 case CDF_REAL8:
323 case CDF_DOUBLE:
324 case CDF_EPOCH: {
325 int srcFpType = FpType (tSrcEncoding);
326 int dstFpType = FpType (tDstEncoding);
327 switch (srcFpType) {
328 /********************************************************************
329 * Floating-point/1 source encoding.
330 ********************************************************************/
331 case FP_1:
332 switch (dstFpType) {
333 /****************************************************************
334 * Floating-point/1 destination encoding desired.
335 ****************************************************************/
336 case FP_1:
337 if (negToPosFp0) {
338 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
339 FP1doubleNEGtoPOS (dstBuffer, numElems);
340 }
341 else {
342 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
343 }
344 break;
345 /****************************************************************
346 * Floating-point/2 destination encoding desired.
347 ****************************************************************/
348 case FP_2:
349 if (negToPosFp0) {
350 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
351 FP1toFP2doubleNEGtoPOS (dstBuffer, numElems);
352 }
353 else {
354 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
355 Reverse8 (dstBuffer, numElems);
356 }
357 break;
358 /****************************************************************
359 * Floating-point/3 destination encoding desired.
360 ****************************************************************/
361 case FP_3:
362 if (negToPosFp0) {
363 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
364 FP1toFP3doubleNEGtoPOS (dstBuffer, numElems);
365 }
366 else {
367 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
368 sX (FP1toFP3double(dstBuffer,numElems), &pStatus);
369 }
370 break;
371 /****************************************************************
372 * Floating-point/4 destination encoding desired.
373 ****************************************************************/
374 case FP_4:
375 if (negToPosFp0) {
376 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
377 FP1toFP4doubleNEGtoPOS (dstBuffer, numElems);
378 }
379 else {
380 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
381 sX (FP1toFP4double(dstBuffer,numElems), &pStatus);
382 }
383 break;
384 }
385 break;
386 /********************************************************************
387 * Floating-point/2 source encoding.
388 ********************************************************************/
389 case FP_2:
390 switch (dstFpType) {
391 /****************************************************************
392 * Floating-point/1 destination encoding desired.
393 ****************************************************************/
394 case FP_1:
395 if (negToPosFp0) {
396 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
397 FP2toFP1doubleNEGtoPOS (dstBuffer, numElems);
398 }
399 else {
400 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
401 Reverse8 (dstBuffer, numElems);
402 }
403 break;
404 /****************************************************************
405 * Floating-point/2 destination encoding desired.
406 ****************************************************************/
407 case FP_2:
408 if (negToPosFp0) {
409 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
410 FP2doubleNEGtoPOS (dstBuffer, numElems);
411 }
412 else {
413 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
414 }
415 break;
416 /****************************************************************
417 * Floating-point/3 destination encoding desired.
418 ****************************************************************/
419 case FP_3:
420 if (negToPosFp0) {
421 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
422 FP2toFP3doubleNEGtoPOS (dstBuffer, numElems);
423 }
424 else {
425 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
426 sX (FP2toFP3double(dstBuffer,numElems), &pStatus);
427 }
428 break;
429 /****************************************************************
430 * Floating-point/4 destination encoding desired.
431 ****************************************************************/
432 case FP_4:
433 if (negToPosFp0) {
434 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
435 FP2toFP4doubleNEGtoPOS (dstBuffer, numElems);
436 }
437 else {
438 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
439 sX (FP2toFP4double(dstBuffer,numElems), &pStatus);
440 }
441 break;
442 }
443 break;
444 /********************************************************************
445 * Floating-point/3 source encoding.
446 ********************************************************************/
447 case FP_3:
448 switch (dstFpType) {
449 /****************************************************************
450 * Floating-point/1 destination encoding desired.
451 ****************************************************************/
452 case FP_1:
453 if (negToPosFp0) {
454 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
455 FP3toFP1doubleNEGtoPOS (dstBuffer, numElems);
456 }
457 else {
458 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
459 FP3toFP1double (dstBuffer, numElems);
460 }
461 break;
462 /****************************************************************
463 * Floating-point/2 destination encoding desired.
464 ****************************************************************/
465 case FP_2:
466 if (negToPosFp0) {
467 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
468 FP3toFP2doubleNEGtoPOS (dstBuffer, numElems);
469 }
470 else {
471 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
472 FP3toFP2double (dstBuffer, numElems);
473 }
474 break;
475 /****************************************************************
476 * Floating-point/3 destination encoding desired.
477 ****************************************************************/
478 case FP_3:
479 if (negToPosFp0) {
480 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
481 FP3doubleNEGtoPOS (dstBuffer, numElems);
482 }
483 else {
484 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
485 #if LIMITfp3DOUBLEs
486 sX (FP3doubleLIMIT(dstBuffer,numElems), &pStatus);
487 #endif
488 }
489 break;
490 /****************************************************************
491 * Floating-point/4 destination encoding desired.
492 ****************************************************************/
493 case FP_4:
494 if (negToPosFp0) {
495 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
496 FP3toFP4doubleNEGtoPOS (dstBuffer, numElems);
497 }
498 else {
499 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
500 sX (FP3toFP4double(dstBuffer,numElems), &pStatus);
501 }
502 break;
503 }
504 break;
505 /********************************************************************
506 * Floating-point/4 source encoding.
507 ********************************************************************/
508 case FP_4:
509 switch (dstFpType) {
510 /****************************************************************
511 * Floating-point/1 destination encoding desired.
512 ****************************************************************/
513 case FP_1:
514 if (negToPosFp0) {
515 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
516 FP4toFP1doubleNEGtoPOS (dstBuffer, numElems);
517 }
518 else {
519 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
520 FP4toFP1double (dstBuffer, numElems);
521 }
522 break;
523 /****************************************************************
524 * Floating-point/2 destination encoding desired.
525 ****************************************************************/
526 case FP_2:
527 if (negToPosFp0) {
528 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
529 FP4toFP2doubleNEGtoPOS (dstBuffer, numElems);
530 }
531 else {
532 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
533 FP4toFP2double (dstBuffer, numElems);
534 }
535 break;
536 /****************************************************************
537 * Floating-point/3 destination encoding desired.
538 ****************************************************************/
539 case FP_3:
540 if (negToPosFp0) {
541 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
542 FP4toFP3doubleNEGtoPOS (dstBuffer, numElems);
543 }
544 else {
545 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
546 sX (FP4toFP3double(dstBuffer,numElems), &pStatus);
547 }
548 break;
549 /****************************************************************
550 * Floating-point/4 destination encoding desired.
551 ****************************************************************/
552 case FP_4:
553 if (negToPosFp0) {
554 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
555 FP4doubleNEGtoPOS (dstBuffer, numElems);
556 }
557 else {
558 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems))
559 }
560 break;
561 }
562 break;
563 }
564 break;
565 }
566 /************************************************************************
567 * 2 8-byte floating-point values.
568 ************************************************************************/
569 case CDF_EPOCH16: {
570 int srcFpType = FpType (tSrcEncoding);
571 int dstFpType = FpType (tDstEncoding);
572 switch (srcFpType) {
573 /********************************************************************
574 * Floating-point/1 source encoding.
575 ********************************************************************/
576 case FP_1:
577 switch (dstFpType) {
578 /****************************************************************
579 * Floating-point/1 destination encoding desired.
580 ****************************************************************/
581 case FP_1:
582 if (negToPosFp0) {
583 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
584 FP1doubleNEGtoPOS (dstBuffer, numElems * 2);
585 }
586 else {
587 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
588 }
589 break;
590 /****************************************************************
591 * Floating-point/2 destination encoding desired.
592 ****************************************************************/
593 case FP_2:
594 if (negToPosFp0) {
595 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
596 FP1toFP2doubleNEGtoPOS (dstBuffer, numElems * 2);
597 }
598 else {
599 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
600 Reverse8 (dstBuffer, numElems * 2);
601 }
602 break;
603 /****************************************************************
604 * Floating-point/3 destination encoding desired.
605 ****************************************************************/
606 case FP_3:
607 if (negToPosFp0) {
608 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
609 FP1toFP3doubleNEGtoPOS (dstBuffer, numElems * 2);
610 }
611 else {
612 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
613 sX (FP1toFP3double(dstBuffer,numElems * 2), &pStatus);
614 }
615 break;
616 /****************************************************************
617 * Floating-point/4 destination encoding desired.
618 ****************************************************************/
619 case FP_4:
620 if (negToPosFp0) {
621 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
622 FP1toFP4doubleNEGtoPOS (dstBuffer, numElems * 2);
623 }
624 else {
625 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
626 sX (FP1toFP4double(dstBuffer,numElems * 2), &pStatus);
627 }
628 break;
629 }
630 break;
631 /********************************************************************
632 * Floating-point/2 source encoding.
633 ********************************************************************/
634 case FP_2:
635 switch (dstFpType) {
636 /****************************************************************
637 * Floating-point/1 destination encoding desired.
638 ****************************************************************/
639 case FP_1:
640 if (negToPosFp0) {
641 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
642 FP2toFP1doubleNEGtoPOS (dstBuffer, numElems * 2);
643 }
644 else {
645 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
646 Reverse8 (dstBuffer, numElems * 2);
647 }
648 break;
649 /****************************************************************
650 * Floating-point/2 destination encoding desired.
651 ****************************************************************/
652 case FP_2:
653 if (negToPosFp0) {
654 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
655 FP2doubleNEGtoPOS (dstBuffer, numElems * 2);
656 }
657 else {
658 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
659 }
660 break;
661 /****************************************************************
662 * Floating-point/3 destination encoding desired.
663 ****************************************************************/
664 case FP_3:
665 if (negToPosFp0) {
666 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
667 FP2toFP3doubleNEGtoPOS (dstBuffer, numElems * 2);
668 }
669 else {
670 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
671 sX (FP2toFP3double(dstBuffer,numElems * 2), &pStatus);
672 }
673 break;
674 /****************************************************************
675 * Floating-point/4 destination encoding desired.
676 ****************************************************************/
677 case FP_4:
678 if (negToPosFp0) {
679 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
680 FP2toFP4doubleNEGtoPOS (dstBuffer, numElems * 2);
681 }
682 else {
683 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
684 sX (FP2toFP4double(dstBuffer,numElems * 2), &pStatus);
685 }
686 break;
687 }
688 break;
689 /********************************************************************
690 * Floating-point/3 source encoding.
691 ********************************************************************/
692 case FP_3:
693 switch (dstFpType) {
694 /****************************************************************
695 * Floating-point/1 destination encoding desired.
696 ****************************************************************/
697 case FP_1:
698 if (negToPosFp0) {
699 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
700 FP3toFP1doubleNEGtoPOS (dstBuffer, numElems * 2);
701 }
702 else {
703 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
704 FP3toFP1double (dstBuffer, numElems * 2);
705 }
706 break;
707 /****************************************************************
708 * Floating-point/2 destination encoding desired.
709 ****************************************************************/
710 case FP_2:
711 if (negToPosFp0) {
712 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
713 FP3toFP2doubleNEGtoPOS (dstBuffer, numElems * 2);
714 }
715 else {
716 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
717 FP3toFP2double (dstBuffer, numElems * 2);
718 }
719 break;
720 /****************************************************************
721 * Floating-point/3 destination encoding desired.
722 ****************************************************************/
723 case FP_3:
724 if (negToPosFp0) {
725 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
726 FP3doubleNEGtoPOS (dstBuffer, numElems * 2);
727 }
728 else {
729 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
730 #if LIMITfp3DOUBLEs
731 sX (FP3doubleLIMIT(dstBuffer,numElems * 2), &pStatus);
732 #endif
733 }
734 break;
735 /****************************************************************
736 * Floating-point/4 destination encoding desired.
737 ****************************************************************/
738 case FP_4:
739 if (negToPosFp0) {
740 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
741 FP3toFP4doubleNEGtoPOS (dstBuffer, numElems * 2);
742 }
743 else {
744 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
745 sX (FP3toFP4double(dstBuffer,numElems * 2), &pStatus);
746 }
747 break;
748 }
749 break;
750 /********************************************************************
751 * Floating-point/4 source encoding.
752 ********************************************************************/
753 case FP_4:
754 switch (dstFpType) {
755 /****************************************************************
756 * Floating-point/1 destination encoding desired.
757 ****************************************************************/
758 case FP_1:
759 if (negToPosFp0) {
760 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
761 FP4toFP1doubleNEGtoPOS (dstBuffer, numElems * 2);
762 }
763 else {
764 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
765 FP4toFP1double (dstBuffer, numElems * 2);
766 }
767 break;
768 /****************************************************************
769 * Floating-point/2 destination encoding desired.
770 ****************************************************************/
771 case FP_2:
772 if (negToPosFp0) {
773 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
774 FP4toFP2doubleNEGtoPOS (dstBuffer, numElems * 2);
775 }
776 else {
777 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
778 FP4toFP2double (dstBuffer, numElems * 2);
779 }
780 break;
781 /****************************************************************
782 * Floating-point/3 destination encoding desired.
783 ****************************************************************/
784 case FP_3:
785 if (negToPosFp0) {
786 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
787 FP4toFP3doubleNEGtoPOS (dstBuffer, numElems * 2);
788 }
789 else {
790 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
791 sX (FP4toFP3double(dstBuffer,numElems * 2), &pStatus);
792 }
793 break;
794 /****************************************************************
795 * Floating-point/4 destination encoding desired.
796 ****************************************************************/
797 case FP_4:
798 if (negToPosFp0) {
799 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
800 FP4doubleNEGtoPOS (dstBuffer, numElems * 2);
801 }
802 else {
803 MEMMOVE (dstBuffer, srcBuffer, (size_t) (8 * numElems * 2))
804 }
805 break;
806 }
807 break;
808 }
809 break;
810 }
811 /************************************************************************
812 * Unknown data type.
813 ************************************************************************/
814 default:
815 return CDF_INTERNAL_ERROR;
816 }
817 return pStatus;
818 }
819
820 /******************************************************************************
821 * ConversionFunction.
822 ******************************************************************************/
823
ConversionFunction(dataType,encoding,decoding,negToPosFp0,function)824 STATICforIDL CDFstatus ConversionFunction (dataType, encoding, decoding,
825 negToPosFp0, function)
826 Int32 dataType;
827 Int32 encoding;
828 Int32 decoding;
829 Logical negToPosFp0;
830 CDFstatus (**function) PROTOARGs((void *buffer, Int32 numElems));
831 {
832 Int32 tDecoding = BOO(decoding == HOST_DECODING,HostDecoding(), decoding);
833 switch (dataType) {
834 /**************************************************************************
835 * Bytes/characters - these are the same on all supported computers so no
836 * decoding is necessary.
837 **************************************************************************/
838 case CDF_BYTE:
839 case CDF_INT1:
840 case CDF_UINT1:
841 case CDF_CHAR:
842 case CDF_UCHAR:
843 *function = NULL;
844 break;
845 /**************************************************************************
846 * 2-byte integers.
847 **************************************************************************/
848 case CDF_INT2:
849 case CDF_UINT2:
850 if (IntegerOrder(encoding) == IntegerOrder(tDecoding))
851 *function = NULL;
852 else
853 *function = Reverse2;
854 break;
855 /**************************************************************************
856 * 4-byte integers.
857 **************************************************************************/
858 case CDF_INT4:
859 case CDF_UINT4:
860 if (IntegerOrder(encoding) == IntegerOrder(tDecoding))
861 *function = NULL;
862 else
863 *function = Reverse4;
864 break;
865 /**************************************************************************
866 * 4-byte floating-point values.
867 **************************************************************************/
868 case CDF_REAL4:
869 case CDF_FLOAT: {
870 int fpEncoding = FpType (encoding);
871 int fpDecoding = FpType (tDecoding);
872 switch (fpEncoding) {
873 /**********************************************************************
874 * Floating-point/1 encoding.
875 **********************************************************************/
876 case FP_1:
877 switch (fpDecoding) {
878 /******************************************************************
879 * Floating-point/1 encoding - floating-point/1 decoding desired.
880 ******************************************************************/
881 case FP_1:
882 if (negToPosFp0)
883 *function = FP1singleNEGtoPOS;
884 else
885 *function = NULL;
886 break;
887 /******************************************************************
888 * Floating-point/1 encoding - floating-point/2 decoding desired.
889 ******************************************************************/
890 case FP_2:
891 if (negToPosFp0)
892 *function = FP1toFP2singleNEGtoPOS;
893 else
894 *function = Reverse4;
895 break;
896 /******************************************************************
897 * Floating-point/1 encoding - floating-point/34 decoding desired.
898 ******************************************************************/
899 case FP_3:
900 case FP_4:
901 if (negToPosFp0)
902 *function = FP1toFP34singleNEGtoPOS;
903 else
904 *function = FP1toFP34single;
905 break;
906 }
907 break;
908 /**********************************************************************
909 * Floating-point/2 encoding.
910 **********************************************************************/
911 case FP_2:
912 switch (fpDecoding) {
913 /******************************************************************
914 * Floating-point/2 encoding - floating-point/1 decoding desired.
915 ******************************************************************/
916 case FP_1:
917 if (negToPosFp0)
918 *function = FP2toFP1singleNEGtoPOS;
919 else
920 *function = Reverse4;
921 break;
922 /******************************************************************
923 * Floating-point/2 encoding - floating-point/2 decoding desired.
924 ******************************************************************/
925 case FP_2:
926 if (negToPosFp0)
927 *function = FP2singleNEGtoPOS;
928 else
929 *function = NULL;
930 break;
931 /******************************************************************
932 * Floating-point/2 encoding - floating-point/34 decoding desired.
933 ******************************************************************/
934 case FP_3:
935 case FP_4:
936 if (negToPosFp0)
937 *function = FP2toFP34singleNEGtoPOS;
938 else
939 *function = FP2toFP34single;
940 break;
941 }
942 break;
943 /**********************************************************************
944 * Floating-point/34 encoding.
945 **********************************************************************/
946 case FP_3:
947 case FP_4:
948 switch (fpDecoding) {
949 /******************************************************************
950 * Floating-point/34 encoding - floating-point/1 decoding desired.
951 ******************************************************************/
952 case FP_1:
953 if (negToPosFp0)
954 *function = FP34toFP1singleNEGtoPOS;
955 else
956 *function = FP34toFP1single;
957 break;
958 /******************************************************************
959 * Floating-point/34 encoding - floating-point/2 decoding desired.
960 ******************************************************************/
961 case FP_2:
962 if (negToPosFp0)
963 *function = FP34toFP2singleNEGtoPOS;
964 else
965 *function = FP34toFP2single;
966 break;
967 /******************************************************************
968 * Floating-point/34 encoding - floating-point/34 decoding
969 * desired.
970 ******************************************************************/
971 case FP_3:
972 case FP_4:
973 if (negToPosFp0)
974 *function = FP34singleNEGtoPOS;
975 else
976 *function = NULL;
977 break;
978 }
979 break;
980 }
981 break;
982 }
983 /**************************************************************************
984 * 8-byte floating-point values.
985 **************************************************************************/
986 case CDF_REAL8:
987 case CDF_DOUBLE:
988 case CDF_EPOCH: {
989 int fpEncoding = FpType (encoding);
990 int fpDecoding = FpType (tDecoding);
991 switch (fpEncoding) {
992 /**********************************************************************
993 * Floating-point/1 encoding.
994 **********************************************************************/
995 case FP_1:
996 switch (fpDecoding) {
997 /******************************************************************
998 * Floating-point/1 encoding - floating-point/1 decoding desired.
999 ******************************************************************/
1000 case FP_1:
1001 if (negToPosFp0)
1002 *function = FP1doubleNEGtoPOS;
1003 else
1004 *function = NULL;
1005 break;
1006 /******************************************************************
1007 * Floating-point/1 encoding - floating-point/2 decoding desired.
1008 ******************************************************************/
1009 case FP_2:
1010 if (negToPosFp0)
1011 *function = FP1toFP2doubleNEGtoPOS;
1012 else
1013 *function = Reverse8;
1014 break;
1015 /******************************************************************
1016 * Floating-point/1 encoding - floating-point/3 decoding desired.
1017 ******************************************************************/
1018 case FP_3:
1019 if (negToPosFp0)
1020 *function = FP1toFP3doubleNEGtoPOS;
1021 else
1022 *function = FP1toFP3double;
1023 break;
1024 /******************************************************************
1025 * Floating-point/1 encoding - floating-point/4 decoding desired.
1026 ******************************************************************/
1027 case FP_4:
1028 if (negToPosFp0)
1029 *function = FP1toFP4doubleNEGtoPOS;
1030 else
1031 *function = FP1toFP4double;
1032 break;
1033 }
1034 break;
1035 /**********************************************************************
1036 * Floating-point/2 encoding.
1037 **********************************************************************/
1038 case FP_2:
1039 switch (fpDecoding) {
1040 /******************************************************************
1041 * Floating-point/2 encoding - floating-point/1 decoding desired.
1042 ******************************************************************/
1043 case FP_1:
1044 if (negToPosFp0)
1045 *function = FP2toFP1doubleNEGtoPOS;
1046 else
1047 *function = Reverse8;
1048 break;
1049 /******************************************************************
1050 * Floating-point/2 encoding - floating-point/2 decoding desired.
1051 ******************************************************************/
1052 case FP_2:
1053 if (negToPosFp0)
1054 *function = FP2doubleNEGtoPOS;
1055 else
1056 *function = NULL;
1057 break;
1058 /******************************************************************
1059 * Floating-point/2 encoding - floating-point/3 decoding desired.
1060 ******************************************************************/
1061 case FP_3:
1062 if (negToPosFp0)
1063 *function = FP2toFP3doubleNEGtoPOS;
1064 else
1065 *function = FP2toFP3double;
1066 break;
1067 /******************************************************************
1068 * Floating-point/2 encoding - floating-point/4 decoding desired.
1069 ******************************************************************/
1070 case FP_4:
1071 if (negToPosFp0)
1072 *function = FP2toFP4doubleNEGtoPOS;
1073 else
1074 *function = FP2toFP4double;
1075 break;
1076 }
1077 break;
1078 /**********************************************************************
1079 * Floating-point/3 encoding.
1080 **********************************************************************/
1081 case FP_3:
1082 switch (fpDecoding) {
1083 /******************************************************************
1084 * Floating-point/3 encoding - floating-point/1 decoding desired.
1085 ******************************************************************/
1086 case FP_1:
1087 if (negToPosFp0)
1088 *function = FP3toFP1doubleNEGtoPOS;
1089 else
1090 *function = FP3toFP1double;
1091 break;
1092 /******************************************************************
1093 * Floating-point/3 encoding - floating-point/2 decoding desired.
1094 ******************************************************************/
1095 case FP_2:
1096 if (negToPosFp0)
1097 *function = FP3toFP2doubleNEGtoPOS;
1098 else
1099 *function = FP3toFP2double;
1100 break;
1101 /******************************************************************
1102 * Floating-point/3 encoding - floating-point/3 decoding desired.
1103 ******************************************************************/
1104 case FP_3:
1105 if (negToPosFp0)
1106 *function = FP3doubleNEGtoPOS;
1107 else
1108 #if LIMITfp3DOUBLEs
1109 *function = FP3doubleLIMIT;
1110 #else
1111 *function = NULL;
1112 #endif
1113 break;
1114 /******************************************************************
1115 * Floating-point/3 encoding - floating-point/4 decoding desired.
1116 ******************************************************************/
1117 case FP_4:
1118 if (negToPosFp0)
1119 *function = FP3toFP4doubleNEGtoPOS;
1120 else
1121 *function = FP3toFP4double;
1122 break;
1123 }
1124 break;
1125 /**********************************************************************
1126 * Floating-point/4 encoding.
1127 **********************************************************************/
1128 case FP_4:
1129 switch (fpDecoding) {
1130 /******************************************************************
1131 * Floating-point/4 encoding - floating-point/1 decoding desired.
1132 ******************************************************************/
1133 case FP_1:
1134 if (negToPosFp0)
1135 *function = FP4toFP1doubleNEGtoPOS;
1136 else
1137 *function = FP4toFP1double;
1138 break;
1139 /******************************************************************
1140 * Floating-point/4 encoding - floating-point/2 decoding desired.
1141 ******************************************************************/
1142 case FP_2:
1143 if (negToPosFp0)
1144 *function = FP4toFP2doubleNEGtoPOS;
1145 else
1146 *function = FP4toFP2double;
1147 break;
1148 /******************************************************************
1149 * Floating-point/4 encoding - floating-point/3 decoding desired.
1150 ******************************************************************/
1151 case FP_3:
1152 if (negToPosFp0)
1153 *function = FP4toFP3doubleNEGtoPOS;
1154 else
1155 *function = FP4toFP3double;
1156 break;
1157 /******************************************************************
1158 * Floating-point/4 encoding - floating-point/4 decoding desired.
1159 ******************************************************************/
1160 case FP_4:
1161 if (negToPosFp0)
1162 *function = FP4doubleNEGtoPOS;
1163 else
1164 *function = NULL;
1165 break;
1166 }
1167 break;
1168 }
1169 break;
1170 }
1171 /**************************************************************************
1172 * 2 8-byte floating-point values.
1173 **************************************************************************/
1174 case CDF_EPOCH16: {
1175 int fpEncoding = FpType (encoding);
1176 int fpDecoding = FpType (tDecoding);
1177 switch (fpEncoding) {
1178 /**********************************************************************
1179 * Floating-point/1 encoding.
1180 **********************************************************************/
1181 case FP_1:
1182 switch (fpDecoding) {
1183 /******************************************************************
1184 * Floating-point/1 encoding - floating-point/1 decoding desired.
1185 ******************************************************************/
1186 case FP_1:
1187 if (negToPosFp0)
1188 *function = FP1doubleNEGtoPOS;
1189 else
1190 *function = NULL;
1191 break;
1192 /******************************************************************
1193 * Floating-point/1 encoding - floating-point/2 decoding desired.
1194 ******************************************************************/
1195 case FP_2:
1196 if (negToPosFp0)
1197 *function = FP1toFP2doubleNEGtoPOS;
1198 else
1199 *function = Reverse16;
1200 break;
1201 /******************************************************************
1202 * Floating-point/1 encoding - floating-point/3 decoding desired.
1203 ******************************************************************/
1204 case FP_3:
1205 if (negToPosFp0)
1206 *function = FP1toFP3doubleNEGtoPOS;
1207 else
1208 *function = FP1toFP3double;
1209 break;
1210 /******************************************************************
1211 * Floating-point/1 encoding - floating-point/4 decoding desired.
1212 ******************************************************************/
1213 case FP_4:
1214 if (negToPosFp0)
1215 *function = FP1toFP4doubleNEGtoPOS;
1216 else
1217 *function = FP1toFP4double;
1218 break;
1219 }
1220 break;
1221 /**********************************************************************
1222 * Floating-point/2 encoding.
1223 **********************************************************************/
1224 case FP_2:
1225 switch (fpDecoding) {
1226 /******************************************************************
1227 * Floating-point/2 encoding - floating-point/1 decoding desired.
1228 ******************************************************************/
1229 case FP_1:
1230 if (negToPosFp0)
1231 *function = FP2toFP1doubleNEGtoPOS;
1232 else
1233 *function = Reverse16;
1234 break;
1235 /******************************************************************
1236 * Floating-point/2 encoding - floating-point/2 decoding desired.
1237 ******************************************************************/
1238 case FP_2:
1239 if (negToPosFp0)
1240 *function = FP2doubleNEGtoPOS;
1241 else
1242 *function = NULL;
1243 break;
1244 /******************************************************************
1245 * Floating-point/2 encoding - floating-point/3 decoding desired.
1246 ******************************************************************/
1247 case FP_3:
1248 if (negToPosFp0)
1249 *function = FP2toFP3doubleNEGtoPOS;
1250 else
1251 *function = FP2toFP3double;
1252 break;
1253 /******************************************************************
1254 * Floating-point/2 encoding - floating-point/4 decoding desired.
1255 ******************************************************************/
1256 case FP_4:
1257 if (negToPosFp0)
1258 *function = FP2toFP4doubleNEGtoPOS;
1259 else
1260 *function = FP2toFP4double;
1261 break;
1262 }
1263 break;
1264 /**********************************************************************
1265 * Floating-point/3 encoding.
1266 **********************************************************************/
1267 case FP_3:
1268 switch (fpDecoding) {
1269 /******************************************************************
1270 * Floating-point/3 encoding - floating-point/1 decoding desired.
1271 ******************************************************************/
1272 case FP_1:
1273 if (negToPosFp0)
1274 *function = FP3toFP1doubleNEGtoPOS;
1275 else
1276 *function = FP3toFP1double;
1277 break;
1278 /******************************************************************
1279 * Floating-point/3 encoding - floating-point/2 decoding desired.
1280 ******************************************************************/
1281 case FP_2:
1282 if (negToPosFp0)
1283 *function = FP3toFP2doubleNEGtoPOS;
1284 else
1285 *function = FP3toFP2double;
1286 break;
1287 /******************************************************************
1288 * Floating-point/3 encoding - floating-point/3 decoding desired.
1289 ******************************************************************/
1290 case FP_3:
1291 if (negToPosFp0)
1292 *function = FP3doubleNEGtoPOS;
1293 else
1294 #if LIMITfp3DOUBLEs
1295 *function = FP3doubleLIMIT;
1296 #else
1297 *function = NULL;
1298 #endif
1299 break;
1300 /******************************************************************
1301 * Floating-point/3 encoding - floating-point/4 decoding desired.
1302 ******************************************************************/
1303 case FP_4:
1304 if (negToPosFp0)
1305 *function = FP3toFP4doubleNEGtoPOS;
1306 else
1307 *function = FP3toFP4double;
1308 break;
1309 }
1310 break;
1311 /**********************************************************************
1312 * Floating-point/4 encoding.
1313 **********************************************************************/
1314 case FP_4:
1315 switch (fpDecoding) {
1316 /******************************************************************
1317 * Floating-point/4 encoding - floating-point/1 decoding desired.
1318 ******************************************************************/
1319 case FP_1:
1320 if (negToPosFp0)
1321 *function = FP4toFP1doubleNEGtoPOS;
1322 else
1323 *function = FP4toFP1double;
1324 break;
1325 /******************************************************************
1326 * Floating-point/4 encoding - floating-point/2 decoding desired.
1327 ******************************************************************/
1328 case FP_2:
1329 if (negToPosFp0)
1330 *function = FP4toFP2doubleNEGtoPOS;
1331 else
1332 *function = FP4toFP2double;
1333 break;
1334 /******************************************************************
1335 * Floating-point/4 encoding - floating-point/3 decoding desired.
1336 ******************************************************************/
1337 case FP_3:
1338 if (negToPosFp0)
1339 *function = FP4toFP3doubleNEGtoPOS;
1340 else
1341 *function = FP4toFP3double;
1342 break;
1343 /******************************************************************
1344 * Floating-point/4 encoding - floating-point/4 decoding desired.
1345 ******************************************************************/
1346 case FP_4:
1347 if (negToPosFp0)
1348 *function = FP4doubleNEGtoPOS;
1349 else
1350 *function = NULL;
1351 break;
1352 }
1353 break;
1354 }
1355 break;
1356 }
1357 /**************************************************************************
1358 * Unknown data type.
1359 **************************************************************************/
1360 default:
1361 return CDF_INTERNAL_ERROR;
1362 }
1363 return CDF_OK;
1364 }
1365
1366 /******************************************************************************
1367 * FP1toFP34single.
1368 * Floating-point/1 to floating-point/34, single-precision.
1369 ******************************************************************************/
1370
FP1toFP34single(buffer,numElems)1371 STATICforIDL CDFstatus FP1toFP34single (buffer, numElems)
1372 void *buffer;
1373 Int32 numElems;
1374 {
1375 uInt16 fp1e, fp34e;
1376 uInt32 fp1m, fp34m;
1377 struct fp1struct4 *fp1;
1378 struct fp34struct4 *fp34, Fp34;
1379 CDFstatus pStatus = CDF_OK;
1380 Int32 elemN;
1381 #if DYNAMICfpSTRUCTs
1382 struct fp34struct4 FP34zeroSingle = { FP34ZEROsingle };
1383 struct fp34struct4 FP34minSingle = { FP34MINsingle };
1384 struct fp34struct4 FP34maxSingle = { FP34MAXsingle };
1385 #endif
1386 for (elemN = 0,
1387 fp1 = (struct fp1struct4 *) buffer,
1388 fp34 = (struct fp34struct4 *) buffer;
1389 elemN < numElems;
1390 elemN++, fp1++, fp34++) {
1391 /*************************************************************************
1392 * Calculate FP1's exponent.
1393 *************************************************************************/
1394 fp1e = (fp1->e1 << 1) | fp1->e0;
1395 switch (fp1e) {
1396 /***********************************************************************
1397 * FP1 exponent of zero (0) - what to do depends on the FP1 mantissa.
1398 ***********************************************************************/
1399 case 0x0:
1400 fp1m = (fp1->m2 << 16) | (fp1->m1 << 8) | fp1->m0;
1401 /*********************************************************************
1402 * If the FP1 mantissa is zero (0), set FP34 to 0.0 and use the sign
1403 * from FP1. Also check for -0.0.
1404 *********************************************************************/
1405 if (fp1m == 0x0) {
1406 Fp34 = FP34zeroSingle;
1407 Fp34.s = fp1->s;
1408 if (Fp34.s == 0x1) pStatus = NEGATIVE_FP_ZERO;
1409 break;
1410 }
1411 /*********************************************************************
1412 * If the FP1 mantissa (with an FP1 exponent of zero [0]) puts the FP1
1413 * value below the smallest magnitude possible for FP34, set FP34 to
1414 * its minimum magnitude but with FP1's sign.
1415 *********************************************************************/
1416 if (fp1m < 0x200000) {
1417 Fp34 = FP34minSingle;
1418 Fp34.s = fp1->s;
1419 break;
1420 }
1421 /*********************************************************************
1422 * If the FP1 mantissa is in the range where it maps 1-to-4 to FP34
1423 * mantissas, set the FP34 mantissa to the first (lowest) value which
1424 * maps.
1425 *********************************************************************/
1426 if (fp1m < 0x400000) {
1427 fp34e = 0x1;
1428 Fp34.e1 = fp34e >> 1;
1429 Fp34.e0 = fp34e;
1430 fp34m = 4 * (fp1m - 0x200000);
1431 Fp34.m2 = (Byte) (fp34m >> 16);
1432 Fp34.m1 = (Byte) (fp34m >> 8);
1433 Fp34.m0 = (Byte) fp34m;
1434 Fp34.s = fp1->s;
1435 break;
1436 }
1437 /*********************************************************************
1438 * The FP1 mantissa is in the range where it maps 1-to-2 to FP34
1439 * mantissas, set the FP34 mantissa to the first (lowest) value which
1440 * maps.
1441 *********************************************************************/
1442 fp34e = 0x2;
1443 Fp34.e1 = fp34e >> 1;
1444 Fp34.e0 = fp34e;
1445 fp34m = 2 * (fp1m - 0x400000);
1446 Fp34.m2 = (Byte) (fp34m >> 16);
1447 Fp34.m1 = (Byte) (fp34m >> 8);
1448 Fp34.m0 = (Byte) fp34m;
1449 Fp34.s = fp1->s;
1450 break;
1451 /***********************************************************************
1452 * The FP1 exponent puts the FP1 value beyond the largest magnitude
1453 * possible for FP34 - set FP34 to its maximum magnitude but with FP1's
1454 * sign.
1455 ***********************************************************************/
1456 case 0xFE:
1457 case 0xFF:
1458 Fp34 = FP34maxSingle;
1459 Fp34.s = fp1->s;
1460 break;
1461 /***********************************************************************
1462 * The FP1 value will `fit' into FP34.
1463 ***********************************************************************/
1464 default:
1465 fp34e = fp1e + 2;
1466 Fp34.e1 = fp34e >> 1;
1467 Fp34.e0 = fp34e;
1468 Fp34.m2 = fp1->m2;
1469 Fp34.m1 = fp1->m1;
1470 Fp34.m0 = fp1->m0;
1471 Fp34.s = fp1->s;
1472 }
1473 *fp34 = Fp34;
1474 }
1475 return pStatus;
1476 }
1477
1478 /******************************************************************************
1479 * FP1toFP34singleNEGtoPOS.
1480 * Floating-point/1 to floating-point/34, single-precision. Convert -0.0
1481 * to 0.0.
1482 ******************************************************************************/
1483
FP1toFP34singleNEGtoPOS(buffer,numElems)1484 STATICforIDL CDFstatus FP1toFP34singleNEGtoPOS (buffer, numElems)
1485 void *buffer;
1486 Int32 numElems;
1487 {
1488 CDFstatus status = FP1toFP34single (buffer, numElems);
1489 if (status == NEGATIVE_FP_ZERO) FP34singleNEGtoPOS (buffer, numElems);
1490 return CDF_OK;
1491 }
1492
1493 /******************************************************************************
1494 * FP2toFP34single.
1495 * Floating-point/2 to floating-point/34, single-precision.
1496 * See FP1toFP34single for comments.
1497 ******************************************************************************/
1498
FP2toFP34single(buffer,numElems)1499 STATICforIDL CDFstatus FP2toFP34single (buffer, numElems)
1500 void *buffer;
1501 Int32 numElems;
1502 {
1503 uInt16 fp2e, fp34e;
1504 uInt32 fp2m, fp34m;
1505 struct fp2struct4 *fp2;
1506 struct fp34struct4 *fp34, Fp34;
1507 CDFstatus pStatus = CDF_OK;
1508 Int32 elemN;
1509 #if DYNAMICfpSTRUCTs
1510 struct fp34struct4 FP34zeroSingle = { FP34ZEROsingle };
1511 struct fp34struct4 FP34minSingle = { FP34MINsingle };
1512 struct fp34struct4 FP34maxSingle = { FP34MAXsingle };
1513 #endif
1514 for (elemN = 0,
1515 fp2 = (struct fp2struct4 *) buffer,
1516 fp34 = (struct fp34struct4 *) buffer;
1517 elemN < numElems;
1518 elemN++, fp2++, fp34++) {
1519 fp2e = (fp2->e1 << 1) | fp2->e0;
1520 switch (fp2e) {
1521 case 0x0:
1522 fp2m = (fp2->m2 << 16) | (fp2->m1 << 8) | fp2->m0;
1523 if (fp2m == 0x0) {
1524 Fp34 = FP34zeroSingle;
1525 Fp34.s = fp2->s;
1526 if (Fp34.s == 0x1) pStatus = NEGATIVE_FP_ZERO;
1527 break;
1528 }
1529 if (fp2m < 0x200000) {
1530 Fp34 = FP34minSingle;
1531 Fp34.s = fp2->s;
1532 break;
1533 }
1534 if (fp2m < 0x400000) {
1535 fp34e = 0x1;
1536 Fp34.e1 = fp34e >> 1;
1537 Fp34.e0 = fp34e;
1538 fp34m = 4 * (fp2m - 0x200000);
1539 Fp34.m2 = (Byte) (fp34m >> 16);
1540 Fp34.m1 = (Byte) (fp34m >> 8);
1541 Fp34.m0 = (Byte) fp34m;
1542 Fp34.s = fp2->s;
1543 break;
1544 }
1545 fp34e = 0x2;
1546 Fp34.e1 = fp34e >> 1;
1547 Fp34.e0 = fp34e;
1548 fp34m = 2 * (fp2m - 0x400000);
1549 Fp34.m2 = (Byte) (fp34m >> 16);
1550 Fp34.m1 = (Byte) (fp34m >> 8);
1551 Fp34.m0 = (Byte) fp34m;
1552 Fp34.s = fp2->s;
1553 break;
1554 case 0xFE:
1555 case 0xFF:
1556 Fp34 = FP34maxSingle;
1557 Fp34.s = fp2->s;
1558 break;
1559 default:
1560 fp34e = fp2e + 2;
1561 Fp34.e1 = fp34e >> 1;
1562 Fp34.e0 = fp34e;
1563 Fp34.m2 = fp2->m2;
1564 Fp34.m1 = fp2->m1;
1565 Fp34.m0 = fp2->m0;
1566 Fp34.s = fp2->s;
1567 }
1568 *fp34 = Fp34;
1569 }
1570 return pStatus;
1571 }
1572
1573 /******************************************************************************
1574 * FP2toFP34singleNEGtoPOS.
1575 * Floating-point/2 to floating-point/34, single-precision. Convert -0.0
1576 * to 0.0.
1577 ******************************************************************************/
1578
FP2toFP34singleNEGtoPOS(buffer,numElems)1579 STATICforIDL CDFstatus FP2toFP34singleNEGtoPOS (buffer, numElems)
1580 void *buffer;
1581 Int32 numElems;
1582 {
1583 CDFstatus status = FP2toFP34single (buffer, numElems);
1584 if (status == NEGATIVE_FP_ZERO) FP34singleNEGtoPOS (buffer, numElems);
1585 return CDF_OK;
1586 }
1587
1588 /******************************************************************************
1589 * FP34toFP1single.
1590 * Floating-point/34 to floating-point/1, single-precision.
1591 ******************************************************************************/
1592
FP34toFP1single(buffer,numElems)1593 STATICforIDL CDFstatus FP34toFP1single (buffer, numElems)
1594 void *buffer;
1595 Int32 numElems;
1596 {
1597 uInt16 fp34e, fp1e;
1598 uInt32 fp34m, fp1m;
1599 struct fp34struct4 *fp34;
1600 struct fp1struct4 *fp1, Fp1;
1601 Int32 elemN;
1602 #if DYNAMICfpSTRUCTs
1603 struct fp1struct4 FP1zeroSingle = { FP1ZEROsingle };
1604 #endif
1605 for (elemN = 0,
1606 fp34 = (struct fp34struct4 *) buffer,
1607 fp1 = (struct fp1struct4 *) buffer;
1608 elemN < numElems;
1609 elemN++, fp34++, fp1++) {
1610 /*************************************************************************
1611 * Calculate the FP34 exponent.
1612 *************************************************************************/
1613 fp34e = (fp34->e1 << 1) | fp34->e0;
1614 switch (fp34e) {
1615 /***********************************************************************
1616 * If the FP34 exponent is zero (0), the value is 0.0 regardless of the
1617 * FP34 mantissa. The FP34 sign shouldn't be set either since -0.0
1618 * isn't valid value on VAXes. But since it might be set (for whatever
1619 * reason), set FP1's sign to that of FP34.
1620 ***********************************************************************/
1621 case 0x0:
1622 Fp1 = FP1zeroSingle;
1623 Fp1.s = fp34->s;
1624 break;
1625 /***********************************************************************
1626 * FP34 exponents of one (1) or two (2) indicate values whose mantissas
1627 * are not the same between FP34 and FP1. For an FP34 exponent of one
1628 * (1), the FP1 exponent is zero (0) and the full range of FP34
1629 * mantissas (0x0 through 0x7FFFFF) maps into the smaller range of FP1
1630 * mantissas from 0x200000 to 0x3FFFFF (a 4-to-1 mapping which means
1631 * that only one out of four FP34 values in this range maps perfectly to
1632 * FP1). For an FP34 exponent of two (2), the FP1 exponent is zero (0)
1633 * and the full range of FP34 mantissas (0x0 through 0x7FFFFF) maps into
1634 * the smaller range of FP1 mantissas from 0x400000 to 0x7FFFFF (a
1635 * 2-to-1 mapping which means that only one out of two FP34 values in
1636 * this range maps perfectly to FP1).
1637 ***********************************************************************/
1638 case 0x1:
1639 case 0x2:
1640 fp34m = (fp34->m2 << 16) | (fp34->m1 << 8) | fp34->m0;
1641 if (fp34e == 0x1)
1642 fp1m = 0x200000 + (fp34m / 4);
1643 else
1644 fp1m = 0x400000 + (fp34m / 2);
1645 Fp1.m2 = (Byte) (fp1m >> 16);
1646 Fp1.m1 = (Byte) (fp1m >> 8);
1647 Fp1.m0 = (Byte) fp1m;
1648 Fp1.e1 = 0x0;
1649 Fp1.e0 = 0x0;
1650 Fp1.s = fp34->s;
1651 break;
1652 /***********************************************************************
1653 * All other FP34 exponents are for FP34 values that map perfectly to FP1
1654 * (the FP1 exponent is just two less than the FP34 exponent).
1655 ***********************************************************************/
1656 default:
1657 Fp1.m2 = fp34->m2;
1658 Fp1.m1 = fp34->m1;
1659 Fp1.m0 = fp34->m0;
1660 fp1e = fp34e - 2;
1661 Fp1.e1 = fp1e >> 1;
1662 Fp1.e0 = fp1e;
1663 Fp1.s = fp34->s;
1664 }
1665 *fp1 = Fp1;
1666 }
1667 return CDF_OK;
1668 }
1669
1670 /******************************************************************************
1671 * FP34toFP1singleNEGtoPOS.
1672 * Floating-point/34 to floating-point/1, single-precision. Convert -0.0
1673 * to 0.0.
1674 ******************************************************************************/
1675
FP34toFP1singleNEGtoPOS(buffer,numElems)1676 STATICforIDL CDFstatus FP34toFP1singleNEGtoPOS (buffer, numElems)
1677 void *buffer;
1678 Int32 numElems;
1679 {
1680 FP34toFP1single (buffer, numElems);
1681 FP1singleNEGtoPOS (buffer, numElems);
1682 return CDF_OK;
1683 }
1684
1685 /******************************************************************************
1686 * FP34toFP2single.
1687 * Floating-point/34 to floating-point/2, single-precision.
1688 * See FP34toFP1single for comments.
1689 ******************************************************************************/
1690
FP34toFP2single(buffer,numElems)1691 STATICforIDL CDFstatus FP34toFP2single (buffer, numElems)
1692 void *buffer;
1693 Int32 numElems;
1694 {
1695 uInt16 fp34e, fp2e;
1696 uInt32 fp34m, fp2m;
1697 struct fp34struct4 *fp34;
1698 struct fp2struct4 *fp2, Fp2;
1699 Int32 elemN;
1700 #if DYNAMICfpSTRUCTs
1701 struct fp2struct4 FP2zeroSingle = { FP2ZEROsingle };
1702 #endif
1703 for (elemN = 0,
1704 fp34 = (struct fp34struct4 *) buffer,
1705 fp2 = (struct fp2struct4 *) buffer;
1706 elemN < numElems;
1707 elemN++, fp34++, fp2++) {
1708 fp34e = (fp34->e1 << 1) | fp34->e0;
1709 switch (fp34e) {
1710 case 0x0:
1711 Fp2 = FP2zeroSingle;
1712 Fp2.s = fp34->s;
1713 break;
1714 case 0x1:
1715 case 0x2:
1716 fp34m = (fp34->m2 << 16) | (fp34->m1 << 8) | fp34->m0;
1717 if (fp34e == 0x1)
1718 fp2m = 0x200000 + (fp34m / 4);
1719 else
1720 fp2m = 0x400000 + (fp34m / 2);
1721 Fp2.m2 = (Byte) (fp2m >> 16);
1722 Fp2.m1 = (Byte) (fp2m >> 8);
1723 Fp2.m0 = (Byte) fp2m;
1724 Fp2.e1 = 0x0;
1725 Fp2.e0 = 0x0;
1726 Fp2.s = fp34->s;
1727 break;
1728 default:
1729 Fp2.m2 = fp34->m2;
1730 Fp2.m1 = fp34->m1;
1731 Fp2.m0 = fp34->m0;
1732 fp2e = fp34e - 2;
1733 Fp2.e1 = fp2e >> 1;
1734 Fp2.e0 = fp2e;
1735 Fp2.s = fp34->s;
1736 }
1737 *fp2 = Fp2;
1738 }
1739 return CDF_OK;
1740 }
1741
1742 /******************************************************************************
1743 * FP34toFP2singleNEGtoPOS.
1744 * Floating-point/34 to floating-point/2, single-precision. Convert -0.0
1745 * to 0.0.
1746 ******************************************************************************/
1747
FP34toFP2singleNEGtoPOS(buffer,numElems)1748 STATICforIDL CDFstatus FP34toFP2singleNEGtoPOS (buffer, numElems)
1749 void *buffer;
1750 Int32 numElems;
1751 {
1752 FP34toFP2single (buffer, numElems);
1753 FP2singleNEGtoPOS (buffer, numElems);
1754 return CDF_OK;
1755 }
1756
1757 /******************************************************************************
1758 * FP1toFP3double.
1759 * Floating-point/1 to floating-point/3, double-precision.
1760 ******************************************************************************/
1761
FP1toFP3double(buffer,numElems)1762 STATICforIDL CDFstatus FP1toFP3double (buffer, numElems)
1763 void *buffer;
1764 Int32 numElems;
1765 {
1766 uInt16 fp1e, fp3e;
1767 struct fp1struct8 *fp1;
1768 struct fp3struct8 *fp3, Fp3;
1769 Int32 elemN;
1770 CDFstatus pStatus = CDF_OK;
1771 #if DYNAMICfpSTRUCTs
1772 struct fp3struct8 FP3zeroDouble = { FP3ZEROdouble };
1773 struct fp3struct8 FP3minDouble = { FP3MINdouble };
1774 struct fp3struct8 FP3maxDouble = { FP3MAXdouble };
1775 #endif
1776 for (elemN = 0,
1777 fp1 = (struct fp1struct8 *) buffer,
1778 fp3 = (struct fp3struct8 *) buffer;
1779 elemN < numElems;
1780 elemN++, fp1++, fp3++) {
1781 /*************************************************************************
1782 * Calculate the FP1 exponent.
1783 *************************************************************************/
1784 fp1e = (fp1->e1 << 4) | fp1->e0;
1785 /*************************************************************************
1786 * Check if the FP1 exponent is too small for FP3 (but not 0.0). If so,
1787 * set the FP3 value to its smallest possible magnitude (but use FP1's
1788 * sign). Also check for -0.0.
1789 *************************************************************************/
1790 if (fp1e < 0x37F) {
1791 if (fp1e == 0x0 &&
1792 fp1->m0 == 0x0 && fp1->m1 == 0x0 && fp1->m2 == 0x0 &&
1793 fp1->m3 == 0x0 && fp1->m4 == 0x0 && fp1->m5 == 0x0 &&
1794 fp1->m6 == 0x0) {
1795 Fp3 = FP3zeroDouble;
1796 Fp3.s = fp1->s;
1797 if (Fp3.s == 0x1) pStatus = NEGATIVE_FP_ZERO;
1798 }
1799 else {
1800 Fp3 = FP3minDouble;
1801 Fp3.s = fp1->s;
1802 }
1803 *fp3 = Fp3;
1804 continue;
1805 }
1806 /*************************************************************************
1807 * Check if the FP1 exponent is too large for FP3. If so, set the FP3
1808 * value to its largest possible magnitude (but use FP1's sign).
1809 *************************************************************************/
1810 if (fp1e > 0x47D) {
1811 Fp3 = FP3maxDouble;
1812 Fp3.s = fp1->s;
1813 *fp3 = Fp3;
1814 continue;
1815 }
1816 /*************************************************************************
1817 * The FP1 value will `fit' but the three (extra) least significant bits of
1818 * the FP3 mantissa are set to zero when the FP1 mantissa is copied to the
1819 * FP3 mantissa.
1820 *************************************************************************/
1821 fp3e = fp1e - 0x37E;
1822 Fp3.e0 = fp3e;
1823 Fp3.e1 = fp3e >> 1;
1824 Fp3.m0 = fp1->m0 << 3;
1825 Fp3.m1 = (fp1->m1 << 3) | (fp1->m0 >> 5);
1826 Fp3.m2 = (fp1->m2 << 3) | (fp1->m1 >> 5);
1827 Fp3.m3 = (fp1->m3 << 3) | (fp1->m2 >> 5);
1828 Fp3.m4 = (fp1->m4 << 3) | (fp1->m3 >> 5);
1829 Fp3.m5 = (fp1->m5 << 3) | (fp1->m4 >> 5);
1830 Fp3.m6 = (fp1->m6 << 3) | (fp1->m5 >> 5);
1831 Fp3.s = fp1->s;
1832 *fp3 = Fp3;
1833 }
1834 #if LIMITfp3DOUBLEs
1835 /****************************************************************************
1836 * If this is a DEC Alpha (OpenVMS or POSIX Shell) built for a default of
1837 * D_FLOAT, check that the values do not exceed the maximum.
1838 ****************************************************************************/
1839 FP3doubleLIMIT (buffer, numElems);
1840 #endif
1841 return pStatus;
1842 }
1843
1844 /******************************************************************************
1845 * FP1toFP3doubleNEGtoPOS.
1846 * Floating-point/1 to floating-point/3, double-precision. Convert -0.0 to
1847 * 0.0.
1848 ******************************************************************************/
1849
FP1toFP3doubleNEGtoPOS(buffer,numElems)1850 STATICforIDL CDFstatus FP1toFP3doubleNEGtoPOS (buffer, numElems)
1851 void *buffer;
1852 Int32 numElems;
1853 {
1854 CDFstatus status = FP1toFP3double (buffer, numElems);
1855 if (status == NEGATIVE_FP_ZERO) FP3doubleNEGtoPOS (buffer, numElems);
1856 return CDF_OK;
1857 }
1858
1859 /******************************************************************************
1860 * FP1toFP4double.
1861 * Floating-point/1 to floating-point/4, double-precision.
1862 ******************************************************************************/
1863
FP1toFP4double(buffer,numElems)1864 STATICforIDL CDFstatus FP1toFP4double (buffer, numElems)
1865 void *buffer;
1866 Int32 numElems;
1867 {
1868 uInt16 fp1e, fp4e;
1869 uInt32 fp1mH, fp1mL, fp4mH, fp4mL;
1870 struct fp1struct8 *fp1;
1871 struct fp4struct8 *fp4, Fp4;
1872 CDFstatus pStatus = CDF_OK;
1873 Int32 elemN;
1874 #if DYNAMICfpSTRUCTs
1875 struct fp4struct8 FP4zeroDouble = { FP4ZEROdouble };
1876 struct fp4struct8 FP4minDouble = { FP4MINdouble };
1877 struct fp4struct8 FP4maxDouble = { FP4MAXdouble };
1878 #endif
1879 for (elemN = 0,
1880 fp1 = (struct fp1struct8 *) buffer,
1881 fp4 = (struct fp4struct8 *) buffer;
1882 elemN < numElems;
1883 elemN++, fp1++, fp4++) {
1884 /*************************************************************************
1885 * Calculate FP1's exponent.
1886 *************************************************************************/
1887 fp1e = (fp1->e1 << 4) | fp1->e0;
1888 switch (fp1e) {
1889 /***********************************************************************
1890 * FP1 exponent of zero (0) - what to do depends on the FP1 mantissa.
1891 ***********************************************************************/
1892 case 0x0:
1893 fp1mH = (fp1->m6 << 16) | (fp1->m5 << 8) | fp1->m4;
1894 fp1mL = (fp1->m3 << 24) | (fp1->m2 << 16) | (fp1->m1 << 8) | fp1->m0;
1895 /*********************************************************************
1896 * If the FP1 mantissa is zero (0), set FP34 to 0.0 and use the sign
1897 * from FP1. Also check for -0.0.
1898 *********************************************************************/
1899 if (fp1mH == 0x0 && fp1mL == 0x0) {
1900 Fp4 = FP4zeroDouble;
1901 Fp4.s = fp1->s;
1902 if (Fp4.s == 0x1) pStatus = NEGATIVE_FP_ZERO;
1903 break;
1904 }
1905 /*********************************************************************
1906 * If the FP1 mantissa (with an FP1 exponent of zero [0]) puts the FP1
1907 * value below the smallest magnitude possible for FP4, set FP4 to its
1908 * minimum magnitude but with FP1's sign.
1909 *********************************************************************/
1910 if (fp1mH < 0x40000) {
1911 Fp4 = FP4minDouble;
1912 Fp4.s = fp1->s;
1913 break;
1914 }
1915 /*********************************************************************
1916 * If the FP1 mantissa is in the range where it maps 1-to-4 to FP4
1917 * mantissas, set the FP4 mantissa to the first (lowest) value which
1918 * maps.
1919 *********************************************************************/
1920 if (fp1mH < 0x80000) {
1921 Fp4.e1 = 0x0;
1922 Fp4.e0 = 0x1;
1923 fp4mH = ((fp1mH - 0x40000) << 2) | (fp1mL >> 30);
1924 fp4mL = fp1mL << 2;
1925 Fp4.m6 = (Byte) (fp4mH >> 16);
1926 Fp4.m5 = (Byte) (fp4mH >> 8);
1927 Fp4.m4 = (Byte) (fp4mH);
1928 Fp4.m3 = (Byte) (fp4mL >> 24);
1929 Fp4.m2 = (Byte) (fp4mL >> 16);
1930 Fp4.m1 = (Byte) (fp4mL >> 8);
1931 Fp4.m0 = (Byte) (fp4mL);
1932 Fp4.s = fp1->s;
1933 break;
1934 }
1935 /*********************************************************************
1936 * The FP1 mantissa is in the range where it maps 1-to-2 to FP4
1937 * mantissas, set the FP4 mantissa to the first (lowest) value which
1938 * maps.
1939 *********************************************************************/
1940 Fp4.e1 = 0x0;
1941 Fp4.e0 = 0x2;
1942 fp4mH = ((fp1mH - 0x80000) << 1) | (fp1mL >> 31);
1943 fp4mL = fp1mL << 1;
1944 Fp4.m6 = (Byte) (fp4mH >> 16);
1945 Fp4.m5 = (Byte) (fp4mH >> 8);
1946 Fp4.m4 = (Byte) (fp4mH);
1947 Fp4.m3 = (Byte) (fp4mL >> 24);
1948 Fp4.m2 = (Byte) (fp4mL >> 16);
1949 Fp4.m1 = (Byte) (fp4mL >> 8);
1950 Fp4.m0 = (Byte) (fp4mL);
1951 Fp4.s = fp1->s;
1952 break;
1953 /***********************************************************************
1954 * The FP1 exponent puts the FP1 value beyond the largest magnitude
1955 * possible for FP4 - set FP4 to its maximum magnitude but with FP1's
1956 * sign.
1957 ***********************************************************************/
1958 case 0x7FE:
1959 case 0x7FF:
1960 Fp4 = FP4maxDouble;
1961 Fp4.s = fp1->s;
1962 break;
1963 /***********************************************************************
1964 * The FP1 value will `fit' into FP4.
1965 ***********************************************************************/
1966 default:
1967 fp4e = fp1e + 2;
1968 Fp4.e1 = fp4e >> 4;
1969 Fp4.e0 = fp4e;
1970 Fp4.m6 = fp1->m6;
1971 Fp4.m5 = fp1->m5;
1972 Fp4.m4 = fp1->m4;
1973 Fp4.m3 = fp1->m3;
1974 Fp4.m2 = fp1->m2;
1975 Fp4.m1 = fp1->m1;
1976 Fp4.m0 = fp1->m0;
1977 Fp4.s = fp1->s;
1978 }
1979 *fp4 = Fp4;
1980 }
1981 return pStatus;
1982 }
1983
1984 /******************************************************************************
1985 * FP1toFP4doubleNEGtoPOS.
1986 * Floating-point/1 to floating-point/4, double-precision. Convert -0.0 to
1987 * 0.0.
1988 ******************************************************************************/
1989
FP1toFP4doubleNEGtoPOS(buffer,numElems)1990 STATICforIDL CDFstatus FP1toFP4doubleNEGtoPOS (buffer, numElems)
1991 void *buffer;
1992 Int32 numElems;
1993 {
1994 CDFstatus status = FP1toFP4double (buffer, numElems);
1995 if (status == NEGATIVE_FP_ZERO) FP4doubleNEGtoPOS (buffer, numElems);
1996 return CDF_OK;
1997 }
1998
1999 /******************************************************************************
2000 * FP2toFP3double.
2001 * Floating-point/2 to floating-point/3, double-precision.
2002 * See FP1toFP3double for comments.
2003 ******************************************************************************/
2004
FP2toFP3double(buffer,numElems)2005 STATICforIDL CDFstatus FP2toFP3double (buffer, numElems)
2006 void *buffer;
2007 Int32 numElems;
2008 {
2009 uInt16 fp2e, fp3e;
2010 struct fp2struct8 *fp2;
2011 struct fp3struct8 *fp3, Fp3;
2012 Int32 elemN;
2013 CDFstatus pStatus = CDF_OK;
2014 #if DYNAMICfpSTRUCTs
2015 struct fp3struct8 FP3zeroDouble = { FP3ZEROdouble };
2016 struct fp3struct8 FP3minDouble = { FP3MINdouble };
2017 struct fp3struct8 FP3maxDouble = { FP3MAXdouble };
2018 #endif
2019 for (elemN = 0,
2020 fp2 = (struct fp2struct8 *) buffer,
2021 fp3 = (struct fp3struct8 *) buffer;
2022 elemN < numElems;
2023 elemN++, fp2++, fp3++) {
2024 fp2e = (fp2->e1 << 4) | fp2->e0;
2025 if (fp2e < 0x37F) {
2026 if (fp2e == 0x0 &&
2027 fp2->m0 == 0x0 && fp2->m1 == 0x0 && fp2->m2 == 0x0 &&
2028 fp2->m3 == 0x0 && fp2->m4 == 0x0 && fp2->m5 == 0x0 &&
2029 fp2->m6 == 0x0) {
2030 Fp3 = FP3zeroDouble;
2031 Fp3.s = fp2->s;
2032 if (Fp3.s == 0x1) pStatus = NEGATIVE_FP_ZERO;
2033 }
2034 else {
2035 Fp3 = FP3minDouble;
2036 Fp3.s = fp2->s;
2037 }
2038 *fp3 = Fp3;
2039 continue;
2040 }
2041 if (fp2e > 0x47D) {
2042 Fp3 = FP3maxDouble;
2043 Fp3.s = fp2->s;
2044 *fp3 = Fp3;
2045 continue;
2046 }
2047 fp3e = fp2e - 0x37E;
2048 Fp3.e0 = fp3e;
2049 Fp3.e1 = fp3e >> 1;
2050 Fp3.m0 = fp2->m0 << 3;
2051 Fp3.m1 = (fp2->m1 << 3) | (fp2->m0 >> 5);
2052 Fp3.m2 = (fp2->m2 << 3) | (fp2->m1 >> 5);
2053 Fp3.m3 = (fp2->m3 << 3) | (fp2->m2 >> 5);
2054 Fp3.m4 = (fp2->m4 << 3) | (fp2->m3 >> 5);
2055 Fp3.m5 = (fp2->m5 << 3) | (fp2->m4 >> 5);
2056 Fp3.m6 = (fp2->m6 << 3) | (fp2->m5 >> 5);
2057 Fp3.s = fp2->s;
2058 *fp3 = Fp3;
2059 }
2060 #if LIMITfp3DOUBLEs
2061 /****************************************************************************
2062 * If this is a DEC Alpha (OpenVMS or POSIX Shell) built for a default of
2063 * D_FLOAT, check that the values do not exceed the maximum.
2064 ****************************************************************************/
2065 FP3doubleLIMIT (buffer, numElems);
2066 #endif
2067 return pStatus;
2068 }
2069
2070 /******************************************************************************
2071 * FP2toFP3doubleNEGtoPOS.
2072 * Floating-point/2 to floating-point/3, double-precision. Convert -0.0 to
2073 * 0.0.
2074 ******************************************************************************/
2075
FP2toFP3doubleNEGtoPOS(buffer,numElems)2076 STATICforIDL CDFstatus FP2toFP3doubleNEGtoPOS (buffer, numElems)
2077 void *buffer;
2078 Int32 numElems;
2079 {
2080 CDFstatus status = FP2toFP3double (buffer, numElems);
2081 if (status == NEGATIVE_FP_ZERO) FP3doubleNEGtoPOS (buffer, numElems);
2082 return CDF_OK;
2083 }
2084
2085 /******************************************************************************
2086 * FP2toFP4double.
2087 * Floating-point/2 to floating-point/4, double-precision.
2088 * See FP1toFP4double for comments.
2089 ******************************************************************************/
2090
FP2toFP4double(buffer,numElems)2091 STATICforIDL CDFstatus FP2toFP4double (buffer, numElems)
2092 void *buffer;
2093 Int32 numElems;
2094 {
2095 uInt16 fp2e, fp4e;
2096 uInt32 fp2mH, fp2mL, fp4mH, fp4mL;
2097 struct fp2struct8 *fp2;
2098 struct fp4struct8 *fp4, Fp4;
2099 CDFstatus pStatus = CDF_OK;
2100 Int32 elemN;
2101 #if DYNAMICfpSTRUCTs
2102 struct fp4struct8 FP4zeroDouble = { FP4ZEROdouble };
2103 struct fp4struct8 FP4minDouble = { FP4MINdouble };
2104 struct fp4struct8 FP4maxDouble = { FP4MAXdouble };
2105 #endif
2106 for (elemN = 0,
2107 fp2 = (struct fp2struct8 *) buffer,
2108 fp4 = (struct fp4struct8 *) buffer;
2109 elemN < numElems;
2110 elemN++, fp2++, fp4++) {
2111 fp2e = (fp2->e1 << 4) | fp2->e0;
2112 switch (fp2e) {
2113 case 0x0:
2114 fp2mH = (fp2->m6 << 16) | (fp2->m5 << 8) | fp2->m4;
2115 fp2mL = (fp2->m3 << 24) | (fp2->m2 << 16) | (fp2->m1 << 8) | fp2->m0;
2116 if (fp2mH == 0x0 && fp2mL == 0x0) {
2117 Fp4 = FP4zeroDouble;
2118 Fp4.s = fp2->s;
2119 if (Fp4.s == 0x1) pStatus = NEGATIVE_FP_ZERO;
2120 break;
2121 }
2122 if (fp2mH < 0x40000) {
2123 Fp4 = FP4minDouble;
2124 Fp4.s = fp2->s;
2125 break;
2126 }
2127 if (fp2mH < 0x80000) {
2128 Fp4.e1 = 0x0;
2129 Fp4.e0 = 0x1;
2130 fp4mH = ((fp2mH - 0x40000) << 2) | (fp2mL >> 30);
2131 fp4mL = fp2mL << 2;
2132 Fp4.m6 = (Byte) (fp4mH >> 16);
2133 Fp4.m5 = (Byte) (fp4mH >> 8);
2134 Fp4.m4 = (Byte) (fp4mH);
2135 Fp4.m3 = (Byte) (fp4mL >> 24);
2136 Fp4.m2 = (Byte) (fp4mL >> 16);
2137 Fp4.m1 = (Byte) (fp4mL >> 8);
2138 Fp4.m0 = (Byte) (fp4mL);
2139 Fp4.s = fp2->s;
2140 break;
2141 }
2142 Fp4.e1 = 0x0;
2143 Fp4.e0 = 0x2;
2144 fp4mH = ((fp2mH - 0x80000) << 1) | (fp2mL >> 31);
2145 fp4mL = fp2mL << 1;
2146 Fp4.m6 = (Byte) (fp4mH >> 16);
2147 Fp4.m5 = (Byte) (fp4mH >> 8);
2148 Fp4.m4 = (Byte) (fp4mH);
2149 Fp4.m3 = (Byte) (fp4mL >> 24);
2150 Fp4.m2 = (Byte) (fp4mL >> 16);
2151 Fp4.m1 = (Byte) (fp4mL >> 8);
2152 Fp4.m0 = (Byte) (fp4mL);
2153 Fp4.s = fp2->s;
2154 break;
2155 case 0x7FE:
2156 case 0x7FF:
2157 Fp4 = FP4maxDouble;
2158 Fp4.s = fp2->s;
2159 break;
2160 default:
2161 fp4e = fp2e + 2;
2162 Fp4.e1 = fp4e >> 4;
2163 Fp4.e0 = fp4e;
2164 Fp4.m6 = fp2->m6;
2165 Fp4.m5 = fp2->m5;
2166 Fp4.m4 = fp2->m4;
2167 Fp4.m3 = fp2->m3;
2168 Fp4.m2 = fp2->m2;
2169 Fp4.m1 = fp2->m1;
2170 Fp4.m0 = fp2->m0;
2171 Fp4.s = fp2->s;
2172 }
2173 *fp4 = Fp4;
2174 }
2175 return pStatus;
2176 }
2177
2178 /******************************************************************************
2179 * FP2toFP4doubleNEGtoPOS.
2180 * Floating-point/1 to floating-point/4, double-precision. Convert -0.0 to
2181 * 0.0.
2182 ******************************************************************************/
2183
FP2toFP4doubleNEGtoPOS(buffer,numElems)2184 STATICforIDL CDFstatus FP2toFP4doubleNEGtoPOS (buffer, numElems)
2185 void *buffer;
2186 Int32 numElems;
2187 {
2188 CDFstatus status = FP2toFP4double (buffer, numElems);
2189 if (status == NEGATIVE_FP_ZERO) FP4doubleNEGtoPOS (buffer, numElems);
2190 return CDF_OK;
2191 }
2192
2193 /******************************************************************************
2194 * FP3toFP1double.
2195 * Floating-point/3 to floating-point/1, double-precision.
2196 ******************************************************************************/
2197
FP3toFP1double(buffer,numElems)2198 STATICforIDL CDFstatus FP3toFP1double (buffer, numElems)
2199 void *buffer;
2200 Int32 numElems;
2201 {
2202 uInt16 fp3e, fp1e;
2203 struct fp3struct8 *fp3;
2204 struct fp1struct8 *fp1, Fp1;
2205 Int32 elemN;
2206 #if DYNAMICfpSTRUCTs
2207 struct fp1struct8 FP1zeroDouble = { FP1ZEROdouble };
2208 #endif
2209 for (elemN = 0,
2210 fp3 = (struct fp3struct8 *) buffer,
2211 fp1 = (struct fp1struct8 *) buffer;
2212 elemN < numElems;
2213 elemN++, fp3++, fp1++) {
2214 /*************************************************************************
2215 * Calculate the FP3 exponent.
2216 *************************************************************************/
2217 fp3e = (fp3->e1 << 1) | fp3->e0;
2218 /*************************************************************************
2219 * If the FP3 exponent is zero (0), the FP3 value is 0.0 regardless of the
2220 * mantissa's value. The FP3 sign bit shouldn't be set either since -0.0
2221 * is not a valid value on VAXes. But since it might be set (for whatever
2222 * reason), set FP1's sign to that of FP3.
2223 * If the FP3 exponent is not zero (0), the FP1 exponent is just 0x37E more
2224 * than the FP3 exponent and the three (extra) least signification bits of
2225 * the FP3 mantissa are lost (truncated) when the FP3 mantissa is copied to
2226 * the FP1 mantissa.
2227 *************************************************************************/
2228 if (fp3e == 0x0) {
2229 Fp1 = FP1zeroDouble;
2230 Fp1.s = fp3->s;
2231 }
2232 else {
2233 fp1e = fp3e + 0x37E;
2234 Fp1.e0 = fp1e;
2235 Fp1.e1 = fp1e >> 4;
2236 Fp1.m0 = (fp3->m1 << 5) | (fp3->m0 >> 3);
2237 Fp1.m1 = (fp3->m2 << 5) | (fp3->m1 >> 3);
2238 Fp1.m2 = (fp3->m3 << 5) | (fp3->m2 >> 3);
2239 Fp1.m3 = (fp3->m4 << 5) | (fp3->m3 >> 3);
2240 Fp1.m4 = (fp3->m5 << 5) | (fp3->m4 >> 3);
2241 Fp1.m5 = (fp3->m6 << 5) | (fp3->m5 >> 3);
2242 Fp1.m6 = fp3->m6 >> 3;
2243 Fp1.s = fp3->s;
2244 }
2245 *fp1 = Fp1;
2246 }
2247 return CDF_OK;
2248 }
2249
2250 /******************************************************************************
2251 * FP3toFP1doubleNEGtoPOS.
2252 * Floating-point/3 to floating-point/1, double-precision. Convert -0.0 to
2253 * 0.0.
2254 ******************************************************************************/
2255
FP3toFP1doubleNEGtoPOS(buffer,numElems)2256 STATICforIDL CDFstatus FP3toFP1doubleNEGtoPOS (buffer, numElems)
2257 void *buffer;
2258 Int32 numElems;
2259 {
2260 FP3toFP1double (buffer, numElems);
2261 FP1doubleNEGtoPOS (buffer, numElems);
2262 return CDF_OK;
2263 }
2264
2265 /******************************************************************************
2266 * FP3toFP2double.
2267 * Floating-point/3 to floating-point/2, double-precision.
2268 * See FP3toFP1double for comments.
2269 ******************************************************************************/
2270
FP3toFP2double(buffer,numElems)2271 STATICforIDL CDFstatus FP3toFP2double (buffer, numElems)
2272 void *buffer;
2273 Int32 numElems;
2274 {
2275 uInt16 fp3e, fp2e;
2276 struct fp3struct8 *fp3;
2277 struct fp2struct8 *fp2, Fp2;
2278 Int32 elemN;
2279 #if DYNAMICfpSTRUCTs
2280 struct fp2struct8 FP2zeroDouble = { FP2ZEROdouble };
2281 #endif
2282 for (elemN = 0,
2283 fp3 = (struct fp3struct8 *) buffer,
2284 fp2 = (struct fp2struct8 *) buffer;
2285 elemN < numElems;
2286 elemN++, fp3++, fp2++) {
2287 fp3e = (fp3->e1 << 1) | fp3->e0;
2288 if (fp3e == 0x0) {
2289 Fp2 = FP2zeroDouble;
2290 Fp2.s = fp3->s;
2291 }
2292 else {
2293 fp2e = fp3e + 0x37E;
2294 Fp2.e0 = fp2e;
2295 Fp2.e1 = fp2e >> 4;
2296 Fp2.m0 = (fp3->m1 << 5) | (fp3->m0 >> 3);
2297 Fp2.m1 = (fp3->m2 << 5) | (fp3->m1 >> 3);
2298 Fp2.m2 = (fp3->m3 << 5) | (fp3->m2 >> 3);
2299 Fp2.m3 = (fp3->m4 << 5) | (fp3->m3 >> 3);
2300 Fp2.m4 = (fp3->m5 << 5) | (fp3->m4 >> 3);
2301 Fp2.m5 = (fp3->m6 << 5) | (fp3->m5 >> 3);
2302 Fp2.m6 = fp3->m6 >> 3;
2303 Fp2.s = fp3->s;
2304 }
2305 *fp2 = Fp2;
2306 }
2307 return CDF_OK;
2308 }
2309
2310 /******************************************************************************
2311 * FP3toFP2doubleNEGtoPOS.
2312 * Floating-point/3 to floating-point/2, double-precision. Convert -0.0 to
2313 * +0.0.
2314 ******************************************************************************/
2315
FP3toFP2doubleNEGtoPOS(buffer,numElems)2316 STATICforIDL CDFstatus FP3toFP2doubleNEGtoPOS (buffer, numElems)
2317 void *buffer;
2318 Int32 numElems;
2319 {
2320 FP3toFP2double (buffer, numElems);
2321 FP2doubleNEGtoPOS (buffer, numElems);
2322 return CDF_OK;
2323 }
2324
2325 /******************************************************************************
2326 * FP3toFP4double.
2327 * Floating-point/3 to floating-point/4, double-precision.
2328 ******************************************************************************/
2329
FP3toFP4double(buffer,numElems)2330 STATICforIDL CDFstatus FP3toFP4double (buffer, numElems)
2331 void *buffer;
2332 Int32 numElems;
2333 {
2334 uInt16 fp3e, fp4e;
2335 struct fp3struct8 *fp3;
2336 struct fp4struct8 *fp4, Fp4;
2337 Int32 elemN;
2338 CDFstatus pStatus = CDF_OK;
2339 #if DYNAMICfpSTRUCTs
2340 struct fp4struct8 FP4zeroDouble = { FP4ZEROdouble };
2341 #endif
2342 for (elemN = 0,
2343 fp3 = (struct fp3struct8 *) buffer,
2344 fp4 = (struct fp4struct8 *) buffer;
2345 elemN < numElems;
2346 elemN++, fp3++, fp4++) {
2347 /*************************************************************************
2348 * Calculate the FP3 exponent.
2349 *************************************************************************/
2350 fp3e = (fp3->e1 << 1) | fp3->e0;
2351 /*************************************************************************
2352 * If the FP3 exponent is zero (0), the FP3 value is 0.0 regardless of the
2353 * mantissa's value. The FP3 sign bit shouldn't be set either since -0.0
2354 * is not a valid value on VAXes or DEC Alphas. But since it might be set
2355 * (for whatever reason), set FP4's sign to that of FP3 [and check for
2356 * -0.0].
2357 * If the FP3 exponent is not zero (0), the FP4 exponent is just 0x380 more
2358 * than the FP3 exponent and the three (extra) least signification bits of
2359 * the FP3 mantissa are lost (truncated) when the FP3 mantissa is copied to
2360 * the FP4 mantissa.
2361 *************************************************************************/
2362 if (fp3e == 0x0) {
2363 Fp4 = FP4zeroDouble;
2364 Fp4.s = fp3->s;
2365 if (Fp4.s == 0x1) pStatus = NEGATIVE_FP_ZERO;
2366 }
2367 else {
2368 fp4e = fp3e + 0x380;
2369 Fp4.e0 = fp4e;
2370 Fp4.e1 = fp4e >> 4;
2371 Fp4.m0 = (fp3->m1 << 5) | (fp3->m0 >> 3);
2372 Fp4.m1 = (fp3->m2 << 5) | (fp3->m1 >> 3);
2373 Fp4.m2 = (fp3->m3 << 5) | (fp3->m2 >> 3);
2374 Fp4.m3 = (fp3->m4 << 5) | (fp3->m3 >> 3);
2375 Fp4.m4 = (fp3->m5 << 5) | (fp3->m4 >> 3);
2376 Fp4.m5 = (fp3->m6 << 5) | (fp3->m5 >> 3);
2377 Fp4.m6 = fp3->m6 >> 3;
2378 Fp4.s = fp3->s;
2379 }
2380 *fp4 = Fp4;
2381 }
2382 return pStatus;
2383 }
2384
2385 /******************************************************************************
2386 * FP3toFP4doubleNEGtoPOS.
2387 * Floating-point/3 to floating-point/4, double-precision. Convert -0.0 to
2388 * 0.0.
2389 ******************************************************************************/
2390
FP3toFP4doubleNEGtoPOS(buffer,numElems)2391 STATICforIDL CDFstatus FP3toFP4doubleNEGtoPOS (buffer, numElems)
2392 void *buffer;
2393 Int32 numElems;
2394 {
2395 CDFstatus status = FP3toFP4double (buffer, numElems);
2396 if (status == NEGATIVE_FP_ZERO) FP4doubleNEGtoPOS (buffer, numElems);
2397 return CDF_OK;
2398 }
2399
2400 /******************************************************************************
2401 * FP4toFP1double.
2402 * Floating-point/4 to floating-point/1, double-precision.
2403 ******************************************************************************/
2404
FP4toFP1double(buffer,numElems)2405 STATICforIDL CDFstatus FP4toFP1double (buffer, numElems)
2406 void *buffer;
2407 Int32 numElems;
2408 {
2409 uInt16 fp4e, fp1e;
2410 uInt32 fp4mH, fp4mL, fp1mH, fp1mL;
2411 struct fp4struct8 *fp4;
2412 struct fp1struct8 *fp1, Fp1;
2413 Int32 elemN;
2414 #if DYNAMICfpSTRUCTs
2415 struct fp1struct8 FP1zeroDouble = { FP1ZEROdouble };
2416 #endif
2417 for (elemN = 0,
2418 fp4 = (struct fp4struct8 *) buffer,
2419 fp1 = (struct fp1struct8 *) buffer;
2420 elemN < numElems;
2421 elemN++, fp4++, fp1++) {
2422 /*************************************************************************
2423 * Calculate the FP4 exponent.
2424 *************************************************************************/
2425 fp4e = (fp4->e1 << 4) | fp4->e0;
2426 switch (fp4e) {
2427 /***********************************************************************
2428 * If the FP4 exponent is zero (0), the value is assumed to be 0.0
2429 * regardless of the FP4 mantissa (non-zero mantissas are illegal on
2430 * DEC Alphas). The FP4 sign shouldn't be set either since -0.0 isn't
2431 * valid value on DEC Alphas. But since it might be set (for whatever
2432 * reason), set FP1's sign to that of FP4.
2433 ***********************************************************************/
2434 case 0x0:
2435 Fp1 = FP1zeroDouble;
2436 Fp1.s = fp4->s;
2437 break;
2438 /***********************************************************************
2439 * FP4 exponents of one (1) or two (2) indicate values whose mantissas
2440 * are not the same between FP4 and FP1. For an FP4 exponent of one
2441 * (1), the FP1 exponent is zero (0) and the full range of FP4
2442 * mantissas (0x0 through 0xFFFFFFFFFFFFF) maps into the smaller range
2443 * of FP1 mantissas from 0x4000000000000 to 0x7FFFFFFFFFFFF (a 4-to-1
2444 * mapping which means that only one out of four FP4 values in this
2445 * range maps perfectly to FP1). For an FP4 exponent of two (2), the
2446 * FP1 exponent is zero (0) and the full range of FP4 mantissas (0x0
2447 * through 0xFFFFFFFFFFFFF) maps into the smaller range of FP1 mantissas
2448 * from 0x8000000000000 to 0xFFFFFFFFFFFFF (a 2-to-1 mapping which means
2449 * that only one out of two FP4 values in this range maps perfectly to
2450 * FP1).
2451 ***********************************************************************/
2452 case 0x1:
2453 case 0x2:
2454 fp4mH = (fp4->m6 << 16) | (fp4->m5 << 8) | fp4->m4;
2455 fp4mL = (fp4->m3 << 24) | (fp4->m2 << 16) | (fp4->m1 << 8) | fp4->m0;
2456 if (fp4e == 0x1) {
2457 fp1mH = 0x40000 + (fp4mH >> 2);
2458 fp1mL = (fp4mH << 30) | (fp4mL >> 2);
2459 }
2460 else {
2461 fp1mH = 0x80000 + (fp4mH >> 1);
2462 fp1mL = (fp4mH << 31) | (fp4mL >> 1);
2463 }
2464 Fp1.m6 = (Byte) (fp1mH >> 16);
2465 Fp1.m5 = (Byte) (fp1mH >> 8);
2466 Fp1.m4 = (Byte) (fp1mH);
2467 Fp1.m3 = (Byte) (fp1mL >> 24);
2468 Fp1.m2 = (Byte) (fp1mL >> 16);
2469 Fp1.m1 = (Byte) (fp1mL >> 8);
2470 Fp1.m0 = (Byte) (fp1mL);
2471 Fp1.e1 = 0x0;
2472 Fp1.e0 = 0x0;
2473 Fp1.s = fp4->s;
2474 break;
2475 /***********************************************************************
2476 * All other FP4 exponents are for FP4 values that map perfectly to FP1
2477 * (the FP1 exponent is just two less than the FP4 exponent).
2478 ***********************************************************************/
2479 default:
2480 Fp1.m6 = fp4->m6;
2481 Fp1.m5 = fp4->m5;
2482 Fp1.m4 = fp4->m4;
2483 Fp1.m3 = fp4->m3;
2484 Fp1.m2 = fp4->m2;
2485 Fp1.m1 = fp4->m1;
2486 Fp1.m0 = fp4->m0;
2487 fp1e = fp4e - 2;
2488 Fp1.e1 = fp1e >> 4;
2489 Fp1.e0 = fp1e;
2490 Fp1.s = fp4->s;
2491 }
2492 *fp1 = Fp1;
2493 }
2494 return CDF_OK;
2495 }
2496
2497 /******************************************************************************
2498 * FP4toFP1doubleNEGtoPOS.
2499 * Floating-point/4 to floating-point/1, double-precision. Convert -0.0 to
2500 * 0.0.
2501 ******************************************************************************/
2502
FP4toFP1doubleNEGtoPOS(buffer,numElems)2503 STATICforIDL CDFstatus FP4toFP1doubleNEGtoPOS (buffer, numElems)
2504 void *buffer;
2505 Int32 numElems;
2506 {
2507 FP4toFP1double (buffer, numElems);
2508 FP1doubleNEGtoPOS (buffer, numElems);
2509 return CDF_OK;
2510 }
2511
2512 /******************************************************************************
2513 * FP4toFP2double.
2514 * Floating-point/4 to floating-point/1, double-precision.
2515 * See FP4toFP1double for comments.
2516 ******************************************************************************/
2517
FP4toFP2double(buffer,numElems)2518 STATICforIDL CDFstatus FP4toFP2double (buffer, numElems)
2519 void *buffer;
2520 Int32 numElems;
2521 {
2522 uInt16 fp4e, fp2e;
2523 uInt32 fp4mH, fp4mL, fp2mH, fp2mL;
2524 struct fp4struct8 *fp4;
2525 struct fp2struct8 *fp2, Fp2;
2526 Int32 elemN;
2527 #if DYNAMICfpSTRUCTs
2528 struct fp2struct8 FP2zeroDouble = { FP2ZEROdouble };
2529 #endif
2530 for (elemN = 0,
2531 fp4 = (struct fp4struct8 *) buffer,
2532 fp2 = (struct fp2struct8 *) buffer;
2533 elemN < numElems;
2534 elemN++, fp4++, fp2++) {
2535 fp4e = (fp4->e1 << 4) | fp4->e0;
2536 switch (fp4e) {
2537 case 0x0:
2538 Fp2 = FP2zeroDouble;
2539 Fp2.s = fp4->s;
2540 break;
2541 case 0x1:
2542 case 0x2:
2543 fp4mH = (fp4->m6 << 16) | (fp4->m5 << 8) | fp4->m4;
2544 fp4mL = (fp4->m3 << 24) | (fp4->m2 << 16) | (fp4->m1 << 8) | fp4->m0;
2545 if (fp4e == 0x1) {
2546 fp2mH = 0x40000 + (fp4mH >> 2);
2547 fp2mL = (fp4mH << 30) | (fp4mL >> 2);
2548 }
2549 else {
2550 fp2mH = 0x80000 + (fp4mH >> 1);
2551 fp2mL = (fp4mH << 31) | (fp4mL >> 1);
2552 }
2553 Fp2.m6 = (Byte) (fp2mH >> 16);
2554 Fp2.m5 = (Byte) (fp2mH >> 8);
2555 Fp2.m4 = (Byte) (fp2mH);
2556 Fp2.m3 = (Byte) (fp2mL >> 24);
2557 Fp2.m2 = (Byte) (fp2mL >> 16);
2558 Fp2.m1 = (Byte) (fp2mL >> 8);
2559 Fp2.m0 = (Byte) (fp2mL);
2560 Fp2.e1 = 0x0;
2561 Fp2.e0 = 0x0;
2562 Fp2.s = fp4->s;
2563 break;
2564 default:
2565 Fp2.m6 = fp4->m6;
2566 Fp2.m5 = fp4->m5;
2567 Fp2.m4 = fp4->m4;
2568 Fp2.m3 = fp4->m3;
2569 Fp2.m2 = fp4->m2;
2570 Fp2.m1 = fp4->m1;
2571 Fp2.m0 = fp4->m0;
2572 fp2e = fp4e - 2;
2573 Fp2.e1 = fp2e >> 4;
2574 Fp2.e0 = fp2e;
2575 Fp2.s = fp4->s;
2576 }
2577 *fp2 = Fp2;
2578 }
2579 return CDF_OK;
2580 }
2581
2582 /******************************************************************************
2583 * FP4toFP2doubleNEGtoPOS.
2584 * Floating-point/4 to floating-point/2, double-precision. Convert -0.0 to
2585 * 0.0.
2586 ******************************************************************************/
2587
FP4toFP2doubleNEGtoPOS(buffer,numElems)2588 STATICforIDL CDFstatus FP4toFP2doubleNEGtoPOS (buffer, numElems)
2589 void *buffer;
2590 Int32 numElems;
2591 {
2592 FP4toFP2double (buffer, numElems);
2593 FP2doubleNEGtoPOS (buffer, numElems);
2594 return CDF_OK;
2595 }
2596
2597 /******************************************************************************
2598 * FP4toFP3double.
2599 * Floating-point/4 to floating-point/3, double-precision.
2600 ******************************************************************************/
2601
FP4toFP3double(buffer,numElems)2602 STATICforIDL CDFstatus FP4toFP3double (buffer, numElems)
2603 void *buffer;
2604 Int32 numElems;
2605 {
2606 uInt16 fp4e, fp3e;
2607 struct fp4struct8 *fp4;
2608 struct fp3struct8 *fp3, Fp3;
2609 Int32 elemN;
2610 CDFstatus pStatus = CDF_OK;
2611 #if DYNAMICfpSTRUCTs
2612 struct fp3struct8 FP3zeroDouble = { FP3ZEROdouble };
2613 struct fp3struct8 FP3minDouble = { FP3MINdouble };
2614 struct fp3struct8 FP3maxDouble = { FP3MAXdouble };
2615 #endif
2616 for (elemN = 0,
2617 fp4 = (struct fp4struct8 *) buffer,
2618 fp3 = (struct fp3struct8 *) buffer;
2619 elemN < numElems;
2620 elemN++, fp4++, fp3++) {
2621 /*************************************************************************
2622 * Calculate the FP4 exponent.
2623 *************************************************************************/
2624 fp4e = (fp4->e1 << 4) | fp4->e0;
2625 /*************************************************************************
2626 * Check if the FP4 exponent is too small for FP3 (but not 0.0). If so,
2627 * set the FP3 value to its smallest possible magnitude (but use FP4's
2628 * sign). Also check for -0.0.
2629 *************************************************************************/
2630 if (fp4e < 0x381) {
2631 if (fp4e == 0x0) {
2632 Fp3 = FP3zeroDouble;
2633 Fp3.s = fp4->s;
2634 if (Fp3.s == 0x1) pStatus = NEGATIVE_FP_ZERO;
2635 }
2636 else {
2637 Fp3 = FP3minDouble;
2638 Fp3.s = fp4->s;
2639 }
2640 *fp3 = Fp3;
2641 continue;
2642 }
2643 /*************************************************************************
2644 * Check if the FP4 exponent is too large for FP3. If so, set the FP3
2645 * value to its largest possible magnitude (but use FP4's sign).
2646 *************************************************************************/
2647 if (fp4e > 0x47F) {
2648 Fp3 = FP3maxDouble;
2649 Fp3.s = fp4->s;
2650 *fp3 = Fp3;
2651 continue;
2652 }
2653 /*************************************************************************
2654 * The FP4 value will `fit' but the three (extra) least significant bits
2655 * of the FP3 mantissa are set to zero when the FP4 mantissa is copied to
2656 * the FP3 mantissa.
2657 *************************************************************************/
2658 fp3e = fp4e - 0x380;
2659 Fp3.e0 = fp3e;
2660 Fp3.e1 = fp3e >> 1;
2661 Fp3.m0 = fp4->m0 << 3;
2662 Fp3.m1 = (fp4->m1 << 3) | (fp4->m0 >> 5);
2663 Fp3.m2 = (fp4->m2 << 3) | (fp4->m1 >> 5);
2664 Fp3.m3 = (fp4->m3 << 3) | (fp4->m2 >> 5);
2665 Fp3.m4 = (fp4->m4 << 3) | (fp4->m3 >> 5);
2666 Fp3.m5 = (fp4->m5 << 3) | (fp4->m4 >> 5);
2667 Fp3.m6 = (fp4->m6 << 3) | (fp4->m5 >> 5);
2668 Fp3.s = fp4->s;
2669 *fp3 = Fp3;
2670 }
2671 #if LIMITfp3DOUBLEs
2672 /****************************************************************************
2673 * If this is a DEC Alpha (OpenVMS or POSIX Shell) built for a default of
2674 * D_FLOAT, check that the values do not exceed the maximum.
2675 ****************************************************************************/
2676 FP3doubleLIMIT (buffer, numElems);
2677 #endif
2678 return pStatus;
2679 }
2680
2681 /******************************************************************************
2682 * FP4toFP3doubleNEGtoPOS.
2683 * Floating-point/4 to floating-point/3, double-precision. Convert -0.0 to
2684 * 0.0.
2685 ******************************************************************************/
2686
FP4toFP3doubleNEGtoPOS(buffer,numElems)2687 STATICforIDL CDFstatus FP4toFP3doubleNEGtoPOS (buffer, numElems)
2688 void *buffer;
2689 Int32 numElems;
2690 {
2691 CDFstatus status = FP4toFP3double (buffer, numElems);
2692 if (status == NEGATIVE_FP_ZERO) FP3doubleNEGtoPOS (buffer, numElems);
2693 return CDF_OK;
2694 }
2695
2696 /******************************************************************************
2697 * FP1toFP2singleNEGtoPOS.
2698 * Floating-point/1 to floating-point/2, single-precision. Convert -0.0 to
2699 * 0.0.
2700 ******************************************************************************/
2701
FP1toFP2singleNEGtoPOS(buffer,numElems)2702 STATICforIDL CDFstatus FP1toFP2singleNEGtoPOS (buffer, numElems)
2703 void *buffer;
2704 Int32 numElems;
2705 {
2706 Byte *ptr; Int32 elemN;
2707 for (elemN = 0, ptr = (Byte *) buffer;
2708 elemN < numElems; elemN++, ptr += 4) {
2709 REVERSE4b (ptr)
2710 }
2711 FP2singleNEGtoPOS (buffer, numElems);
2712 return CDF_OK;
2713 }
2714
2715 /******************************************************************************
2716 * FP2toFP1singleNEGtoPOS.
2717 * Floating-point/2 to floating-point/1, single-precision. Convert -0.0 to
2718 * 0.0.
2719 ******************************************************************************/
2720
FP2toFP1singleNEGtoPOS(buffer,numElems)2721 STATICforIDL CDFstatus FP2toFP1singleNEGtoPOS (buffer, numElems)
2722 void *buffer;
2723 Int32 numElems;
2724 {
2725 Byte *ptr; Int32 elemN;
2726 for (elemN = 0, ptr = (Byte *) buffer;
2727 elemN < numElems; elemN++, ptr += 4) {
2728 REVERSE4b (ptr)
2729 }
2730 FP1singleNEGtoPOS (buffer, numElems);
2731 return CDF_OK;
2732 }
2733
2734 /******************************************************************************
2735 * FP1toFP2doubleNEGtoPOS.
2736 * Floating-point/1 to floating-point/2, single-precision. Convert -0.0 to
2737 * 0.0.
2738 ******************************************************************************/
2739
FP1toFP2doubleNEGtoPOS(buffer,numElems)2740 STATICforIDL CDFstatus FP1toFP2doubleNEGtoPOS (buffer, numElems)
2741 void *buffer;
2742 Int32 numElems;
2743 {
2744 Byte *ptr; Int32 elemN;
2745 for (elemN = 0, ptr = (Byte *) buffer;
2746 elemN < numElems; elemN++, ptr += 8) {
2747 REVERSE8b (ptr)
2748 }
2749 FP2doubleNEGtoPOS (buffer, numElems);
2750 return CDF_OK;
2751 }
2752
2753 /******************************************************************************
2754 * FP2toFP1doubleNEGtoPOS.
2755 * Floating-point/2 to floating-point/1, single-precision. Convert -0.0 to
2756 * 0.0.
2757 ******************************************************************************/
2758
FP2toFP1doubleNEGtoPOS(buffer,numElems)2759 STATICforIDL CDFstatus FP2toFP1doubleNEGtoPOS (buffer, numElems)
2760 void *buffer;
2761 Int32 numElems;
2762 {
2763 Byte *ptr; Int32 elemN;
2764 for (elemN = 0, ptr = (Byte *) buffer;
2765 elemN < numElems; elemN++, ptr += 8) {
2766 REVERSE8b (ptr)
2767 }
2768 FP1doubleNEGtoPOS (buffer, numElems);
2769 return CDF_OK;
2770 }
2771
2772 /******************************************************************************
2773 * FP1singleNEGtoPOS.
2774 * Convert -0.0 to 0.0 for floating-point/1 single-precision.
2775 ******************************************************************************/
2776
FP1singleNEGtoPOS(buffer,numElems)2777 STATICforIDL CDFstatus FP1singleNEGtoPOS (buffer, numElems)
2778 void *buffer;
2779 Int32 numElems;
2780 {
2781 Byte *ptr;
2782 Int32 elemN;
2783 #if DYNAMICfpSTRUCTs
2784 struct fp1struct4 FP1zeroSingle = { FP1ZEROsingle };
2785 struct fp1struct4 FP1zeroSingleNeg = { FP1ZEROsingleNEG };
2786 #endif
2787 for (elemN = 0, ptr = (Byte *) buffer; elemN < numElems; elemN++, ptr += 4) {
2788 if (*((uInt32 *) ptr) == *((uInt32 *) &FP1zeroSingleNeg)) {
2789 *((struct fp1struct4 *) ptr) = FP1zeroSingle;
2790 }
2791 }
2792 return CDF_OK;
2793 }
2794
2795 /******************************************************************************
2796 * FP2singleNEGtoPOS.
2797 * Convert -0.0 to 0.0 for floating-point/2 single-precision.
2798 ******************************************************************************/
2799
FP2singleNEGtoPOS(buffer,numElems)2800 STATICforIDL CDFstatus FP2singleNEGtoPOS (buffer, numElems)
2801 void *buffer;
2802 Int32 numElems;
2803 {
2804 Byte *ptr;
2805 Int32 elemN;
2806 #if DYNAMICfpSTRUCTs
2807 struct fp2struct4 FP2zeroSingle = { FP2ZEROsingle };
2808 struct fp2struct4 FP2zeroSingleNeg = { FP2ZEROsingleNEG };
2809 #endif
2810 for (elemN = 0, ptr = (Byte *) buffer; elemN < numElems; elemN++, ptr += 4) {
2811 if (*((uInt32 *) ptr) == *((uInt32 *) &FP2zeroSingleNeg)) {
2812 *((struct fp2struct4 *) ptr) = FP2zeroSingle;
2813 }
2814 }
2815 return CDF_OK;
2816 }
2817
2818 /******************************************************************************
2819 * FP34singleNEGtoPOS.
2820 * Convert -0.0 to 0.0 for floating-point/34 single-precision.
2821 ******************************************************************************/
2822
FP34singleNEGtoPOS(buffer,numElems)2823 STATICforIDL CDFstatus FP34singleNEGtoPOS (buffer, numElems)
2824 void *buffer;
2825 Int32 numElems;
2826 {
2827 struct fp34struct4 *fp34;
2828 Int32 elemN;
2829 #if DYNAMICfpSTRUCTs
2830 struct fp34struct4 FP34zeroSingle = { FP34ZEROsingle };
2831 #endif
2832 for (elemN = 0, fp34 = (struct fp34struct4 *) buffer;
2833 elemN < numElems; elemN++, fp34++) {
2834 if (fp34->e1 == 0x0 && fp34->e0 == 0x0 && fp34->s == 0x1) {
2835 *fp34 = FP34zeroSingle;
2836 }
2837 }
2838 return CDF_OK;
2839 }
2840
2841 /******************************************************************************
2842 * FP1doubleNEGtoPOS.
2843 * Convert -0.0 to 0.0 for floating-point/1 double-precision.
2844 ******************************************************************************/
2845
FP1doubleNEGtoPOS(buffer,numElems)2846 STATICforIDL CDFstatus FP1doubleNEGtoPOS (buffer, numElems)
2847 void *buffer;
2848 Int32 numElems;
2849 {
2850 Byte *ptr;
2851 Int32 elemN;
2852 #if DYNAMICfpSTRUCTs
2853 struct fp1struct8 FP1zeroDouble = { FP1ZEROdouble };
2854 struct fp1struct8 FP1zeroDoubleNeg = { FP1ZEROdoubleNEG };
2855 #endif
2856 for (elemN = 0, ptr = (Byte *) buffer; elemN < numElems; elemN++, ptr += 8) {
2857 if (*((uInt32 *) ptr) == *((uInt32 *) &FP1zeroDoubleNeg) &&
2858 *((uInt32 *) ptr + 1) == *((uInt32 *) &FP1zeroDoubleNeg + 1)) {
2859 *((struct fp1struct8 *) ptr) = FP1zeroDouble;
2860 }
2861 }
2862 return CDF_OK;
2863 }
2864
2865 /******************************************************************************
2866 * FP2doubleNEGtoPOS.
2867 * Convert -0.0 to 0.0 for floating-point/2 double-precision.
2868 ******************************************************************************/
2869
FP2doubleNEGtoPOS(buffer,numElems)2870 STATICforIDL CDFstatus FP2doubleNEGtoPOS (buffer, numElems)
2871 void *buffer;
2872 Int32 numElems;
2873 {
2874 Byte *ptr;
2875 Int32 elemN;
2876 #if DYNAMICfpSTRUCTs
2877 struct fp2struct8 FP2zeroDouble = { FP2ZEROdouble };
2878 struct fp2struct8 FP2zeroDoubleNeg = { FP2ZEROdoubleNEG };
2879 #endif
2880 for (elemN = 0, ptr = (Byte *) buffer; elemN < numElems; elemN++, ptr += 8) {
2881 if (*((uInt32 *) ptr) == *((uInt32 *) &FP2zeroDoubleNeg) &&
2882 *((uInt32 *) ptr + 1) == *((uInt32 *) &FP2zeroDoubleNeg + 1)) {
2883 *((struct fp2struct8 *) ptr) = FP2zeroDouble;
2884 }
2885 }
2886 return CDF_OK;
2887 }
2888
2889 /******************************************************************************
2890 * FP3doubleNEGtoPOS.
2891 * Convert -0.0 to 0.0 for floating-point/3 double-precision.
2892 ******************************************************************************/
2893
FP3doubleNEGtoPOS(buffer,numElems)2894 STATICforIDL CDFstatus FP3doubleNEGtoPOS (buffer, numElems)
2895 void *buffer;
2896 Int32 numElems;
2897 {
2898 struct fp3struct8 *fp3;
2899 Int32 elemN;
2900 #if DYNAMICfpSTRUCTs
2901 struct fp3struct8 FP3zeroDouble = { FP3ZEROdouble };
2902 #endif
2903 for (elemN = 0, fp3 = (struct fp3struct8 *) buffer;
2904 elemN < numElems; elemN++, fp3++) {
2905 if (fp3->e1 == 0x0 && fp3->e0 == 0x0 && fp3->s == 0x1) {
2906 *fp3 = FP3zeroDouble;
2907 }
2908 }
2909 #if LIMITfp3DOUBLEs
2910 /****************************************************************************
2911 * If this is a DEC Alpha (OpenVMS or POSIX Shell) built for a default of
2912 * D_FLOAT, check that the values do not exceed the maximum.
2913 ****************************************************************************/
2914 FP3doubleLIMIT (buffer, numElems);
2915 #endif
2916 return CDF_OK;
2917 }
2918
2919 /******************************************************************************
2920 * FP4doubleNEGtoPOS.
2921 * Convert -0.0 to 0.0 for floating-point/4 double-precision.
2922 ******************************************************************************/
2923
FP4doubleNEGtoPOS(buffer,numElems)2924 STATICforIDL CDFstatus FP4doubleNEGtoPOS (buffer, numElems)
2925 void *buffer;
2926 Int32 numElems;
2927 {
2928 struct fp4struct8 *fp4; Int32 elemN;
2929 #if DYNAMICfpSTRUCTs
2930 struct fp4struct8 FP4zeroDouble = { FP4ZEROdouble };
2931 #endif
2932 for (elemN = 0, fp4 = (struct fp4struct8 *) buffer;
2933 elemN < numElems; elemN++, fp4++) {
2934 if (fp4->e1 == 0x0 && fp4->e0 == 0x0 && fp4->s == 0x1) {
2935 *fp4 = FP4zeroDouble;
2936 }
2937 }
2938 return CDF_OK;
2939 }
2940
2941 /******************************************************************************
2942 * FP3doubleLIMIT.
2943 * Check that the maximum double-precision, floating-point/3 value on a
2944 * DEC Alpha (built for D_FLOAT) is not exceeded. The maximum allowed value
2945 * has an exponent of 0xFF and a mantissa of 0x7FFFFFFFFFFFFB.
2946 ******************************************************************************/
2947
FP3doubleLIMIT(buffer,numElems)2948 STATICforIDL CDFstatus FP3doubleLIMIT (buffer, numElems)
2949 void *buffer;
2950 Int32 numElems;
2951 {
2952 struct fp3struct8 *fp3; Int32 elemN;
2953 for (elemN = 0, fp3 = (struct fp3struct8 *) buffer;
2954 elemN < numElems; elemN++, fp3++) {
2955 if (fp3->e1 == 0x7F && fp3->e0 == 0x1 && fp3->m6 == 0x7F &&
2956 fp3->m5 == 0xFF && fp3->m4 == 0xFF && fp3->m3 == 0xFF &&
2957 fp3->m2 == 0xFF && fp3->m1 == 0xFF && fp3->m0 > 0xFB) {
2958 fp3->m0 = 0xFB;
2959 }
2960 }
2961 return CDF_OK;
2962 }
2963
2964 /******************************************************************************
2965 * Reverse2.
2966 ******************************************************************************/
2967
Reverse2(buffer,numElems)2968 STATICforIDL CDFstatus Reverse2 (buffer, numElems)
2969 void *buffer;
2970 Int32 numElems;
2971 {
2972 Byte *ptr; Int32 elemN;
2973 for (elemN = 0, ptr = (Byte *) buffer; elemN < numElems; elemN++, ptr += 2) {
2974 REVERSE2b (ptr)
2975 }
2976 return CDF_OK;
2977 }
2978
2979 /******************************************************************************
2980 * Reverse4.
2981 ******************************************************************************/
2982
Reverse4(buffer,numElems)2983 STATICforIDL CDFstatus Reverse4 (buffer, numElems)
2984 void *buffer;
2985 Int32 numElems;
2986 {
2987 Byte *ptr; Int32 elemN;
2988 for (elemN = 0, ptr = (Byte *) buffer; elemN < numElems; elemN++, ptr += 4) {
2989 REVERSE4b (ptr)
2990 }
2991 return CDF_OK;
2992 }
2993
2994 /******************************************************************************
2995 * Reverse8.
2996 ******************************************************************************/
2997
Reverse8(buffer,numElems)2998 STATICforIDL CDFstatus Reverse8 (buffer, numElems)
2999 void *buffer;
3000 Int32 numElems;
3001 {
3002 Byte *ptr; Int32 elemN;
3003 for (elemN = 0, ptr = (Byte *) buffer; elemN < numElems; elemN++, ptr += 8) {
3004 REVERSE8b (ptr)
3005 }
3006 return CDF_OK;
3007 }
3008
3009 /******************************************************************************
3010 * Reverse16.
3011 ******************************************************************************/
3012
Reverse16(buffer,numElems)3013 STATICforIDL CDFstatus Reverse16 (buffer, numElems)
3014 void *buffer;
3015 Int32 numElems;
3016 {
3017 Byte *ptr; Int32 elemN;
3018 for (elemN = 0, ptr = (Byte *) buffer; elemN < numElems; elemN++, ptr += 16) {
3019 REVERSE8b (ptr)
3020 REVERSE8b (ptr+8)
3021 }
3022 return CDF_OK;
3023 }
3024
3025
3026