std_limits.h revision 117397
1// The template and inlines for the -*- C++ -*- numeric_limits classes. 2 3// Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. 4// 5// This file is part of the GNU ISO C++ Library. This library is free 6// software; you can redistribute it and/or modify it under the 7// terms of the GNU General Public License as published by the 8// Free Software Foundation; either version 2, or (at your option) 9// any later version. 10 11// This library is distributed in the hope that it will be useful, 12// but WITHOUT ANY WARRANTY; without even the implied warranty of 13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14// GNU General Public License for more details. 15 16// You should have received a copy of the GNU General Public License along 17// with this library; see the file COPYING. If not, write to the Free 18// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 19// USA. 20 21// As a special exception, you may use this file as part of a free software 22// library without restriction. Specifically, if other files instantiate 23// templates or use macros or inline functions from this file, or you compile 24// this file and link it with other files to produce an executable, this 25// file does not by itself cause the resulting executable to be covered by 26// the GNU General Public License. This exception does not however 27// invalidate any other reasons why the executable file might be covered by 28// the GNU General Public License. 29 30// Note: this is not a conforming implementation. 31// Written by Gabriel Dos Reis <gdr@codesourcery.com> 32 33// 34// ISO 14882:1998 35// 18.2.1 36// 37 38/** @file limits 39 * This is a Standard C++ Library header. You should @c #include this header 40 * in your programs, rather than any of the "st[dl]_*.h" implementation files. 41 */ 42 43#ifndef _CPP_NUMERIC_LIMITS 44#define _CPP_NUMERIC_LIMITS 1 45 46#pragma GCC system_header 47 48#include <bits/c++config.h> 49 50// 51// The numeric_limits<> traits document implementation-defined aspects 52// of fundamental arithmetic data types (integers and floating points). 53// From Standard C++ point of view, there are 13 such types: 54// * integers 55// bool (1) 56// char, signed char, unsigned char (3) 57// short, unsigned short (2) 58// int, unsigned (2) 59// long, unsigned long (2) 60// 61// * floating points 62// float (1) 63// double (1) 64// long double (1) 65// 66// GNU C++ undertstands (where supported by the host C-library) 67// * integer 68// long long, unsigned long long (2) 69// 70// which brings us to 15 fundamental arithmetic data types in GNU C++. 71// 72// 73// Since a numeric_limits<> is a bit tricky to get right, we rely on 74// an interface composed of macros which should be defined in config/os 75// or config/cpu when they differ from the generic (read arbitrary) 76// definitions given here. 77// 78 79// These values can be overridden in the target configuration file. 80// The default values are appropriate for many 32-bit targets. 81 82// GCC only intrinsicly supports modulo integral types. The only remaining 83// integral exceptional values is division by zero. Only targets that do not 84// signal division by zero in some "hard to ignore" way should use false. 85#ifndef __glibcpp_integral_traps 86# define __glibcpp_integral_traps true 87#endif 88 89// float 90// 91 92// Default values. Should be overriden in configuration files if necessary. 93 94#ifndef __glibcpp_float_has_denorm_loss 95# define __glibcpp_float_has_denorm_loss false 96#endif 97#ifndef __glibcpp_float_traps 98# define __glibcpp_float_traps false 99#endif 100#ifndef __glibcpp_float_tinyness_before 101# define __glibcpp_float_tinyness_before false 102#endif 103 104// double 105 106// Default values. Should be overriden in configuration files if necessary. 107 108#ifndef __glibcpp_double_has_denorm_loss 109# define __glibcpp_double_has_denorm_loss false 110#endif 111#ifndef __glibcpp_double_traps 112# define __glibcpp_double_traps false 113#endif 114#ifndef __glibcpp_double_tinyness_before 115# define __glibcpp_double_tinyness_before false 116#endif 117 118// long double 119 120// Default values. Should be overriden in configuration files if necessary. 121 122#ifndef __glibcpp_long_double_has_denorm_loss 123# define __glibcpp_long_double_has_denorm_loss false 124#endif 125#ifndef __glibcpp_long_double_traps 126# define __glibcpp_long_double_traps false 127#endif 128#ifndef __glibcpp_long_double_tinyness_before 129# define __glibcpp_long_double_tinyness_before false 130#endif 131 132// You should not need to define any macros below this point. 133 134#define __glibcpp_signed(T) ((T)(-1) < 0) 135 136#define __glibcpp_min(T) \ 137 (__glibcpp_signed (T) ? (T)1 << __glibcpp_digits (T) : (T)0) 138 139#define __glibcpp_max(T) \ 140 (__glibcpp_signed (T) ? ((T)1 << __glibcpp_digits (T)) - 1 : ~(T)0) 141 142#define __glibcpp_digits(T) \ 143 (sizeof(T) * __CHAR_BIT__ - __glibcpp_signed (T)) 144 145// The fraction 643/2136 approximates log10(2) to 7 significant digits. 146#define __glibcpp_digits10(T) \ 147 (__glibcpp_digits (T) * 643 / 2136) 148 149 150namespace std 151{ 152 enum float_round_style 153 { 154 round_indeterminate = -1, 155 round_toward_zero = 0, 156 round_to_nearest = 1, 157 round_toward_infinity = 2, 158 round_toward_neg_infinity = 3 159 }; 160 161 enum float_denorm_style 162 { 163 denorm_indeterminate = -1, 164 denorm_absent = 0, 165 denorm_present = 1 166 }; 167 168 // 169 // The primary class traits 170 // 171 struct __numeric_limits_base 172 { 173 static const bool is_specialized = false; 174 175 static const int digits = 0; 176 static const int digits10 = 0; 177 static const bool is_signed = false; 178 static const bool is_integer = false; 179 static const bool is_exact = false; 180 static const int radix = 0; 181 182 static const int min_exponent = 0; 183 static const int min_exponent10 = 0; 184 static const int max_exponent = 0; 185 static const int max_exponent10 = 0; 186 187 static const bool has_infinity = false; 188 static const bool has_quiet_NaN = false; 189 static const bool has_signaling_NaN = false; 190 static const float_denorm_style has_denorm = denorm_absent; 191 static const bool has_denorm_loss = false; 192 193 static const bool is_iec559 = false; 194 static const bool is_bounded = false; 195 static const bool is_modulo = false; 196 197 static const bool traps = false; 198 static const bool tinyness_before = false; 199 static const float_round_style round_style = round_toward_zero; 200 }; 201 202 template<typename _Tp> 203 struct numeric_limits : public __numeric_limits_base 204 { 205 static _Tp min() throw() { return static_cast<_Tp>(0); } 206 static _Tp max() throw() { return static_cast<_Tp>(0); } 207 static _Tp epsilon() throw() { return static_cast<_Tp>(0); } 208 static _Tp round_error() throw() { return static_cast<_Tp>(0); } 209 static _Tp infinity() throw() { return static_cast<_Tp>(0); } 210 static _Tp quiet_NaN() throw() { return static_cast<_Tp>(0); } 211 static _Tp signaling_NaN() throw() { return static_cast<_Tp>(0); } 212 static _Tp denorm_min() throw() { return static_cast<_Tp>(0); } 213 }; 214 215 // Now there follow 15 explicit specializations. Yes, 15. Make sure 216 // you get the count right. 217 template<> 218 struct numeric_limits<bool> 219 { 220 static const bool is_specialized = true; 221 222 static bool min() throw() 223 { return false; } 224 static bool max() throw() 225 { return true; } 226 227 static const int digits = 1; 228 static const int digits10 = 0; 229 static const bool is_signed = false; 230 static const bool is_integer = true; 231 static const bool is_exact = true; 232 static const int radix = 2; 233 static bool epsilon() throw() 234 { return false; } 235 static bool round_error() throw() 236 { return false; } 237 238 static const int min_exponent = 0; 239 static const int min_exponent10 = 0; 240 static const int max_exponent = 0; 241 static const int max_exponent10 = 0; 242 243 static const bool has_infinity = false; 244 static const bool has_quiet_NaN = false; 245 static const bool has_signaling_NaN = false; 246 static const float_denorm_style has_denorm = denorm_absent; 247 static const bool has_denorm_loss = false; 248 249 static bool infinity() throw() 250 { return false; } 251 static bool quiet_NaN() throw() 252 { return false; } 253 static bool signaling_NaN() throw() 254 { return false; } 255 static bool denorm_min() throw() 256 { return false; } 257 258 static const bool is_iec559 = false; 259 static const bool is_bounded = true; 260 static const bool is_modulo = false; 261 262 // It is not clear what it means for a boolean type to trap. 263 // This is a DR on the LWG issue list. Here, I use integer 264 // promotion semantics. 265 static const bool traps = __glibcpp_integral_traps; 266 static const bool tinyness_before = false; 267 static const float_round_style round_style = round_toward_zero; 268 }; 269 270 template<> 271 struct numeric_limits<char> 272 { 273 static const bool is_specialized = true; 274 275 static char min() throw() 276 { return __glibcpp_min(char); } 277 static char max() throw() 278 { return __glibcpp_max(char); } 279 280 static const int digits = __glibcpp_digits (char); 281 static const int digits10 = __glibcpp_digits10 (char); 282 static const bool is_signed = __glibcpp_signed (char); 283 static const bool is_integer = true; 284 static const bool is_exact = true; 285 static const int radix = 2; 286 static char epsilon() throw() 287 { return 0; } 288 static char round_error() throw() 289 { return 0; } 290 291 static const int min_exponent = 0; 292 static const int min_exponent10 = 0; 293 static const int max_exponent = 0; 294 static const int max_exponent10 = 0; 295 296 static const bool has_infinity = false; 297 static const bool has_quiet_NaN = false; 298 static const bool has_signaling_NaN = false; 299 static const float_denorm_style has_denorm = denorm_absent; 300 static const bool has_denorm_loss = false; 301 302 static char infinity() throw() 303 { return char(); } 304 static char quiet_NaN() throw() 305 { return char(); } 306 static char signaling_NaN() throw() 307 { return char(); } 308 static char denorm_min() throw() 309 { return static_cast<char>(0); } 310 311 static const bool is_iec559 = false; 312 static const bool is_bounded = true; 313 static const bool is_modulo = true; 314 315 static const bool traps = __glibcpp_integral_traps; 316 static const bool tinyness_before = false; 317 static const float_round_style round_style = round_toward_zero; 318 }; 319 320 template<> 321 struct numeric_limits<signed char> 322 { 323 static const bool is_specialized = true; 324 325 static signed char min() throw() 326 { return -__SCHAR_MAX__ - 1; } 327 static signed char max() throw() 328 { return __SCHAR_MAX__; } 329 330 static const int digits = __glibcpp_digits (signed char); 331 static const int digits10 = __glibcpp_digits10 (signed char); 332 static const bool is_signed = true; 333 static const bool is_integer = true; 334 static const bool is_exact = true; 335 static const int radix = 2; 336 static signed char epsilon() throw() 337 { return 0; } 338 static signed char round_error() throw() 339 { return 0; } 340 341 static const int min_exponent = 0; 342 static const int min_exponent10 = 0; 343 static const int max_exponent = 0; 344 static const int max_exponent10 = 0; 345 346 static const bool has_infinity = false; 347 static const bool has_quiet_NaN = false; 348 static const bool has_signaling_NaN = false; 349 static const float_denorm_style has_denorm = denorm_absent; 350 static const bool has_denorm_loss = false; 351 352 static signed char infinity() throw() 353 { return static_cast<signed char>(0); } 354 static signed char quiet_NaN() throw() 355 { return static_cast<signed char>(0); } 356 static signed char signaling_NaN() throw() 357 { return static_cast<signed char>(0); } 358 static signed char denorm_min() throw() 359 { return static_cast<signed char>(0); } 360 361 static const bool is_iec559 = false; 362 static const bool is_bounded = true; 363 static const bool is_modulo = true; 364 365 static const bool traps = __glibcpp_integral_traps; 366 static const bool tinyness_before = false; 367 static const float_round_style round_style = round_toward_zero; 368 }; 369 370 template<> 371 struct numeric_limits<unsigned char> 372 { 373 static const bool is_specialized = true; 374 375 static unsigned char min() throw() 376 { return 0; } 377 static unsigned char max() throw() 378 { return __SCHAR_MAX__ * 2U + 1; } 379 380 static const int digits = __glibcpp_digits (unsigned char); 381 static const int digits10 = __glibcpp_digits10 (unsigned char); 382 static const bool is_signed = false; 383 static const bool is_integer = true; 384 static const bool is_exact = true; 385 static const int radix = 2; 386 static unsigned char epsilon() throw() 387 { return 0; } 388 static unsigned char round_error() throw() 389 { return 0; } 390 391 static const int min_exponent = 0; 392 static const int min_exponent10 = 0; 393 static const int max_exponent = 0; 394 static const int max_exponent10 = 0; 395 396 static const bool has_infinity = false; 397 static const bool has_quiet_NaN = false; 398 static const bool has_signaling_NaN = false; 399 static const float_denorm_style has_denorm = denorm_absent; 400 static const bool has_denorm_loss = false; 401 402 static unsigned char infinity() throw() 403 { return static_cast<unsigned char>(0); } 404 static unsigned char quiet_NaN() throw() 405 { return static_cast<unsigned char>(0); } 406 static unsigned char signaling_NaN() throw() 407 { return static_cast<unsigned char>(0); } 408 static unsigned char denorm_min() throw() 409 { return static_cast<unsigned char>(0); } 410 411 static const bool is_iec559 = false; 412 static const bool is_bounded = true; 413 static const bool is_modulo = true; 414 415 static const bool traps = __glibcpp_integral_traps; 416 static const bool tinyness_before = false; 417 static const float_round_style round_style = round_toward_zero; 418 }; 419 420 template<> 421 struct numeric_limits<wchar_t> 422 { 423 static const bool is_specialized = true; 424 425 static wchar_t min() throw() 426 { return __glibcpp_min (wchar_t); } 427 static wchar_t max() throw() 428 { return __glibcpp_max (wchar_t); } 429 430 static const int digits = __glibcpp_digits (wchar_t); 431 static const int digits10 = __glibcpp_digits10 (wchar_t); 432 static const bool is_signed = __glibcpp_signed (wchar_t); 433 static const bool is_integer = true; 434 static const bool is_exact = true; 435 static const int radix = 2; 436 static wchar_t epsilon() throw() 437 { return 0; } 438 static wchar_t round_error() throw() 439 { return 0; } 440 441 static const int min_exponent = 0; 442 static const int min_exponent10 = 0; 443 static const int max_exponent = 0; 444 static const int max_exponent10 = 0; 445 446 static const bool has_infinity = false; 447 static const bool has_quiet_NaN = false; 448 static const bool has_signaling_NaN = false; 449 static const float_denorm_style has_denorm = denorm_absent; 450 static const bool has_denorm_loss = false; 451 452 static wchar_t infinity() throw() 453 { return wchar_t(); } 454 static wchar_t quiet_NaN() throw() 455 { return wchar_t(); } 456 static wchar_t signaling_NaN() throw() 457 { return wchar_t(); } 458 static wchar_t denorm_min() throw() 459 { return wchar_t(); } 460 461 static const bool is_iec559 = false; 462 static const bool is_bounded = true; 463 static const bool is_modulo = true; 464 465 static const bool traps = __glibcpp_integral_traps; 466 static const bool tinyness_before = false; 467 static const float_round_style round_style = round_toward_zero; 468 }; 469 470 template<> 471 struct numeric_limits<short> 472 { 473 static const bool is_specialized = true; 474 475 static short min() throw() 476 { return -__SHRT_MAX__ - 1; } 477 static short max() throw() 478 { return __SHRT_MAX__; } 479 480 static const int digits = __glibcpp_digits (short); 481 static const int digits10 = __glibcpp_digits10 (short); 482 static const bool is_signed = true; 483 static const bool is_integer = true; 484 static const bool is_exact = true; 485 static const int radix = 2; 486 static short epsilon() throw() 487 { return 0; } 488 static short round_error() throw() 489 { return 0; } 490 491 static const int min_exponent = 0; 492 static const int min_exponent10 = 0; 493 static const int max_exponent = 0; 494 static const int max_exponent10 = 0; 495 496 static const bool has_infinity = false; 497 static const bool has_quiet_NaN = false; 498 static const bool has_signaling_NaN = false; 499 static const float_denorm_style has_denorm = denorm_absent; 500 static const bool has_denorm_loss = false; 501 502 static short infinity() throw() 503 { return short(); } 504 static short quiet_NaN() throw() 505 { return short(); } 506 static short signaling_NaN() throw() 507 { return short(); } 508 static short denorm_min() throw() 509 { return short(); } 510 511 static const bool is_iec559 = false; 512 static const bool is_bounded = true; 513 static const bool is_modulo = true; 514 515 static const bool traps = __glibcpp_integral_traps; 516 static const bool tinyness_before = false; 517 static const float_round_style round_style = round_toward_zero; 518 }; 519 520 template<> 521 struct numeric_limits<unsigned short> 522 { 523 static const bool is_specialized = true; 524 525 static unsigned short min() throw() 526 { return 0; } 527 static unsigned short max() throw() 528 { return __SHRT_MAX__ * 2U + 1; } 529 530 static const int digits = __glibcpp_digits (unsigned short); 531 static const int digits10 = __glibcpp_digits10 (unsigned short); 532 static const bool is_signed = false; 533 static const bool is_integer = true; 534 static const bool is_exact = true; 535 static const int radix = 2; 536 static unsigned short epsilon() throw() 537 { return 0; } 538 static unsigned short round_error() throw() 539 { return 0; } 540 541 static const int min_exponent = 0; 542 static const int min_exponent10 = 0; 543 static const int max_exponent = 0; 544 static const int max_exponent10 = 0; 545 546 static const bool has_infinity = false; 547 static const bool has_quiet_NaN = false; 548 static const bool has_signaling_NaN = false; 549 static const float_denorm_style has_denorm = denorm_absent; 550 static const bool has_denorm_loss = false; 551 552 static unsigned short infinity() throw() 553 { return static_cast<unsigned short>(0); } 554 static unsigned short quiet_NaN() throw() 555 { return static_cast<unsigned short>(0); } 556 static unsigned short signaling_NaN() throw() 557 { return static_cast<unsigned short>(0); } 558 static unsigned short denorm_min() throw() 559 { return static_cast<unsigned short>(0); } 560 561 static const bool is_iec559 = false; 562 static const bool is_bounded = true; 563 static const bool is_modulo = true; 564 565 static const bool traps = __glibcpp_integral_traps; 566 static const bool tinyness_before = false; 567 static const float_round_style round_style = round_toward_zero; 568 }; 569 570 template<> 571 struct numeric_limits<int> 572 { 573 static const bool is_specialized = true; 574 575 static int min() throw() 576 { return -__INT_MAX__ - 1; } 577 static int max() throw() 578 { return __INT_MAX__; } 579 580 static const int digits = __glibcpp_digits (int); 581 static const int digits10 = __glibcpp_digits10 (int); 582 static const bool is_signed = true; 583 static const bool is_integer = true; 584 static const bool is_exact = true; 585 static const int radix = 2; 586 static int epsilon() throw() 587 { return 0; } 588 static int round_error() throw() 589 { return 0; } 590 591 static const int min_exponent = 0; 592 static const int min_exponent10 = 0; 593 static const int max_exponent = 0; 594 static const int max_exponent10 = 0; 595 596 static const bool has_infinity = false; 597 static const bool has_quiet_NaN = false; 598 static const bool has_signaling_NaN = false; 599 static const float_denorm_style has_denorm = denorm_absent; 600 static const bool has_denorm_loss = false; 601 602 static int infinity() throw() 603 { return static_cast<int>(0); } 604 static int quiet_NaN() throw() 605 { return static_cast<int>(0); } 606 static int signaling_NaN() throw() 607 { return static_cast<int>(0); } 608 static int denorm_min() throw() 609 { return static_cast<int>(0); } 610 611 static const bool is_iec559 = false; 612 static const bool is_bounded = true; 613 static const bool is_modulo = true; 614 615 static const bool traps = __glibcpp_integral_traps; 616 static const bool tinyness_before = false; 617 static const float_round_style round_style = round_toward_zero; 618 }; 619 620 template<> 621 struct numeric_limits<unsigned int> 622 { 623 static const bool is_specialized = true; 624 625 static unsigned int min() throw() 626 { return 0; } 627 static unsigned int max() throw() 628 { return __INT_MAX__ * 2U + 1; } 629 630 static const int digits = __glibcpp_digits (unsigned int); 631 static const int digits10 = __glibcpp_digits10 (unsigned int); 632 static const bool is_signed = false; 633 static const bool is_integer = true; 634 static const bool is_exact = true; 635 static const int radix = 2; 636 static unsigned int epsilon() throw() 637 { return 0; } 638 static unsigned int round_error() throw() 639 { return 0; } 640 641 static const int min_exponent = 0; 642 static const int min_exponent10 = 0; 643 static const int max_exponent = 0; 644 static const int max_exponent10 = 0; 645 646 static const bool has_infinity = false; 647 static const bool has_quiet_NaN = false; 648 static const bool has_signaling_NaN = false; 649 static const float_denorm_style has_denorm = denorm_absent; 650 static const bool has_denorm_loss = false; 651 652 static unsigned int infinity() throw() 653 { return static_cast<unsigned int>(0); } 654 static unsigned int quiet_NaN() throw() 655 { return static_cast<unsigned int>(0); } 656 static unsigned int signaling_NaN() throw() 657 { return static_cast<unsigned int>(0); } 658 static unsigned int denorm_min() throw() 659 { return static_cast<unsigned int>(0); } 660 661 static const bool is_iec559 = false; 662 static const bool is_bounded = true; 663 static const bool is_modulo = true; 664 665 static const bool traps = __glibcpp_integral_traps; 666 static const bool tinyness_before = false; 667 static const float_round_style round_style = round_toward_zero; 668 }; 669 670 template<> 671 struct numeric_limits<long> 672 { 673 static const bool is_specialized = true; 674 675 static long min() throw() 676 { return -__LONG_MAX__ - 1; } 677 static long max() throw() 678 { return __LONG_MAX__; } 679 680 static const int digits = __glibcpp_digits (long); 681 static const int digits10 = __glibcpp_digits10 (long); 682 static const bool is_signed = true; 683 static const bool is_integer = true; 684 static const bool is_exact = true; 685 static const int radix = 2; 686 static long epsilon() throw() 687 { return 0; } 688 static long round_error() throw() 689 { return 0; } 690 691 static const int min_exponent = 0; 692 static const int min_exponent10 = 0; 693 static const int max_exponent = 0; 694 static const int max_exponent10 = 0; 695 696 static const bool has_infinity = false; 697 static const bool has_quiet_NaN = false; 698 static const bool has_signaling_NaN = false; 699 static const float_denorm_style has_denorm = denorm_absent; 700 static const bool has_denorm_loss = false; 701 702 static long infinity() throw() 703 { return static_cast<long>(0); } 704 static long quiet_NaN() throw() 705 { return static_cast<long>(0); } 706 static long signaling_NaN() throw() 707 { return static_cast<long>(0); } 708 static long denorm_min() throw() 709 { return static_cast<long>(0); } 710 711 static const bool is_iec559 = false; 712 static const bool is_bounded = true; 713 static const bool is_modulo = true; 714 715 static const bool traps = __glibcpp_integral_traps; 716 static const bool tinyness_before = false; 717 static const float_round_style round_style = round_toward_zero; 718 }; 719 720 template<> 721 struct numeric_limits<unsigned long> 722 { 723 static const bool is_specialized = true; 724 725 static unsigned long min() throw() 726 { return 0; } 727 static unsigned long max() throw() 728 { return __LONG_MAX__ * 2UL + 1; } 729 730 static const int digits = __glibcpp_digits (unsigned long); 731 static const int digits10 = __glibcpp_digits10 (unsigned long); 732 static const bool is_signed = false; 733 static const bool is_integer = true; 734 static const bool is_exact = true; 735 static const int radix = 2; 736 static unsigned long epsilon() throw() 737 { return 0; } 738 static unsigned long round_error() throw() 739 { return 0; } 740 741 static const int min_exponent = 0; 742 static const int min_exponent10 = 0; 743 static const int max_exponent = 0; 744 static const int max_exponent10 = 0; 745 746 static const bool has_infinity = false; 747 static const bool has_quiet_NaN = false; 748 static const bool has_signaling_NaN = false; 749 static const float_denorm_style has_denorm = denorm_absent; 750 static const bool has_denorm_loss = false; 751 752 static unsigned long infinity() throw() 753 { return static_cast<unsigned long>(0); } 754 static unsigned long quiet_NaN() throw() 755 { return static_cast<unsigned long>(0); } 756 static unsigned long signaling_NaN() throw() 757 { return static_cast<unsigned long>(0); } 758 static unsigned long denorm_min() throw() 759 { return static_cast<unsigned long>(0); } 760 761 static const bool is_iec559 = false; 762 static const bool is_bounded = true; 763 static const bool is_modulo = true; 764 765 static const bool traps = __glibcpp_integral_traps; 766 static const bool tinyness_before = false; 767 static const float_round_style round_style = round_toward_zero; 768 }; 769 770 template<> 771 struct numeric_limits<long long> 772 { 773 static const bool is_specialized = true; 774 775 static long long min() throw() 776 { return -__LONG_LONG_MAX__ - 1; } 777 static long long max() throw() 778 { return __LONG_LONG_MAX__; } 779 780 static const int digits = __glibcpp_digits (long long); 781 static const int digits10 = __glibcpp_digits10 (long long); 782 static const bool is_signed = true; 783 static const bool is_integer = true; 784 static const bool is_exact = true; 785 static const int radix = 2; 786 static long long epsilon() throw() 787 { return 0; } 788 static long long round_error() throw() 789 { return 0; } 790 791 static const int min_exponent = 0; 792 static const int min_exponent10 = 0; 793 static const int max_exponent = 0; 794 static const int max_exponent10 = 0; 795 796 static const bool has_infinity = false; 797 static const bool has_quiet_NaN = false; 798 static const bool has_signaling_NaN = false; 799 static const float_denorm_style has_denorm = denorm_absent; 800 static const bool has_denorm_loss = false; 801 802 static long long infinity() throw() 803 { return static_cast<long long>(0); } 804 static long long quiet_NaN() throw() 805 { return static_cast<long long>(0); } 806 static long long signaling_NaN() throw() 807 { return static_cast<long long>(0); } 808 static long long denorm_min() throw() 809 { return static_cast<long long>(0); } 810 811 static const bool is_iec559 = false; 812 static const bool is_bounded = true; 813 static const bool is_modulo = true; 814 815 static const bool traps = __glibcpp_integral_traps; 816 static const bool tinyness_before = false; 817 static const float_round_style round_style = round_toward_zero; 818 }; 819 820 template<> 821 struct numeric_limits<unsigned long long> 822 { 823 static const bool is_specialized = true; 824 825 static unsigned long long min() throw() 826 { return 0; } 827 static unsigned long long max() throw() 828 { return __LONG_LONG_MAX__ * 2ULL + 1; } 829 830 static const int digits = __glibcpp_digits (unsigned long long); 831 static const int digits10 = __glibcpp_digits10 (unsigned long long); 832 static const bool is_signed = false; 833 static const bool is_integer = true; 834 static const bool is_exact = true; 835 static const int radix = 2; 836 static unsigned long long epsilon() throw() 837 { return 0; } 838 static unsigned long long round_error() throw() 839 { return 0; } 840 841 static const int min_exponent = 0; 842 static const int min_exponent10 = 0; 843 static const int max_exponent = 0; 844 static const int max_exponent10 = 0; 845 846 static const bool has_infinity = false; 847 static const bool has_quiet_NaN = false; 848 static const bool has_signaling_NaN = false; 849 static const float_denorm_style has_denorm = denorm_absent; 850 static const bool has_denorm_loss = false; 851 852 static unsigned long long infinity() throw() 853 { return static_cast<unsigned long long>(0); } 854 static unsigned long long quiet_NaN() throw() 855 { return static_cast<unsigned long long>(0); } 856 static unsigned long long signaling_NaN() throw() 857 { return static_cast<unsigned long long>(0); } 858 static unsigned long long denorm_min() throw() 859 { return static_cast<unsigned long long>(0); } 860 861 static const bool is_iec559 = false; 862 static const bool is_bounded = true; 863 static const bool is_modulo = true; 864 865 static const bool traps = __glibcpp_integral_traps; 866 static const bool tinyness_before = false; 867 static const float_round_style round_style = round_toward_zero; 868 }; 869 870 template<> 871 struct numeric_limits<float> 872 { 873 static const bool is_specialized = true; 874 875 static float min() throw() 876 { return __FLT_MIN__; } 877 static float max() throw() 878 { return __FLT_MAX__; } 879 880 static const int digits = __FLT_MANT_DIG__; 881 static const int digits10 = __FLT_DIG__; 882 static const bool is_signed = true; 883 static const bool is_integer = false; 884 static const bool is_exact = false; 885 static const int radix = __FLT_RADIX__; 886 static float epsilon() throw() 887 { return __FLT_EPSILON__; } 888 static float round_error() throw() 889 { return 0.5F; } 890 891 static const int min_exponent = __FLT_MIN_EXP__; 892 static const int min_exponent10 = __FLT_MIN_10_EXP__; 893 static const int max_exponent = __FLT_MAX_EXP__; 894 static const int max_exponent10 = __FLT_MAX_10_EXP__; 895 896 static const bool has_infinity 897 = __builtin_huge_valf () / 2 == __builtin_huge_valf (); 898 static const bool has_quiet_NaN 899 = __builtin_nanf ("") != __builtin_nanf (""); 900 static const bool has_signaling_NaN = has_quiet_NaN; 901 static const float_denorm_style has_denorm 902 = __FLT_DENORM_MIN__ ? denorm_present : denorm_absent; 903 static const bool has_denorm_loss = __glibcpp_float_has_denorm_loss; 904 905 static float infinity() throw() 906 { return __builtin_huge_valf (); } 907 static float quiet_NaN() throw() 908 { return __builtin_nanf (""); } 909 static float signaling_NaN() throw() 910 { return __builtin_nansf (""); } 911 static float denorm_min() throw() 912 { return __FLT_DENORM_MIN__; } 913 914 static const bool is_iec559 915 = has_infinity && has_quiet_NaN && has_denorm == denorm_present; 916 static const bool is_bounded = true; 917 static const bool is_modulo = false; 918 919 static const bool traps = __glibcpp_float_traps; 920 static const bool tinyness_before = __glibcpp_float_tinyness_before; 921 static const float_round_style round_style = round_to_nearest; 922 }; 923 924#undef __glibcpp_float_has_denorm_loss 925#undef __glibcpp_float_traps 926#undef __glibcpp_float_tinyness_before 927 928 template<> 929 struct numeric_limits<double> 930 { 931 static const bool is_specialized = true; 932 933 static double min() throw() 934 { return __DBL_MIN__; } 935 static double max() throw() 936 { return __DBL_MAX__; } 937 938 static const int digits = __DBL_MANT_DIG__; 939 static const int digits10 = __DBL_DIG__; 940 static const bool is_signed = true; 941 static const bool is_integer = false; 942 static const bool is_exact = false; 943 static const int radix = __FLT_RADIX__; 944 static double epsilon() throw() 945 { return __DBL_EPSILON__; } 946 static double round_error() throw() 947 { return 0.5; } 948 949 static const int min_exponent = __DBL_MIN_EXP__; 950 static const int min_exponent10 = __DBL_MIN_10_EXP__; 951 static const int max_exponent = __DBL_MAX_EXP__; 952 static const int max_exponent10 = __DBL_MAX_10_EXP__; 953 954 static const bool has_infinity 955 = __builtin_huge_val () / 2 == __builtin_huge_val (); 956 static const bool has_quiet_NaN 957 = __builtin_nan ("") != __builtin_nan (""); 958 static const bool has_signaling_NaN = has_quiet_NaN; 959 static const float_denorm_style has_denorm 960 = __DBL_DENORM_MIN__ ? denorm_present : denorm_absent; 961 static const bool has_denorm_loss = __glibcpp_double_has_denorm_loss; 962 963 static double infinity() throw() 964 { return __builtin_huge_val(); } 965 static double quiet_NaN() throw() 966 { return __builtin_nan (""); } 967 static double signaling_NaN() throw() 968 { return __builtin_nans (""); } 969 static double denorm_min() throw() 970 { return __DBL_DENORM_MIN__; } 971 972 static const bool is_iec559 973 = has_infinity && has_quiet_NaN && has_denorm == denorm_present; 974 static const bool is_bounded = true; 975 static const bool is_modulo = false; 976 977 static const bool traps = __glibcpp_double_traps; 978 static const bool tinyness_before = __glibcpp_double_tinyness_before; 979 static const float_round_style round_style = round_to_nearest; 980 }; 981 982#undef __glibcpp_double_has_denorm_loss 983#undef __glibcpp_double_traps 984#undef __glibcpp_double_tinyness_before 985 986 template<> 987 struct numeric_limits<long double> 988 { 989 static const bool is_specialized = true; 990 991 static long double min() throw() 992 { return __LDBL_MIN__; } 993 static long double max() throw() 994 { return __LDBL_MAX__; } 995 996 static const int digits = __LDBL_MANT_DIG__; 997 static const int digits10 = __LDBL_DIG__; 998 static const bool is_signed = true; 999 static const bool is_integer = false; 1000 static const bool is_exact = false; 1001 static const int radix = __FLT_RADIX__; 1002 static long double epsilon() throw() 1003 { return __LDBL_EPSILON__; } 1004 static long double round_error() throw() 1005 { return 0.5L; } 1006 1007 static const int min_exponent = __LDBL_MIN_EXP__; 1008 static const int min_exponent10 = __LDBL_MIN_10_EXP__; 1009 static const int max_exponent = __LDBL_MAX_EXP__; 1010 static const int max_exponent10 = __LDBL_MAX_10_EXP__; 1011 1012 static const bool has_infinity 1013 = __builtin_huge_vall () / 2 == __builtin_huge_vall (); 1014 static const bool has_quiet_NaN 1015 = __builtin_nanl ("") != __builtin_nanl (""); 1016 static const bool has_signaling_NaN = has_quiet_NaN; 1017 static const float_denorm_style has_denorm 1018 = __LDBL_DENORM_MIN__ ? denorm_present : denorm_absent; 1019 static const bool has_denorm_loss 1020 = __glibcpp_long_double_has_denorm_loss; 1021 1022 static long double infinity() throw() 1023 { return __builtin_huge_vall (); } 1024 static long double quiet_NaN() throw() 1025 { return __builtin_nanl (""); } 1026 static long double signaling_NaN() throw() 1027 { return __builtin_nansl (""); } 1028 static long double denorm_min() throw() 1029 { return __LDBL_DENORM_MIN__; } 1030 1031 static const bool is_iec559 1032 = has_infinity && has_quiet_NaN && has_denorm == denorm_present; 1033 static const bool is_bounded = true; 1034 static const bool is_modulo = false; 1035 1036 static const bool traps = __glibcpp_long_double_traps; 1037 static const bool tinyness_before = __glibcpp_long_double_tinyness_before; 1038 static const float_round_style round_style = round_to_nearest; 1039 }; 1040 1041#undef __glibcpp_long_double_has_denorm_loss 1042#undef __glibcpp_long_double_traps 1043#undef __glibcpp_long_double_tinyness_before 1044 1045} // namespace std 1046 1047#undef __glibcpp_signed 1048#undef __glibcpp_min 1049#undef __glibcpp_max 1050#undef __glibcpp_digits 1051#undef __glibcpp_digits10 1052 1053#endif // _CPP_NUMERIC_LIMITS 1054