EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

StdLib/Include/sys/ieee754.h

Go to the documentation of this file.
00001 /*      $NetBSD: ieee754.h,v 1.6.24.1 2007/05/07 19:49:10 pavel Exp $   */
00002 
00003 /*
00004  * Copyright (c) 1992, 1993
00005  *      The Regents of the University of California.  All rights reserved.
00006  *
00007  * This software was developed by the Computer Systems Engineering group
00008  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
00009  * contributed to Berkeley.
00010  *
00011  * All advertising materials mentioning features or use of this software
00012  * must display the following acknowledgement:
00013  *      This product includes software developed by the University of
00014  *      California, Lawrence Berkeley Laboratory.
00015  *
00016  * Redistribution and use in source and binary forms, with or without
00017  * modification, are permitted provided that the following conditions
00018  * are met:
00019  * 1. Redistributions of source code must retain the above copyright
00020  *    notice, this list of conditions and the following disclaimer.
00021  * 2. Redistributions in binary form must reproduce the above copyright
00022  *    notice, this list of conditions and the following disclaimer in the
00023  *    documentation and/or other materials provided with the distribution.
00024  * 3. Neither the name of the University nor the names of its contributors
00025  *    may be used to endorse or promote products derived from this software
00026  *    without specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00029  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00032  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00034  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00035  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00036  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00037  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00038  * SUCH DAMAGE.
00039  *
00040  *      @(#)ieee.h      8.1 (Berkeley) 6/11/93
00041  */
00042 #ifndef _SYS_IEEE754_H_
00043 #define _SYS_IEEE754_H_
00044 
00045 /*
00046  * NOTICE: This is not a standalone file.  To use it, #include it in
00047  * your port's ieee.h header.
00048  */
00049 
00050 #include <machine/endian.h>
00051 
00052 /*
00053  * <sys/ieee754.h> defines the layout of IEEE 754 floating point types.
00054  * Only single-precision and double-precision types are defined here;
00055  * extended types, if available, are defined in the machine-dependent
00056  * header.
00057  */
00058 
00059 /*
00060  * Define the number of bits in each fraction and exponent.
00061  *
00062  *                   k           k+1
00063  * Note that  1.0 x 2  == 0.1 x 2      and that denorms are represented
00064  *
00065  *                                        (-exp_bias+1)
00066  * as fractions that look like 0.fffff x 2             .  This means that
00067  *
00068  *                       -126
00069  * the number 0.10000 x 2    , for instance, is the same as the normalized
00070  *
00071  *              -127                       -128
00072  * float 1.0 x 2    .  Thus, to represent 2    , we need one leading zero
00073  *
00074  *                                -129
00075  * in the fraction; to represent 2    , we need two, and so on.  This
00076  *
00077  *                                                   (-exp_bias-fracbits+1)
00078  * implies that the smallest denormalized number is 2
00079  *
00080  * for whichever format we are talking about: for single precision, for
00081  *
00082  *                                              -126            -149
00083  * instance, we get .00000000000000000000001 x 2    , or 1.0 x 2    , and
00084  *
00085  * -149 == -127 - 23 + 1.
00086  */
00087 #define SNG_EXPBITS     8
00088 #define SNG_FRACBITS    23
00089 
00090 struct ieee_single {
00091 #if _BYTE_ORDER == _BIG_ENDIAN
00092         u_int   sng_sign:1;
00093         u_int   sng_exp:SNG_EXPBITS;
00094         u_int   sng_frac:SNG_FRACBITS;
00095 #else
00096         u_int   sng_frac:SNG_FRACBITS;
00097         u_int   sng_exp:SNG_EXPBITS;
00098         u_int   sng_sign:1;
00099 #endif
00100 };
00101 
00102 #define DBL_EXPBITS     11
00103 #define DBL_FRACHBITS   20
00104 #define DBL_FRACLBITS   32
00105 #define DBL_FRACBITS    (DBL_FRACHBITS + DBL_FRACLBITS)
00106 
00107 struct ieee_double {
00108 #if _BYTE_ORDER == _BIG_ENDIAN
00109         u_int   dbl_sign:1;
00110         u_int   dbl_exp:DBL_EXPBITS;
00111         u_int   dbl_frach:DBL_FRACHBITS;
00112         u_int   dbl_fracl:DBL_FRACLBITS;
00113 #else
00114         u_int   dbl_fracl:DBL_FRACLBITS;
00115         u_int   dbl_frach:DBL_FRACHBITS;
00116         u_int   dbl_exp:DBL_EXPBITS;
00117         u_int   dbl_sign:1;
00118 #endif
00119 };
00120 
00121 /*
00122  * Floats whose exponent is in [1..INFNAN) (of whatever type) are
00123  * `normal'.  Floats whose exponent is INFNAN are either Inf or NaN.
00124  * Floats whose exponent is zero are either zero (iff all fraction
00125  * bits are zero) or subnormal values.
00126  *
00127  * At least one `signalling NaN' and one `quiet NaN' value must be
00128  * implemented.  It is left to the architecture to specify how to
00129  * distinguish between these.
00130  */
00131 #define SNG_EXP_INFNAN  255
00132 #define DBL_EXP_INFNAN  2047
00133 
00134 /*
00135  * Exponent biases.
00136  */
00137 #define SNG_EXP_BIAS    127
00138 #define DBL_EXP_BIAS    1023
00139 
00140 /*
00141  * Convenience data structures.
00142  */
00143 union ieee_single_u {
00144         float                   sngu_f;
00145         struct ieee_single      sngu_sng;
00146 };
00147 
00148 union ieee_double_u {
00149         double                  dblu_d;
00150         struct ieee_double      dblu_dbl;
00151 };
00152 #endif /* _SYS_IEEE754_H_ */
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines