00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #ifndef __SFTYPES_H__
00036 #define __SFTYPES_H__
00037
00038 #include <endian.h>
00039 #include <stdint.h>
00040
00041 typedef union {
00042 float f;
00043 uint32_t binary;
00044
00045 struct {
00046 #if __BYTE_ORDER == __BIG_ENDIAN
00047 uint32_t sign:1;
00048 uint32_t exp:8;
00049 uint32_t fraction:23;
00050 #elif __BYTE_ORDER == __LITTLE_ENDIAN
00051 uint32_t fraction:23;
00052 uint32_t exp:8;
00053 uint32_t sign:1;
00054 #else
00055 #error "Unknown endians."
00056 #endif
00057 } parts __attribute__ ((packed));
00058 } float32;
00059
00060 typedef union {
00061 double d;
00062 uint64_t binary;
00063
00064 struct {
00065 #if __BYTE_ORDER == __BIG_ENDIAN
00066 uint64_t sign:1;
00067 uint64_t exp:11;
00068 uint64_t fraction:52;
00069 #elif __BYTE_ORDER == __LITTLE_ENDIAN
00070 uint64_t fraction:52;
00071 uint64_t exp:11;
00072 uint64_t sign:1;
00073 #else
00074 #error "Unknown endians."
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 #define FLOAT32_NAN 0x7FC00001
00086 #define FLOAT32_SIGNAN 0x7F800001
00087 #define FLOAT32_INF 0x7F800000
00088
00089 #define FLOAT64_NAN 0x7FF8000000000001ll
00090 #define FLOAT64_SIGNAN 0x7FF0000000000001ll
00091 #define FLOAT64_INF 0x7FF0000000000000ll
00092
00093 #define FLOAT32_FRACTION_SIZE 23
00094 #define FLOAT64_FRACTION_SIZE 52
00095
00096 #define FLOAT32_HIDDEN_BIT_MASK 0x800000
00097 #define FLOAT64_HIDDEN_BIT_MASK 0x10000000000000ll
00098
00099 #define FLOAT32_MAX_EXPONENT 0xFF
00100 #define FLOAT64_MAX_EXPONENT 0x7FF
00101
00102 #define FLOAT32_BIAS 0x7F
00103 #define FLOAT64_BIAS 0x3FF
00104 #define FLOAT80_BIAS 0x3FFF
00105
00106
00107 #endif
00108
00109