sftypes.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Josef Cejka
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef __SFTYPES_H__
00036 #define __SFTYPES_H__
00037 
00038 #include <byteorder.h>
00039 #include <stdint.h>
00040 
00041 typedef union {
00042         float f;
00043         uint32_t binary;
00044         
00045         struct {
00046 #if defined(__BE__)
00047                 uint32_t sign : 1;
00048                 uint32_t exp : 8;
00049                 uint32_t fraction : 23;
00050 #elif defined(__LE__)
00051                 uint32_t fraction : 23;
00052                 uint32_t exp : 8;
00053                 uint32_t sign : 1;
00054 #else
00055         #error Unknown endianess
00056 #endif
00057         } parts __attribute__ ((packed));
00058 } float32;
00059 
00060 typedef union {
00061         double d;
00062         uint64_t binary;
00063         
00064         struct {
00065 #if defined(__BE__)
00066                 uint64_t sign : 1;
00067                 uint64_t exp : 11;
00068                 uint64_t fraction : 52;
00069 #elif defined(__LE__)
00070                 uint64_t fraction : 52;
00071                 uint64_t exp : 11;
00072                 uint64_t sign : 1;
00073 #else
00074         #error Unknown endianess
00075 #endif
00076         } parts __attribute__ ((packed));
00077 } float64;
00078 
00079 #define FLOAT32_MAX  0x7f800000
00080 #define FLOAT32_MIN  0xff800000
00081 #define FLOAT64_MAX
00082 #define FLOAT64_MIN
00083 
00084 /*
00085  * For recognizing NaNs or infinity use isFloat32NaN and is Float32Inf,
00086  * comparing with these constants is not sufficient.
00087  */
00088 
00089 #define FLOAT32_NAN     0x7FC00001
00090 #define FLOAT32_SIGNAN  0x7F800001
00091 #define FLOAT32_INF     0x7F800000
00092 
00093 #define FLOAT64_NAN     0x7FF8000000000001ll
00094 #define FLOAT64_SIGNAN  0x7FF0000000000001ll
00095 #define FLOAT64_INF     0x7FF0000000000000ll
00096 
00097 #define FLOAT32_FRACTION_SIZE  23
00098 #define FLOAT64_FRACTION_SIZE  52
00099 
00100 #define FLOAT32_HIDDEN_BIT_MASK  0x800000
00101 #define FLOAT64_HIDDEN_BIT_MASK  0x10000000000000ll
00102 
00103 #define FLOAT32_MAX_EXPONENT  0xFF
00104 #define FLOAT64_MAX_EXPONENT  0x7FF
00105 
00106 #define FLOAT32_BIAS  0x7F
00107 #define FLOAT64_BIAS  0x3FF
00108 #define FLOAT80_BIAS  0x3FFF
00109 
00110 #endif
00111 

Generated on Thu Jun 2 07:45:48 2011 for HelenOS/USB by  doxygen 1.4.7