annotate DEPENDENCIES/generic/include/boost/math/special_functions/detail/fp_traits.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // fp_traits.hpp
Chris@16 2
Chris@16 3 #ifndef BOOST_MATH_FP_TRAITS_HPP
Chris@16 4 #define BOOST_MATH_FP_TRAITS_HPP
Chris@16 5
Chris@16 6 // Copyright (c) 2006 Johan Rade
Chris@16 7
Chris@16 8 // Distributed under the Boost Software License, Version 1.0.
Chris@16 9 // (See accompanying file LICENSE_1_0.txt
Chris@16 10 // or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 11
Chris@16 12 /*
Chris@16 13 To support old compilers, care has been taken to avoid partial template
Chris@16 14 specialization and meta function forwarding.
Chris@16 15 With these techniques, the code could be simplified.
Chris@16 16 */
Chris@16 17
Chris@16 18 #if defined(__vms) && defined(__DECCXX) && !__IEEE_FLOAT
Chris@16 19 // The VAX floating point formats are used (for float and double)
Chris@16 20 # define BOOST_FPCLASSIFY_VAX_FORMAT
Chris@16 21 #endif
Chris@16 22
Chris@16 23 #include <cstring>
Chris@16 24
Chris@16 25 #include <boost/assert.hpp>
Chris@16 26 #include <boost/cstdint.hpp>
Chris@16 27 #include <boost/detail/endian.hpp>
Chris@16 28 #include <boost/static_assert.hpp>
Chris@16 29 #include <boost/type_traits/is_floating_point.hpp>
Chris@16 30
Chris@16 31 #ifdef BOOST_NO_STDC_NAMESPACE
Chris@16 32 namespace std{ using ::memcpy; }
Chris@16 33 #endif
Chris@16 34
Chris@16 35 #ifndef FP_NORMAL
Chris@16 36
Chris@16 37 #define FP_ZERO 0
Chris@16 38 #define FP_NORMAL 1
Chris@16 39 #define FP_INFINITE 2
Chris@16 40 #define FP_NAN 3
Chris@16 41 #define FP_SUBNORMAL 4
Chris@16 42
Chris@16 43 #else
Chris@16 44
Chris@16 45 #define BOOST_HAS_FPCLASSIFY
Chris@16 46
Chris@16 47 #ifndef fpclassify
Chris@16 48 # if (defined(__GLIBCPP__) || defined(__GLIBCXX__)) \
Chris@16 49 && defined(_GLIBCXX_USE_C99_MATH) \
Chris@16 50 && !(defined(_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC) \
Chris@16 51 && (_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC != 0))
Chris@16 52 # ifdef _STLP_VENDOR_CSTD
Chris@16 53 # if _STLPORT_VERSION >= 0x520
Chris@16 54 # define BOOST_FPCLASSIFY_PREFIX ::__std_alias::
Chris@16 55 # else
Chris@16 56 # define BOOST_FPCLASSIFY_PREFIX ::_STLP_VENDOR_CSTD::
Chris@16 57 # endif
Chris@16 58 # else
Chris@16 59 # define BOOST_FPCLASSIFY_PREFIX ::std::
Chris@16 60 # endif
Chris@16 61 # else
Chris@16 62 # undef BOOST_HAS_FPCLASSIFY
Chris@16 63 # define BOOST_FPCLASSIFY_PREFIX
Chris@16 64 # endif
Chris@16 65 #elif (defined(__HP_aCC) && !defined(__hppa))
Chris@16 66 // aCC 6 appears to do "#define fpclassify fpclassify" which messes us up a bit!
Chris@16 67 # define BOOST_FPCLASSIFY_PREFIX ::
Chris@16 68 #else
Chris@16 69 # define BOOST_FPCLASSIFY_PREFIX
Chris@16 70 #endif
Chris@16 71
Chris@16 72 #ifdef __MINGW32__
Chris@16 73 # undef BOOST_HAS_FPCLASSIFY
Chris@16 74 #endif
Chris@16 75
Chris@16 76 #endif
Chris@16 77
Chris@16 78
Chris@16 79 //------------------------------------------------------------------------------
Chris@16 80
Chris@16 81 namespace boost {
Chris@16 82 namespace math {
Chris@16 83 namespace detail {
Chris@16 84
Chris@16 85 //------------------------------------------------------------------------------
Chris@16 86
Chris@16 87 /*
Chris@16 88 The following classes are used to tag the different methods that are used
Chris@16 89 for floating point classification
Chris@16 90 */
Chris@16 91
Chris@16 92 struct native_tag {};
Chris@16 93 template <bool has_limits>
Chris@16 94 struct generic_tag {};
Chris@16 95 struct ieee_tag {};
Chris@16 96 struct ieee_copy_all_bits_tag : public ieee_tag {};
Chris@16 97 struct ieee_copy_leading_bits_tag : public ieee_tag {};
Chris@16 98
Chris@16 99 #ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
Chris@16 100 //
Chris@16 101 // These helper functions are used only when numeric_limits<>
Chris@16 102 // members are not compile time constants:
Chris@16 103 //
Chris@16 104 inline bool is_generic_tag_false(const generic_tag<false>*)
Chris@16 105 {
Chris@16 106 return true;
Chris@16 107 }
Chris@16 108 inline bool is_generic_tag_false(const void*)
Chris@16 109 {
Chris@16 110 return false;
Chris@16 111 }
Chris@16 112 #endif
Chris@16 113
Chris@16 114 //------------------------------------------------------------------------------
Chris@16 115
Chris@16 116 /*
Chris@16 117 Most processors support three different floating point precisions:
Chris@16 118 single precision (32 bits), double precision (64 bits)
Chris@16 119 and extended double precision (80 - 128 bits, depending on the processor)
Chris@16 120
Chris@16 121 Note that the C++ type long double can be implemented
Chris@16 122 both as double precision and extended double precision.
Chris@16 123 */
Chris@16 124
Chris@16 125 struct unknown_precision{};
Chris@16 126 struct single_precision {};
Chris@16 127 struct double_precision {};
Chris@16 128 struct extended_double_precision {};
Chris@16 129
Chris@16 130 // native_tag version --------------------------------------------------------------
Chris@16 131
Chris@16 132 template<class T> struct fp_traits_native
Chris@16 133 {
Chris@16 134 typedef native_tag method;
Chris@16 135 };
Chris@16 136
Chris@16 137 // generic_tag version -------------------------------------------------------------
Chris@16 138
Chris@16 139 template<class T, class U> struct fp_traits_non_native
Chris@16 140 {
Chris@16 141 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
Chris@16 142 typedef generic_tag<std::numeric_limits<T>::is_specialized> method;
Chris@16 143 #else
Chris@16 144 typedef generic_tag<false> method;
Chris@16 145 #endif
Chris@16 146 };
Chris@16 147
Chris@16 148 // ieee_tag versions ---------------------------------------------------------------
Chris@16 149
Chris@16 150 /*
Chris@16 151 These specializations of fp_traits_non_native contain information needed
Chris@16 152 to "parse" the binary representation of a floating point number.
Chris@16 153
Chris@16 154 Typedef members:
Chris@16 155
Chris@16 156 bits -- the target type when copying the leading bytes of a floating
Chris@16 157 point number. It is a typedef for uint32_t or uint64_t.
Chris@16 158
Chris@16 159 method -- tells us whether all bytes are copied or not.
Chris@16 160 It is a typedef for ieee_copy_all_bits_tag or ieee_copy_leading_bits_tag.
Chris@16 161
Chris@16 162 Static data members:
Chris@16 163
Chris@16 164 sign, exponent, flag, significand -- bit masks that give the meaning of the
Chris@16 165 bits in the leading bytes.
Chris@16 166
Chris@16 167 Static function members:
Chris@16 168
Chris@16 169 get_bits(), set_bits() -- provide access to the leading bytes.
Chris@16 170
Chris@16 171 */
Chris@16 172
Chris@16 173 // ieee_tag version, float (32 bits) -----------------------------------------------
Chris@16 174
Chris@16 175 #ifndef BOOST_FPCLASSIFY_VAX_FORMAT
Chris@16 176
Chris@16 177 template<> struct fp_traits_non_native<float, single_precision>
Chris@16 178 {
Chris@16 179 typedef ieee_copy_all_bits_tag method;
Chris@16 180
Chris@16 181 BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u);
Chris@16 182 BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7f800000);
Chris@16 183 BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00000000);
Chris@16 184 BOOST_STATIC_CONSTANT(uint32_t, significand = 0x007fffff);
Chris@16 185
Chris@16 186 typedef uint32_t bits;
Chris@16 187 static void get_bits(float x, uint32_t& a) { std::memcpy(&a, &x, 4); }
Chris@16 188 static void set_bits(float& x, uint32_t a) { std::memcpy(&x, &a, 4); }
Chris@16 189 };
Chris@16 190
Chris@16 191 // ieee_tag version, double (64 bits) ----------------------------------------------
Chris@16 192
Chris@16 193 #if defined(BOOST_NO_INT64_T) || defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION) \
Chris@16 194 || defined(__BORLANDC__) || defined(__CODEGEAR__)
Chris@16 195
Chris@16 196 template<> struct fp_traits_non_native<double, double_precision>
Chris@16 197 {
Chris@16 198 typedef ieee_copy_leading_bits_tag method;
Chris@16 199
Chris@16 200 BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u);
Chris@16 201 BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7ff00000);
Chris@16 202 BOOST_STATIC_CONSTANT(uint32_t, flag = 0);
Chris@16 203 BOOST_STATIC_CONSTANT(uint32_t, significand = 0x000fffff);
Chris@16 204
Chris@16 205 typedef uint32_t bits;
Chris@16 206
Chris@16 207 static void get_bits(double x, uint32_t& a)
Chris@16 208 {
Chris@16 209 std::memcpy(&a, reinterpret_cast<const unsigned char*>(&x) + offset_, 4);
Chris@16 210 }
Chris@16 211
Chris@16 212 static void set_bits(double& x, uint32_t a)
Chris@16 213 {
Chris@16 214 std::memcpy(reinterpret_cast<unsigned char*>(&x) + offset_, &a, 4);
Chris@16 215 }
Chris@16 216
Chris@16 217 private:
Chris@16 218
Chris@16 219 #if defined(BOOST_BIG_ENDIAN)
Chris@16 220 BOOST_STATIC_CONSTANT(int, offset_ = 0);
Chris@16 221 #elif defined(BOOST_LITTLE_ENDIAN)
Chris@16 222 BOOST_STATIC_CONSTANT(int, offset_ = 4);
Chris@16 223 #else
Chris@16 224 BOOST_STATIC_ASSERT(false);
Chris@16 225 #endif
Chris@16 226 };
Chris@16 227
Chris@16 228 //..............................................................................
Chris@16 229
Chris@16 230 #else
Chris@16 231
Chris@16 232 template<> struct fp_traits_non_native<double, double_precision>
Chris@16 233 {
Chris@16 234 typedef ieee_copy_all_bits_tag method;
Chris@16 235
Chris@16 236 static const uint64_t sign = ((uint64_t)0x80000000u) << 32;
Chris@16 237 static const uint64_t exponent = ((uint64_t)0x7ff00000) << 32;
Chris@16 238 static const uint64_t flag = 0;
Chris@16 239 static const uint64_t significand
Chris@16 240 = (((uint64_t)0x000fffff) << 32) + ((uint64_t)0xffffffffu);
Chris@16 241
Chris@16 242 typedef uint64_t bits;
Chris@16 243 static void get_bits(double x, uint64_t& a) { std::memcpy(&a, &x, 8); }
Chris@16 244 static void set_bits(double& x, uint64_t a) { std::memcpy(&x, &a, 8); }
Chris@16 245 };
Chris@16 246
Chris@16 247 #endif
Chris@16 248
Chris@16 249 #endif // #ifndef BOOST_FPCLASSIFY_VAX_FORMAT
Chris@16 250
Chris@16 251 // long double (64 bits) -------------------------------------------------------
Chris@16 252
Chris@16 253 #if defined(BOOST_NO_INT64_T) || defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION)\
Chris@16 254 || defined(__BORLANDC__) || defined(__CODEGEAR__)
Chris@16 255
Chris@16 256 template<> struct fp_traits_non_native<long double, double_precision>
Chris@16 257 {
Chris@16 258 typedef ieee_copy_leading_bits_tag method;
Chris@16 259
Chris@16 260 BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u);
Chris@16 261 BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7ff00000);
Chris@16 262 BOOST_STATIC_CONSTANT(uint32_t, flag = 0);
Chris@16 263 BOOST_STATIC_CONSTANT(uint32_t, significand = 0x000fffff);
Chris@16 264
Chris@16 265 typedef uint32_t bits;
Chris@16 266
Chris@16 267 static void get_bits(long double x, uint32_t& a)
Chris@16 268 {
Chris@16 269 std::memcpy(&a, reinterpret_cast<const unsigned char*>(&x) + offset_, 4);
Chris@16 270 }
Chris@16 271
Chris@16 272 static void set_bits(long double& x, uint32_t a)
Chris@16 273 {
Chris@16 274 std::memcpy(reinterpret_cast<unsigned char*>(&x) + offset_, &a, 4);
Chris@16 275 }
Chris@16 276
Chris@16 277 private:
Chris@16 278
Chris@16 279 #if defined(BOOST_BIG_ENDIAN)
Chris@16 280 BOOST_STATIC_CONSTANT(int, offset_ = 0);
Chris@16 281 #elif defined(BOOST_LITTLE_ENDIAN)
Chris@16 282 BOOST_STATIC_CONSTANT(int, offset_ = 4);
Chris@16 283 #else
Chris@16 284 BOOST_STATIC_ASSERT(false);
Chris@16 285 #endif
Chris@16 286 };
Chris@16 287
Chris@16 288 //..............................................................................
Chris@16 289
Chris@16 290 #else
Chris@16 291
Chris@16 292 template<> struct fp_traits_non_native<long double, double_precision>
Chris@16 293 {
Chris@16 294 typedef ieee_copy_all_bits_tag method;
Chris@16 295
Chris@16 296 static const uint64_t sign = (uint64_t)0x80000000u << 32;
Chris@16 297 static const uint64_t exponent = (uint64_t)0x7ff00000 << 32;
Chris@16 298 static const uint64_t flag = 0;
Chris@16 299 static const uint64_t significand
Chris@16 300 = ((uint64_t)0x000fffff << 32) + (uint64_t)0xffffffffu;
Chris@16 301
Chris@16 302 typedef uint64_t bits;
Chris@16 303 static void get_bits(long double x, uint64_t& a) { std::memcpy(&a, &x, 8); }
Chris@16 304 static void set_bits(long double& x, uint64_t a) { std::memcpy(&x, &a, 8); }
Chris@16 305 };
Chris@16 306
Chris@16 307 #endif
Chris@16 308
Chris@16 309
Chris@16 310 // long double (>64 bits), x86 and x64 -----------------------------------------
Chris@16 311
Chris@16 312 #if defined(__i386) || defined(__i386__) || defined(_M_IX86) \
Chris@16 313 || defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) \
Chris@16 314 || defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)
Chris@16 315
Chris@16 316 // Intel extended double precision format (80 bits)
Chris@16 317
Chris@16 318 template<>
Chris@16 319 struct fp_traits_non_native<long double, extended_double_precision>
Chris@16 320 {
Chris@16 321 typedef ieee_copy_leading_bits_tag method;
Chris@16 322
Chris@16 323 BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u);
Chris@16 324 BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7fff0000);
Chris@16 325 BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00008000);
Chris@16 326 BOOST_STATIC_CONSTANT(uint32_t, significand = 0x00007fff);
Chris@16 327
Chris@16 328 typedef uint32_t bits;
Chris@16 329
Chris@16 330 static void get_bits(long double x, uint32_t& a)
Chris@16 331 {
Chris@16 332 std::memcpy(&a, reinterpret_cast<const unsigned char*>(&x) + 6, 4);
Chris@16 333 }
Chris@16 334
Chris@16 335 static void set_bits(long double& x, uint32_t a)
Chris@16 336 {
Chris@16 337 std::memcpy(reinterpret_cast<unsigned char*>(&x) + 6, &a, 4);
Chris@16 338 }
Chris@16 339 };
Chris@16 340
Chris@16 341
Chris@16 342 // long double (>64 bits), Itanium ---------------------------------------------
Chris@16 343
Chris@16 344 #elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
Chris@16 345
Chris@16 346 // The floating point format is unknown at compile time
Chris@16 347 // No template specialization is provided.
Chris@16 348 // The generic_tag definition is used.
Chris@16 349
Chris@16 350 // The Itanium supports both
Chris@16 351 // the Intel extended double precision format (80 bits) and
Chris@16 352 // the IEEE extended double precision format with 15 exponent bits (128 bits).
Chris@16 353
Chris@101 354 #elif defined(__GNUC__) && (LDBL_MANT_DIG == 106)
Chris@101 355
Chris@101 356 //
Chris@101 357 // Define nothing here and fall though to generic_tag:
Chris@101 358 // We have GCC's "double double" in effect, and any attempt
Chris@101 359 // to handle it via bit-fiddling is pretty much doomed to fail...
Chris@101 360 //
Chris@16 361
Chris@16 362 // long double (>64 bits), PowerPC ---------------------------------------------
Chris@16 363
Chris@16 364 #elif defined(__powerpc) || defined(__powerpc__) || defined(__POWERPC__) \
Chris@16 365 || defined(__ppc) || defined(__ppc__) || defined(__PPC__)
Chris@16 366
Chris@16 367 // PowerPC extended double precision format (128 bits)
Chris@16 368
Chris@16 369 template<>
Chris@16 370 struct fp_traits_non_native<long double, extended_double_precision>
Chris@16 371 {
Chris@16 372 typedef ieee_copy_leading_bits_tag method;
Chris@16 373
Chris@16 374 BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u);
Chris@16 375 BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7ff00000);
Chris@16 376 BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00000000);
Chris@16 377 BOOST_STATIC_CONSTANT(uint32_t, significand = 0x000fffff);
Chris@16 378
Chris@16 379 typedef uint32_t bits;
Chris@16 380
Chris@16 381 static void get_bits(long double x, uint32_t& a)
Chris@16 382 {
Chris@16 383 std::memcpy(&a, reinterpret_cast<const unsigned char*>(&x) + offset_, 4);
Chris@16 384 }
Chris@16 385
Chris@16 386 static void set_bits(long double& x, uint32_t a)
Chris@16 387 {
Chris@16 388 std::memcpy(reinterpret_cast<unsigned char*>(&x) + offset_, &a, 4);
Chris@16 389 }
Chris@16 390
Chris@16 391 private:
Chris@16 392
Chris@16 393 #if defined(BOOST_BIG_ENDIAN)
Chris@16 394 BOOST_STATIC_CONSTANT(int, offset_ = 0);
Chris@16 395 #elif defined(BOOST_LITTLE_ENDIAN)
Chris@16 396 BOOST_STATIC_CONSTANT(int, offset_ = 12);
Chris@16 397 #else
Chris@16 398 BOOST_STATIC_ASSERT(false);
Chris@16 399 #endif
Chris@16 400 };
Chris@16 401
Chris@16 402
Chris@16 403 // long double (>64 bits), Motorola 68K ----------------------------------------
Chris@16 404
Chris@16 405 #elif defined(__m68k) || defined(__m68k__) \
Chris@16 406 || defined(__mc68000) || defined(__mc68000__) \
Chris@16 407
Chris@16 408 // Motorola extended double precision format (96 bits)
Chris@16 409
Chris@16 410 // It is the same format as the Intel extended double precision format,
Chris@16 411 // except that 1) it is big-endian, 2) the 3rd and 4th byte are padding, and
Chris@16 412 // 3) the flag bit is not set for infinity
Chris@16 413
Chris@16 414 template<>
Chris@16 415 struct fp_traits_non_native<long double, extended_double_precision>
Chris@16 416 {
Chris@16 417 typedef ieee_copy_leading_bits_tag method;
Chris@16 418
Chris@16 419 BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u);
Chris@16 420 BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7fff0000);
Chris@16 421 BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00008000);
Chris@16 422 BOOST_STATIC_CONSTANT(uint32_t, significand = 0x00007fff);
Chris@16 423
Chris@16 424 // copy 1st, 2nd, 5th and 6th byte. 3rd and 4th byte are padding.
Chris@16 425
Chris@16 426 typedef uint32_t bits;
Chris@16 427
Chris@16 428 static void get_bits(long double x, uint32_t& a)
Chris@16 429 {
Chris@16 430 std::memcpy(&a, &x, 2);
Chris@16 431 std::memcpy(reinterpret_cast<unsigned char*>(&a) + 2,
Chris@16 432 reinterpret_cast<const unsigned char*>(&x) + 4, 2);
Chris@16 433 }
Chris@16 434
Chris@16 435 static void set_bits(long double& x, uint32_t a)
Chris@16 436 {
Chris@16 437 std::memcpy(&x, &a, 2);
Chris@16 438 std::memcpy(reinterpret_cast<unsigned char*>(&x) + 4,
Chris@16 439 reinterpret_cast<const unsigned char*>(&a) + 2, 2);
Chris@16 440 }
Chris@16 441 };
Chris@16 442
Chris@16 443
Chris@16 444 // long double (>64 bits), All other processors --------------------------------
Chris@16 445
Chris@16 446 #else
Chris@16 447
Chris@16 448 // IEEE extended double precision format with 15 exponent bits (128 bits)
Chris@16 449
Chris@16 450 template<>
Chris@16 451 struct fp_traits_non_native<long double, extended_double_precision>
Chris@16 452 {
Chris@16 453 typedef ieee_copy_leading_bits_tag method;
Chris@16 454
Chris@16 455 BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u);
Chris@16 456 BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7fff0000);
Chris@16 457 BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00000000);
Chris@16 458 BOOST_STATIC_CONSTANT(uint32_t, significand = 0x0000ffff);
Chris@16 459
Chris@16 460 typedef uint32_t bits;
Chris@16 461
Chris@16 462 static void get_bits(long double x, uint32_t& a)
Chris@16 463 {
Chris@16 464 std::memcpy(&a, reinterpret_cast<const unsigned char*>(&x) + offset_, 4);
Chris@16 465 }
Chris@16 466
Chris@16 467 static void set_bits(long double& x, uint32_t a)
Chris@16 468 {
Chris@16 469 std::memcpy(reinterpret_cast<unsigned char*>(&x) + offset_, &a, 4);
Chris@16 470 }
Chris@16 471
Chris@16 472 private:
Chris@16 473
Chris@16 474 #if defined(BOOST_BIG_ENDIAN)
Chris@16 475 BOOST_STATIC_CONSTANT(int, offset_ = 0);
Chris@16 476 #elif defined(BOOST_LITTLE_ENDIAN)
Chris@16 477 BOOST_STATIC_CONSTANT(int, offset_ = 12);
Chris@16 478 #else
Chris@16 479 BOOST_STATIC_ASSERT(false);
Chris@16 480 #endif
Chris@16 481 };
Chris@16 482
Chris@16 483 #endif
Chris@16 484
Chris@16 485 //------------------------------------------------------------------------------
Chris@16 486
Chris@16 487 // size_to_precision is a type switch for converting a C++ floating point type
Chris@16 488 // to the corresponding precision type.
Chris@16 489
Chris@16 490 template<int n, bool fp> struct size_to_precision
Chris@16 491 {
Chris@16 492 typedef unknown_precision type;
Chris@16 493 };
Chris@16 494
Chris@16 495 template<> struct size_to_precision<4, true>
Chris@16 496 {
Chris@16 497 typedef single_precision type;
Chris@16 498 };
Chris@16 499
Chris@16 500 template<> struct size_to_precision<8, true>
Chris@16 501 {
Chris@16 502 typedef double_precision type;
Chris@16 503 };
Chris@16 504
Chris@16 505 template<> struct size_to_precision<10, true>
Chris@16 506 {
Chris@16 507 typedef extended_double_precision type;
Chris@16 508 };
Chris@16 509
Chris@16 510 template<> struct size_to_precision<12, true>
Chris@16 511 {
Chris@16 512 typedef extended_double_precision type;
Chris@16 513 };
Chris@16 514
Chris@16 515 template<> struct size_to_precision<16, true>
Chris@16 516 {
Chris@16 517 typedef extended_double_precision type;
Chris@16 518 };
Chris@16 519
Chris@16 520 //------------------------------------------------------------------------------
Chris@16 521 //
Chris@16 522 // Figure out whether to use native classification functions based on
Chris@16 523 // whether T is a built in floating point type or not:
Chris@16 524 //
Chris@16 525 template <class T>
Chris@16 526 struct select_native
Chris@16 527 {
Chris@16 528 typedef BOOST_DEDUCED_TYPENAME size_to_precision<sizeof(T), ::boost::is_floating_point<T>::value>::type precision;
Chris@16 529 typedef fp_traits_non_native<T, precision> type;
Chris@16 530 };
Chris@16 531 template<>
Chris@16 532 struct select_native<float>
Chris@16 533 {
Chris@16 534 typedef fp_traits_native<float> type;
Chris@16 535 };
Chris@16 536 template<>
Chris@16 537 struct select_native<double>
Chris@16 538 {
Chris@16 539 typedef fp_traits_native<double> type;
Chris@16 540 };
Chris@16 541 template<>
Chris@16 542 struct select_native<long double>
Chris@16 543 {
Chris@16 544 typedef fp_traits_native<long double> type;
Chris@16 545 };
Chris@16 546
Chris@16 547 //------------------------------------------------------------------------------
Chris@16 548
Chris@16 549 // fp_traits is a type switch that selects the right fp_traits_non_native
Chris@16 550
Chris@16 551 #if (defined(BOOST_MATH_USE_C99) && !(defined(__GNUC__) && (__GNUC__ < 4))) \
Chris@16 552 && !defined(__hpux) \
Chris@16 553 && !defined(__DECCXX)\
Chris@16 554 && !defined(__osf__) \
Chris@16 555 && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)\
Chris@101 556 && !defined(__FAST_MATH__)\
Chris@101 557 && !defined(BOOST_MATH_DISABLE_STD_FPCLASSIFY)\
Chris@101 558 && !defined(BOOST_INTEL)\
Chris@101 559 && !defined(sun)
Chris@16 560 # define BOOST_MATH_USE_STD_FPCLASSIFY
Chris@16 561 #endif
Chris@16 562
Chris@16 563 template<class T> struct fp_traits
Chris@16 564 {
Chris@16 565 typedef BOOST_DEDUCED_TYPENAME size_to_precision<sizeof(T), ::boost::is_floating_point<T>::value>::type precision;
Chris@16 566 #if defined(BOOST_MATH_USE_STD_FPCLASSIFY) && !defined(BOOST_MATH_DISABLE_STD_FPCLASSIFY)
Chris@16 567 typedef typename select_native<T>::type type;
Chris@16 568 #else
Chris@16 569 typedef fp_traits_non_native<T, precision> type;
Chris@16 570 #endif
Chris@16 571 typedef fp_traits_non_native<T, precision> sign_change_type;
Chris@16 572 };
Chris@16 573
Chris@16 574 //------------------------------------------------------------------------------
Chris@16 575
Chris@16 576 } // namespace detail
Chris@16 577 } // namespace math
Chris@16 578 } // namespace boost
Chris@16 579
Chris@16 580 #endif