IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16549


Ignore:
Timestamp:
Feb 19, 2008, 11:36:33 AM (18 years ago)
Author:
Paul Price
Message:

ieee754.h doesn't exist on MacOS X. Moved required definition from glibc into this file.

File:
1 edited

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
    120#ifdef HAVE_CONFIG_H
    221#include <config.h>
    322#endif
    423
    5 #include <ieee754.h>
    624#include <string.h>
    725#include <assert.h>
     
    1735#include "psFitsFloat.h"
    1836
    19 #define BIAS_FLOAT_16_0              10 // Exponent bias for FLOAT_16_0
    2037
    2138//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
    2340//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    2441
     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.
     44union 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
    2563union 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
    3369    } f16;
    3470};
     71#define BIAS_FLOAT_16_0              10 // Exponent bias for FLOAT_16_0
    3572
    3673
    3774static inline psS16 convertF32toFloat16_0(psF32 value)
    3875{
    39     union ieee754_float in;             // Input value
     76    union float_ieee754 in;             // Input value
    4077    union float_16_0 out;               // Output value
    4178
     
    4380    in.f = value;
    4481    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;
    4683    out.f16.mantissa = in.ieee.mantissa >> 13;
    4784
     
    5289{
    5390    union float_16_0 in;                // Input value
    54     union ieee754_float out;            // Output value
     91    union float_ieee754 out;            // Output value
    5592
    5693    in.s16 = value;
    5794    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;
    5996    out.ieee.mantissa = in.f16.mantissa << 13;
    6097
Note: See TracChangeset for help on using the changeset viewer.