]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/example/inspect_fp.cpp
3 // Copyright (c) 2006 Johan Rade
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt
7 // or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //-------------------------------------
16 #include <boost/detail/endian.hpp>
18 //------------------------------------------------------------------------------
23 unsigned char first_byte
;
24 memcpy(&first_byte
, &x
, 1);
25 return first_byte
!= 0;
28 //------------------------------------------------------------------------------
30 void print_processor();
31 void print_endianness();
32 template<class T
> void print_table();
33 template<class T
> void print_row(const char* name
, T val
, bool ok
= true);
35 //------------------------------------------------------------------------------
45 std::cout
<< "---------- float --------------------\n\n";
48 std::cout
<< "---------- double -------------------\n\n";
49 print_table
<double>();
51 std::cout
<< "---------- long double --------------\n\n";
52 print_table
<long double>();
57 //------------------------------------------------------------------------------
59 void print_processor()
61 #if defined(__i386) || defined(__i386__) || defined(_M_IX86) \
62 || defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) \
63 || defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)
65 std::cout
<< "Processor: x86 or x64\n\n";
67 #elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
69 std::cout
<< "Processor: ia64\n\n";
71 #elif defined(__powerpc) || defined(__powerpc__) || defined(__POWERPC__) \
72 || defined(__ppc) || defined(__ppc__) || defined(__PPC__)
74 std::cout
<< "Processor: PowerPC\n\n";
76 #elif defined(__m68k) || defined(__m68k__) \
77 || defined(__mc68000) || defined(__mc68000__) \
79 std::cout << "Processor: Motorola 68K\n\n";
83 std::cout
<< "Processor: Unknown\n\n";
88 void print_endianness()
91 std::cout
<< "This platform is big-endian.\n";
93 std::cout
<< "This platform is little-endian.\n";
95 #ifdef BOOST_BIG_ENDIAN
96 std::cout
<< "BOOST_BIG_ENDIAN is defined.\n\n";
98 #if defined BOOST_LITTLE_ENDIAN
99 std::cout
<< "BOOST_LITTTLE_ENDIAN is defined.\n\n";
103 //..............................................................................
105 template<class T
> void print_table()
107 print_row("0", (T
)0);
108 print_row("sn.min", std::numeric_limits
<T
>::denorm_min(),
109 std::numeric_limits
<T
>::has_denorm
);
110 print_row("-sn.min", -std::numeric_limits
<T
>::denorm_min(),
111 std::numeric_limits
<T
>::has_denorm
);
112 print_row("n.min/256", (std::numeric_limits
<T
>::min
)()/256);
113 print_row("n.min/2", (std::numeric_limits
<T
>::min
)()/2);
114 print_row("-n.min/2", -(std::numeric_limits
<T
>::min
)()/2);
115 print_row("n.min", (std::numeric_limits
<T
>::min
)());
116 print_row("1", (T
)1);
117 print_row("3/4", (T
)3/(T
)4);
118 print_row("4/3", (T
)4/(T
)3);
119 print_row("max", (std::numeric_limits
<T
>::max
)());
120 print_row("inf", std::numeric_limits
<T
>::infinity(),
121 std::numeric_limits
<T
>::has_infinity
);
122 print_row("q.nan", std::numeric_limits
<T
>::quiet_NaN(),
123 std::numeric_limits
<T
>::has_quiet_NaN
);
124 print_row("s.nan", std::numeric_limits
<T
>::signaling_NaN(),
125 std::numeric_limits
<T
>::has_signaling_NaN
);
131 void print_row(const char* name
, T val
, bool ok
)
133 std::cout
<< std::left
<< std::setw(10) << name
<< std::right
;
135 std::cout
<< std::hex
<< std::setfill('0');
138 if(is_big_endian()) {
139 for(size_t i
= 0; i
< sizeof(T
); ++i
) {
140 unsigned char c
= *(reinterpret_cast<unsigned char*>(&val
) + i
);
141 std::cout
<< std::setw(2)
142 << static_cast<unsigned int>(c
) << ' ';
146 for(size_t i
= sizeof(T
) - 1; i
< sizeof(T
); --i
) {
147 unsigned char c
= *(reinterpret_cast<unsigned char*>(&val
) + i
);
148 std::cout
<< std::setw(2)
149 << static_cast<unsigned int>(c
) << ' ';
154 for(size_t i
= 0; i
< sizeof(T
); ++i
)
159 std::cout
<< std::dec
<< std::setfill(' ');
164 Sample output on an AMD Quadcore running MSVC 10
166 Processor: x86 or x64
168 This platform is little-endian.
169 BOOST_LITTTLE_ENDIAN is defined.
171 ---------- float --------------------
176 n.min/256 00 00 80 00
189 ---------- double -------------------
191 0 00 00 00 00 00 00 00 00
192 sn.min 00 00 00 00 00 00 00 01
193 -sn.min 80 00 00 00 00 00 00 01
194 n.min/256 00 00 10 00 00 00 00 00
195 n.min/2 00 08 00 00 00 00 00 00
196 -n.min/2 80 08 00 00 00 00 00 00
197 n.min 00 10 00 00 00 00 00 00
198 1 3f f0 00 00 00 00 00 00
199 3/4 3f e8 00 00 00 00 00 00
200 4/3 3f f5 55 55 55 55 55 55
201 max 7f ef ff ff ff ff ff ff
202 inf 7f f0 00 00 00 00 00 00
203 q.nan 7f f8 00 00 00 00 00 00
204 s.nan 7f f8 00 00 00 00 00 01
207 ---------- long double --------------
209 0 00 00 00 00 00 00 00 00
210 sn.min 00 00 00 00 00 00 00 01
211 -sn.min 80 00 00 00 00 00 00 01
212 n.min/256 00 00 10 00 00 00 00 00
213 n.min/2 00 08 00 00 00 00 00 00
214 -n.min/2 80 08 00 00 00 00 00 00
215 n.min 00 10 00 00 00 00 00 00
216 1 3f f0 00 00 00 00 00 00
217 3/4 3f e8 00 00 00 00 00 00
218 4/3 3f f5 55 55 55 55 55 55
219 max 7f ef ff ff ff ff ff ff
220 inf 7f f0 00 00 00 00 00 00
221 q.nan 7f f8 00 00 00 00 00 00
222 s.nan 7f f8 00 00 00 00 00 01