Professional Web Applications Themes

Reliable definition of 80 bit floating point value - Mac Programming

At work, I am dealing with a cross platform code base that attempts to define an 80-bit floating point value with a definition similar to the following: typedef long double float80; With the Macintosh compiler this definition produces this warning message: warning: use of `long double' type; its size may change in a future release The compiler mentions that the warning can be eliminated by using the -Wno-long-double compiler switch to disable the warning. Our company prefers to compile code that generates no warnings, and we feel the best way to eliminate warnings is to fix code so it doesn't ...

  1. #1

    Default Reliable definition of 80 bit floating point value

    At work, I am dealing with a cross platform code base that attempts to
    define an 80-bit floating point value with a definition similar to the
    following:

    typedef long double float80;

    With the Macintosh compiler this definition produces this warning
    message:

    warning: use of `long double' type; its size may change in a future
    release

    The compiler mentions that the warning can be eliminated by using the
    -Wno-long-double compiler switch to disable the warning. Our company
    prefers to compile code that generates no warnings, and we feel the
    best way to eliminate warnings is to fix code so it doesn't produce
    warnings instead of relying on compiler switches prevent the warnings.

    What is a reliable way of defining an 80-bit floating point value that
    will no generate any compiler warnings?
    Tron Guest

  2. #2

    Default Re: Reliable definition of 80 bit floating point value

    In article <google.com>,
    net (Tron Thomas) wrote:
     

    You should be more concerned that a long double is really 80 bits. It
    is a shame you can't say something like:

    #if 10 != sizeof(long double)
    #error "long double isn't 8 bits"
    #endif

    look at boost.org 's compile-time if package
    David Guest

  3. #3

    Default Re: Reliable definition of 80 bit floating point value

    net (Tron Thomas) writes: 

    There is no cross platform mandate in the C Standard for any floating
    point type to have 80 bits. Even if an implementation defines
    __STDC_IEC_559__ and conforms to IEC 60559, there are no guarantees,
    long double will be 80 bits (an implementation could as well
    use 128 bits or 64 bits).
     

    There is none. You can only check wether your platform has 8 bit chars
    and store the value in a 10 char array, but you will never get
    guaranteed hardware support for 80 bit floating-point arithmetics.

    Please read ISO C99 Standard 5.2.4.2.2 and Annex D and F for the C
    language floating-point definitions.

    Thomas Jahns
    --
    "Computers are good at following instructions,
    but not at reading your mind."
    D. E. Knuth, The TeXbook, Addison-Wesley 1984, 1986, 1996, p. 9
    Thomas Guest

  4. #4

    Default Re: Reliable definition of 80 bit floating point value

    Thomas Jahns <de> wrote in message news:<user.dfncis.de>... 
    >
    > There is none. You can only check wether your platform has 8 bit chars
    > and store the value in a 10 char array, but you will never get
    > guaranteed hardware support for 80 bit floating-point arithmetics.
    >
    > Please read ISO C99 Standard 5.2.4.2.2 and Annex D and F for the C
    > language floating-point definitions.
    >
    > Thomas Jahns[/ref]

    Okay, given that there is no cross platform way to define and 80 bit
    floating point value. How can someone define an 80 bit floating point
    value on the Macintosh platform that will not produce a compiler
    warning?
    Tron Guest

  5. #5

    Default Re: Reliable definition of 80 bit floating point value

    dans l'article google.com, Tron Thomas à
    net a écrit le 2/07/04 5:07:
     
    >>
    >> There is none. You can only check wether your platform has 8 bit chars
    >> and store the value in a 10 char array, but you will never get
    >> guaranteed hardware support for 80 bit floating-point arithmetics.
    >>
    >> Please read ISO C99 Standard 5.2.4.2.2 and Annex D and F for the C
    >> language floating-point definitions.
    >>
    >> Thomas Jahns[/ref]
    >
    > Okay, given that there is no cross platform way to define and 80 bit
    > floating point value. How can someone define an 80 bit floating point
    > value on the Macintosh platform that will not produce a compiler
    > warning?[/ref]

    You can use the following, defined in MacTypes.h. But I'm unsure how they
    are supported by gcc.

    /************************************************** *************************
    *****

    Base floating point types

    Float32 32 bit IEEE float: 1 sign bit, 8 exponent bits, 23
    fraction bits
    Float64 64 bit IEEE float: 1 sign bit, 11 exponent bits, 52
    fraction bits
    Float80 80 bit MacOS float: 1 sign bit, 15 exponent bits, 1
    integer bit, 63 fraction bits
    Float96 96 bit 68881 float: 1 sign bit, 15 exponent bits, 16
    pad bits, 1 integer bit, 63 fraction bits

    Note: These are fixed size floating point types, useful when writing a
    floating
    point value to disk. If your compiler does not support a
    particular size
    float, a struct is used instead.
    Use of of the NCEG types (e.g. double_t) or an ANSI C type (e.g.
    double) if
    you want a floating point representation that is natural for any
    given
    compiler, but might be a different size on different compilers.

    ************************************************** **************************
    *****/
    typedef float Float32;
    #if (defined(__MWERKS__) && TARGET_CPU_68K) || defined(THINK_C)
    typedef short double Float64;
    #else
    typedef double Float64;
    #endif
    #if TARGET_CPU_68K
    #if TARGET_RT_MAC_68881
    typedef long double Float96;
    struct Float80 {
    SInt16 exp;
    UInt16 man[4];
    };
    typedef struct Float80 Float80;
    #else
    typedef long double Float80;
    struct Float96 {
    SInt16 exp[2]; /* the second 16-bits are undefined */
    UInt16 man[4];
    };
    typedef struct Float96 Float96;
    #endif
    #else
    struct Float80 {
    SInt16 exp;
    UInt16 man[4];
    };
    typedef struct Float80 Float80;

    struct Float96 {
    SInt16 exp[2]; /* the second 16-bits are undefined */
    UInt16 man[4];
    };
    typedef struct Float96 Float96;
    #endif
    struct Float32Point {
    Float32 x;
    Float32 y;
    };
    typedef struct Float32Point Float32Point;

    Eric

    Eric Guest

  6. #6

    Default Re: Reliable definition of 80 bit floating point value

    net (Tron Thomas) writes: 

    Well, there is none I know of because Macintosh does just what is most
    sensible for powerpc: long double is the same as double, there is no
    80bit floating point hardware support on the Macintosh (and many many
    other platforms). If you have to read in data saved as binary 80bit
    values in a file you will need to do a conversion by hand or get a
    library to do that for you.

    Thomas Jahns
    --
    "Computers are good at following instructions,
    but not at reading your mind."
    D. E. Knuth, The TeXbook, Addison-Wesley 1984, 1986, 1996, p. 9
    Thomas Guest

Similar Threads

  1. Floating point trickery
    By JeffS87 in forum Mac Programming
    Replies: 10
    Last Post: June 22nd, 01:01 AM
  2. Rounding of floating point numbers
    By Robert in forum PERL Beginners
    Replies: 18
    Last Post: February 25th, 10:59 AM
  3. OS 10.3 and floating point exception handling.
    By Jamie in forum Mac Programming
    Replies: 1
    Last Post: October 22nd, 05:05 PM
  4. From floating point to fraction
    By jon rogers in forum PERL Miscellaneous
    Replies: 6
    Last Post: July 5th, 08:19 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139