Changeset 16549 for trunk/psLib/src/fits/psFitsFloat.c
- Timestamp:
- Feb 19, 2008, 11:36:33 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/fits/psFitsFloat.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFitsFloat.c
r16108 r16549 1 /* 2 ** Copyright (C) 2008 Institute for Astronomy, University of Hawaii 3 ** 4 ** This is free software; you can redistribute it and/or 5 ** modify it under the terms of the GNU Lesser General Public 6 ** License as published by the Free Software Foundation; either 7 ** version 2.1 of the License, or (at your option) any later version. 8 ** 9 ** The GNU C Library is distributed in the hope that it will be useful, 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 ** Lesser General Public License for more details. 13 ** 14 ** You should have received a copy of the GNU Lesser General Public 15 ** License along with the GNU C Library; if not, write to the Free 16 ** Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 17 ** 02111-1307 USA. 18 */ 19 1 20 #ifdef HAVE_CONFIG_H 2 21 #include <config.h> 3 22 #endif 4 23 5 #include <ieee754.h>6 24 #include <string.h> 7 25 #include <assert.h> … … 17 35 #include "psFitsFloat.h" 18 36 19 #define BIAS_FLOAT_16_0 10 // Exponent bias for FLOAT_16_020 37 21 38 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 23 40 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 24 41 42 // This definition of IEEE754 floating-point, with some modifications, is from the GNU C Library, ieee754.h 43 // Copyright (C) 1992, 1995, 1996, 1999 Free Software Foundation, Inc. 44 union float_ieee754 { 45 float f; // Floating point 46 struct { // IEEE 754 single-precision format 47 #ifdef WORDS_BIGENDIAN 48 unsigned int negative:1; 49 unsigned int exponent:8; 50 unsigned int mantissa:23; 51 #else 52 unsigned int mantissa:23; 53 unsigned int exponent:8; 54 unsigned int negative:1; 55 #endif 56 } ieee; 57 }; 58 #define BIAS_FLOAT_IEEE754 0x7f // Exponent bias for IEEE754 59 // End definition from ieee754.h 60 61 62 // 16-bit floating point 25 63 union float_16_0 { 26 psS16 s16; // 16-bit integer version 27 28 // Floating-point version 29 struct { 30 unsigned int negative:1; // Sign bit 31 unsigned int exponent:5; // Exponent bits 32 unsigned int mantissa:10; // Mantissa bits 64 psS16 s16; // 16-bit integer version 65 struct { // Floating-point version 66 unsigned int negative:1; // Sign bit 67 unsigned int exponent:5; // Exponent bits 68 unsigned int mantissa:10; // Mantissa bits 33 69 } f16; 34 70 }; 71 #define BIAS_FLOAT_16_0 10 // Exponent bias for FLOAT_16_0 35 72 36 73 37 74 static inline psS16 convertF32toFloat16_0(psF32 value) 38 75 { 39 union ieee754_floatin; // Input value76 union float_ieee754 in; // Input value 40 77 union float_16_0 out; // Output value 41 78 … … 43 80 in.f = value; 44 81 out.f16.negative = in.ieee.negative; 45 out.f16.exponent = in.ieee.exponent - IEEE754_FLOAT_BIAS+ BIAS_FLOAT_16_0;82 out.f16.exponent = in.ieee.exponent - BIAS_FLOAT_IEEE754 + BIAS_FLOAT_16_0; 46 83 out.f16.mantissa = in.ieee.mantissa >> 13; 47 84 … … 52 89 { 53 90 union float_16_0 in; // Input value 54 union ieee754_floatout; // Output value91 union float_ieee754 out; // Output value 55 92 56 93 in.s16 = value; 57 94 out.ieee.negative = in.f16.negative; 58 out.ieee.exponent = in.f16.exponent + IEEE754_FLOAT_BIAS- BIAS_FLOAT_16_0;95 out.ieee.exponent = in.f16.exponent + BIAS_FLOAT_IEEE754 - BIAS_FLOAT_16_0; 59 96 out.ieee.mantissa = in.f16.mantissa << 13; 60 97
Note:
See TracChangeset
for help on using the changeset viewer.
