Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*      Copyright (C) 2006 Garrett A. Kajmowicz
  2.         This file is part of the uClibc++ Library.
  3.  
  4.         This library is free software; you can redistribute it and/or
  5.         modify it under the terms of the GNU Lesser General Public
  6.         License as published by the Free Software Foundation; either
  7.         version 2.1 of the License, or (at your option) any later version.
  8.  
  9.         This library is distributed in the hope that it will be useful,
  10.         but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.         Lesser General Public License for more details.
  13.  
  14.         You should have received a copy of the GNU Lesser General Public
  15.         License along with this library; if not, write to the Free Software
  16.         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17. */
  18.  
  19. #include <climits>
  20.  
  21. #ifndef __STD_HEADER_LIMITS
  22. #define __STD_HEADER_LIMITS 1
  23.  
  24. #warning limits header is nowhere complete or accurate
  25.  
  26. #pragma GCC visibility push(default)
  27.  
  28. namespace std{
  29.  
  30. enum float_round_style{
  31.         round_indeterminate             =-1,
  32.         round_toward_zero               = 0,
  33.         round_to_nearest                = 1,
  34.         round_toward_infinity           = 2,
  35.         round_toward_neg_infinity       = 3
  36. };
  37.  
  38. template <int bitsize> struct __bits_to_base_10{
  39.         static const int size = -1;
  40. };
  41. template <> struct __bits_to_base_10<7>{
  42.         static const int size = 2;
  43. };
  44. template <> struct __bits_to_base_10<8>{
  45.         static const int size = 2;
  46. };
  47. template <> struct __bits_to_base_10<9>{
  48.         static const int size = 2;
  49. };
  50. template <> struct __bits_to_base_10<10>{
  51.         static const int size = 3;
  52. };
  53. template <> struct __bits_to_base_10<15>{
  54.         static const int size = 4;
  55. };
  56. template <> struct __bits_to_base_10<16>{
  57.         static const int size = 4;
  58. };
  59. template <> struct __bits_to_base_10<17>{
  60.         static const int size = 5;
  61. };
  62. template <> struct __bits_to_base_10<18>{
  63.         static const int size = 5;
  64. };
  65. template <> struct __bits_to_base_10<31>{
  66.         static const int size = 9;
  67. };
  68. template <> struct __bits_to_base_10<32>{
  69.         static const int size = 9;
  70. };
  71. template <> struct __bits_to_base_10<35>{
  72.         static const int size = 10;
  73. };
  74. template <> struct __bits_to_base_10<36>{
  75.         static const int size = 10;
  76. };
  77. template <> struct __bits_to_base_10<63>{
  78.         static const int size = 18;
  79. };
  80. template <> struct __bits_to_base_10<64>{
  81.         static const int size = 19;
  82. };
  83. template <> struct __bits_to_base_10<71>{
  84.         static const int size = 21;
  85. };
  86. template <> struct __bits_to_base_10<72>{
  87.         static const int size = 21;
  88. };
  89. template <> struct __bits_to_base_10<79>{
  90.         static const int size = 23;
  91. };
  92. template <> struct __bits_to_base_10<80>{
  93.         static const int size = 24;
  94. };
  95. template <> struct __bits_to_base_10<127>{
  96.         static const int size = 38;
  97. };
  98. template <> struct __bits_to_base_10<128>{
  99.         static const int size = 38;
  100. };
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. template <class T> class numeric_limits {
  108. public:
  109.         // General -- meaningful for all specializations.
  110.  
  111.         static const bool is_specialized = false;
  112.         static T min();
  113.         static T max();
  114.         static const int radix;
  115.         static const int digits;
  116.         static const int digits10;
  117.         static const bool is_signed;
  118.         static const bool is_integer;
  119.         static const bool is_exact;
  120.         static const bool traps;
  121.         static const bool is_modulo;
  122.         static const bool is_bounded;
  123.  
  124.         // Floating point specific.
  125.  
  126.         static T epsilon();
  127.         static T round_error();
  128.         static const int min_exponent10;
  129.         static const int max_exponent10;
  130.         static const int min_exponent;
  131.  
  132.         static const int max_exponent;
  133.         static const bool has_infinity;
  134.         static const bool has_quiet_NaN;
  135.         static const bool has_signaling_NaN;
  136.         static const bool is_iec559;
  137.         static const bool has_denorm;
  138.         static const bool tinyness_before;
  139.         static const float_round_style round_style;
  140.         static T denorm_min();
  141.         static T infinity();
  142.         static T quiet_NaN();
  143.         static T signaling_NaN();
  144. };
  145.  
  146. template <> class numeric_limits<bool> {
  147. public:
  148.         typedef bool T;
  149.         // General -- meaningful for all specializations.
  150.         static const bool is_specialized = true;
  151.         static T min(){
  152.                 return false;
  153.         }
  154.         static T max(){
  155.                 return true;
  156.         }
  157.         static const int radix = 2;
  158.         static const int digits = 1;
  159.         static const int digits10 = 0;
  160.         static const bool is_signed = false;
  161.         static const bool is_integer = true;
  162.         static const bool is_exact = true;
  163.         static const bool traps = false;
  164.         static const bool is_modulo = false;
  165.         static const bool is_bounded = true;
  166.  
  167.         // Floating point specific.
  168.  
  169.         static T epsilon(){
  170.                 return 0;
  171.         }
  172.         static T round_error(){
  173.                 return 0;
  174.         }
  175.         static const int min_exponent10 = 0;
  176.         static const int max_exponent10 = 0;
  177.         static const int min_exponent = 0;
  178.  
  179.         static const int max_exponent = 0;
  180.         static const bool has_infinity = false;
  181.         static const bool has_quiet_NaN = false;
  182.         static const bool has_signaling_NaN = false;
  183.         static const bool is_iec559 = false;
  184.         static const bool has_denorm = false;
  185.         static const bool tinyness_before = false;
  186.         static const float_round_style round_style = round_indeterminate;
  187.         static T denorm_min();
  188.         static T infinity();
  189.         static T quiet_NaN();
  190.         static T signaling_NaN();
  191. };
  192.  
  193. template <> class numeric_limits<unsigned char> {
  194. public:
  195.         typedef unsigned char T;
  196.         // General -- meaningful for all specializations.
  197.         static const bool is_specialized = true;
  198.         static T min(){
  199.                 return 0;
  200.         }
  201.         static T max(){
  202.                 return UCHAR_MAX;
  203.         }
  204.         static const int radix = 2;
  205.         static const int digits = CHAR_BIT;
  206.         static const int digits10 = __bits_to_base_10<digits>::size;
  207.         static const bool is_signed = false;
  208.         static const bool is_integer = true;
  209.         static const bool is_exact = true;
  210.         static const bool traps = false;
  211.         static const bool is_modulo = true;
  212.         static const bool is_bounded = true;
  213.  
  214.         // Floating point specific.
  215.  
  216.         static T epsilon(){
  217.                 return 0;
  218.         }
  219.         static T round_error(){
  220.                 return 0;
  221.         }
  222.         static const int min_exponent10 = 0;
  223.         static const int max_exponent10 = 0;
  224.         static const int min_exponent = 0;
  225.  
  226.         static const int max_exponent = 0;
  227.         static const bool has_infinity = false;
  228.         static const bool has_quiet_NaN = false;
  229.         static const bool has_signaling_NaN = false;
  230.         static const bool is_iec559 = false;
  231.         static const bool has_denorm = false;
  232.         static const bool tinyness_before = false;
  233.         static const float_round_style round_style = round_indeterminate;
  234.         static T denorm_min();
  235.         static T infinity();
  236.         static T quiet_NaN();
  237.         static T signaling_NaN();
  238. };
  239.  
  240. template <> class numeric_limits<signed char> {
  241. public:
  242.         typedef signed char T;
  243.         // General -- meaningful for all specializations.
  244.         static const bool is_specialized = true;
  245.         static T min(){
  246.                 return SCHAR_MIN;
  247.         }
  248.         static T max(){
  249.                 return SCHAR_MAX;
  250.         }
  251.         static const int radix = 2;
  252.         static const int digits = CHAR_BIT - 1;
  253.         static const int digits10 = __bits_to_base_10<digits>::size;
  254.         static const bool is_signed = true;
  255.         static const bool is_integer = true;
  256.         static const bool is_exact = true;
  257.         static const bool traps = false;
  258.         static const bool is_modulo = true;
  259.         static const bool is_bounded = true;
  260.  
  261.         // Floating point specific.
  262.  
  263.         static T epsilon(){
  264.                 return 0;
  265.         }
  266.         static T round_error(){
  267.                 return 0;
  268.         }
  269.         static const int min_exponent10 = 0;
  270.         static const int max_exponent10 = 0;
  271.         static const int min_exponent = 0;
  272.  
  273.         static const int max_exponent = 0;
  274.         static const bool has_infinity = false;
  275.         static const bool has_quiet_NaN = false;
  276.         static const bool has_signaling_NaN = false;
  277.         static const bool is_iec559 = false;
  278.         static const bool has_denorm = false;
  279.         static const bool tinyness_before = false;
  280.         static const float_round_style round_style = round_indeterminate;
  281.         static T denorm_min();
  282.         static T infinity();
  283.         static T quiet_NaN();
  284.         static T signaling_NaN();
  285. };
  286.  
  287. template <> class numeric_limits<char> {
  288. public:
  289.         typedef char T;
  290.         // General -- meaningful for all specializations.
  291.         static const bool is_specialized = true;
  292.         static T min(){
  293.                 return CHAR_MIN;
  294.         }
  295.         static T max(){
  296.                 return CHAR_MAX;
  297.         }
  298.         static const int radix = 2;
  299.         static const int digits = (CHAR_MIN != 0) ? CHAR_BIT - 1 : CHAR_BIT;
  300.         static const int digits10 = __bits_to_base_10<digits>::size;
  301.         static const bool is_signed = (CHAR_MIN != 0);
  302.         static const bool is_integer = true;
  303.         static const bool is_exact = true;
  304.         static const bool traps = false;
  305.         static const bool is_modulo = true;
  306.         static const bool is_bounded = true;
  307.  
  308.         // Floating point specific.
  309.  
  310.         static T epsilon(){
  311.                 return 0;
  312.         }
  313.         static T round_error(){
  314.                 return 0;
  315.         }
  316.         static const int min_exponent10 = 0;
  317.         static const int max_exponent10 = 0;
  318.         static const int min_exponent = 0;
  319.  
  320.         static const int max_exponent = 0;
  321.         static const bool has_infinity = false;
  322.         static const bool has_quiet_NaN = false;
  323.         static const bool has_signaling_NaN = false;
  324.         static const bool is_iec559 = false;
  325.         static const bool has_denorm = false;
  326.         static const bool tinyness_before = false;
  327.         static const float_round_style round_style = round_indeterminate;
  328.         static T denorm_min();
  329.         static T infinity();
  330.         static T quiet_NaN();
  331.         static T signaling_NaN();
  332. };
  333.  
  334. template <> class numeric_limits<unsigned short> {
  335. public:
  336.         typedef unsigned short T;
  337.         // General -- meaningful for all specializations.
  338.         static const bool is_specialized = true;
  339.         static T min(){
  340.                 return 0;
  341.         }
  342.         static T max(){
  343.                 return USHRT_MAX;
  344.         }
  345.         static const int radix = 2;
  346.         static const int digits = CHAR_BIT * sizeof(T);
  347.         static const int digits10 = __bits_to_base_10<digits>::size;
  348.         static const bool is_signed = false;
  349.         static const bool is_integer = true;
  350.         static const bool is_exact = true;
  351.         static const bool traps = false;
  352.         static const bool is_modulo = true;
  353.         static const bool is_bounded = true;
  354.  
  355.         // Floating point specific.
  356.  
  357.         static T epsilon(){
  358.                 return 0;
  359.         }
  360.         static T round_error(){
  361.                 return 0;
  362.         }
  363.         static const int min_exponent10 = 0;
  364.         static const int max_exponent10 = 0;
  365.         static const int min_exponent = 0;
  366.  
  367.         static const int max_exponent = 0;
  368.         static const bool has_infinity = false;
  369.         static const bool has_quiet_NaN = false;
  370.         static const bool has_signaling_NaN = false;
  371.         static const bool is_iec559 = false;
  372.         static const bool has_denorm = false;
  373.         static const bool tinyness_before = false;
  374.         static const float_round_style round_style = round_indeterminate;
  375.         static T denorm_min();
  376.         static T infinity();
  377.         static T quiet_NaN();
  378.         static T signaling_NaN();
  379. };
  380.  
  381. template <> class numeric_limits<signed short> {
  382. public:
  383.         typedef signed short T;
  384.         // General -- meaningful for all specializations.
  385.         static const bool is_specialized = true;
  386.         static T min(){
  387.                 return SHRT_MIN;
  388.         }
  389.         static T max(){
  390.                 return SHRT_MAX;
  391.         }
  392.         static const int radix = 2;
  393.         static const int digits = CHAR_BIT * sizeof(T);
  394.         static const int digits10 = __bits_to_base_10<digits>::size;
  395.         static const bool is_signed = true;
  396.         static const bool is_integer = true;
  397.         static const bool is_exact = true;
  398.         static const bool traps = false;
  399.         static const bool is_modulo = true;
  400.         static const bool is_bounded = true;
  401.  
  402.         // Floating point specific.
  403.  
  404.         static T epsilon(){
  405.                 return 0;
  406.         }
  407.         static T round_error(){
  408.                 return 0;
  409.         }
  410.         static const int min_exponent10 = 0;
  411.         static const int max_exponent10 = 0;
  412.         static const int min_exponent = 0;
  413.  
  414.         static const int max_exponent = 0;
  415.         static const bool has_infinity = false;
  416.         static const bool has_quiet_NaN = false;
  417.         static const bool has_signaling_NaN = false;
  418.         static const bool is_iec559 = false;
  419.         static const bool has_denorm = false;
  420.         static const bool tinyness_before = false;
  421.         static const float_round_style round_style = round_indeterminate;
  422.         static T denorm_min();
  423.         static T infinity();
  424.         static T quiet_NaN();
  425.         static T signaling_NaN();
  426. };
  427.  
  428. template <> class numeric_limits<unsigned int> {
  429. public:
  430.         typedef unsigned int T;
  431.         // General -- meaningful for all specializations.
  432.         static const bool is_specialized = true;
  433.         static T min(){
  434.                 return 0;
  435.         }
  436.         static T max(){
  437.                 return UINT_MAX;
  438.         }
  439.         static const int radix = 2;
  440.         static const int digits = CHAR_BIT * sizeof(T);
  441.         static const int digits10 = __bits_to_base_10<digits>::size;
  442.         static const bool is_signed = false;
  443.         static const bool is_integer = true;
  444.         static const bool is_exact = true;
  445.         static const bool traps = false;
  446.         static const bool is_modulo = true;
  447.         static const bool is_bounded = true;
  448.  
  449.         // Floating point specific.
  450.  
  451.         static T epsilon(){
  452.                 return 0;
  453.         }
  454.         static T round_error(){
  455.                 return 0;
  456.         }
  457.         static const int min_exponent10 = 0;
  458.         static const int max_exponent10 = 0;
  459.         static const int min_exponent = 0;
  460.  
  461.         static const int max_exponent = 0;
  462.         static const bool has_infinity = false;
  463.         static const bool has_quiet_NaN = false;
  464.         static const bool has_signaling_NaN = false;
  465.         static const bool is_iec559 = false;
  466.         static const bool has_denorm = false;
  467.         static const bool tinyness_before = false;
  468.         static const float_round_style round_style = round_indeterminate;
  469.         static T denorm_min();
  470.         static T infinity();
  471.         static T quiet_NaN();
  472.         static T signaling_NaN();
  473. };
  474.  
  475. template <> class numeric_limits<signed int> {
  476. public:
  477.         typedef signed int T;
  478.         // General -- meaningful for all specializations.
  479.         static const bool is_specialized = true;
  480.         static T min(){
  481.                 return INT_MIN;
  482.         }
  483.         static T max(){
  484.                 return INT_MAX;
  485.         }
  486.         static const int radix = 2;
  487.         static const int digits = CHAR_BIT * sizeof(T);
  488.         static const int digits10 = __bits_to_base_10<digits>::size;
  489.         static const bool is_signed = true;
  490.         static const bool is_integer = true;
  491.         static const bool is_exact = true;
  492.         static const bool traps = false;
  493.         static const bool is_modulo = true;
  494.         static const bool is_bounded = true;
  495.  
  496.         // Floating point specific.
  497.  
  498.         static T epsilon(){
  499.                 return 0;
  500.         }
  501.         static T round_error(){
  502.                 return 0;
  503.         }
  504.         static const int min_exponent10 = 0;
  505.         static const int max_exponent10 = 0;
  506.         static const int min_exponent = 0;
  507.  
  508.         static const int max_exponent = 0;
  509.         static const bool has_infinity = false;
  510.         static const bool has_quiet_NaN = false;
  511.         static const bool has_signaling_NaN = false;
  512.         static const bool is_iec559 = false;
  513.         static const bool has_denorm = false;
  514.         static const bool tinyness_before = false;
  515.         static const float_round_style round_style = round_indeterminate;
  516.         static T denorm_min();
  517.         static T infinity();
  518.         static T quiet_NaN();
  519.         static T signaling_NaN();
  520. };
  521.  
  522. template <> class numeric_limits<unsigned long int> {
  523. public:
  524.         typedef unsigned long int T;
  525.         // General -- meaningful for all specializations.
  526.         static const bool is_specialized = true;
  527.         static T min(){
  528.                 return 0;
  529.         }
  530.         static T max(){
  531.                 return ULONG_MAX;
  532.         }
  533.         static const int radix = 2;
  534.         static const int digits = CHAR_BIT * sizeof(T);
  535.         static const int digits10 = __bits_to_base_10<digits>::size;
  536.         static const bool is_signed = false;
  537.         static const bool is_integer = true;
  538.         static const bool is_exact = true;
  539.         static const bool traps = false;
  540.         static const bool is_modulo = true;
  541.         static const bool is_bounded = true;
  542.  
  543.         // Floating point specific.
  544.  
  545.         static T epsilon(){
  546.                 return 0;
  547.         }
  548.         static T round_error(){
  549.                 return 0;
  550.         }
  551.         static const int min_exponent10 = 0;
  552.         static const int max_exponent10 = 0;
  553.         static const int min_exponent = 0;
  554.  
  555.         static const int max_exponent = 0;
  556.         static const bool has_infinity = false;
  557.         static const bool has_quiet_NaN = false;
  558.         static const bool has_signaling_NaN = false;
  559.         static const bool is_iec559 = false;
  560.         static const bool has_denorm = false;
  561.         static const bool tinyness_before = false;
  562.         static const float_round_style round_style = round_indeterminate;
  563.         static T denorm_min();
  564.         static T infinity();
  565.         static T quiet_NaN();
  566.         static T signaling_NaN();
  567. };
  568.  
  569. template <> class numeric_limits<signed long int> {
  570. public:
  571.         typedef signed long int T;
  572.         // General -- meaningful for all specializations.
  573.         static const bool is_specialized = true;
  574.         static T min(){
  575.                 return LONG_MIN;
  576.         }
  577.         static T max(){
  578.                 return LONG_MAX;
  579.         }
  580.         static const int radix = 2;
  581.         static const int digits = CHAR_BIT * sizeof(T);
  582.         static const int digits10 = __bits_to_base_10<digits>::size;
  583.         static const bool is_signed = true;
  584.         static const bool is_integer = true;
  585.         static const bool is_exact = true;
  586.         static const bool traps = false;
  587.         static const bool is_modulo = true;
  588.         static const bool is_bounded = true;
  589.  
  590.         // Floating point specific.
  591.  
  592.         static T epsilon(){
  593.                 return 0;
  594.         }
  595.         static T round_error(){
  596.                 return 0;
  597.         }
  598.         static const int min_exponent10 = 0;
  599.         static const int max_exponent10 = 0;
  600.         static const int min_exponent = 0;
  601.  
  602.         static const int max_exponent = 0;
  603.         static const bool has_infinity = false;
  604.         static const bool has_quiet_NaN = false;
  605.         static const bool has_signaling_NaN = false;
  606.         static const bool is_iec559 = false;
  607.         static const bool has_denorm = false;
  608.         static const bool tinyness_before = false;
  609.         static const float_round_style round_style = round_indeterminate;
  610.         static T denorm_min();
  611.         static T infinity();
  612.         static T quiet_NaN();
  613.         static T signaling_NaN();
  614. };
  615.  
  616. template <> class numeric_limits<double> {
  617. public:
  618.         typedef double numeric_type;
  619.  
  620.         static const bool is_specialized = true;
  621.         static numeric_type min () { return __DBL_MIN__; }
  622.         static numeric_type max () { return __DBL_MAX__; }
  623.         static const int radix = __FLT_RADIX__;
  624.         static const int digits = __DBL_MANT_DIG__;
  625.         static const int digits10 = __DBL_DIG__;
  626.         static const bool is_signed = true;
  627.         static const bool is_integer = false;
  628.         static const bool is_exact = false;
  629.         static const bool traps = false; // this is a guess
  630.         static const bool is_modulo = false;
  631.         static const bool is_bounded = true;
  632.  
  633.         // Floating point specific.
  634.  
  635.         static numeric_type epsilon () { return __DBL_EPSILON__; }
  636.         static numeric_type round_error () { return 0.5; }
  637.         static const int min_exponent10 = -1; //How do I properly get this?
  638.         static const int max_exponent10 = -1; //How do I properly get this?
  639.         static const int min_exponent   = -1; //How do I properly get this?
  640.         static const int max_exponent   = -1; //How do I properly get this?
  641.         static const bool has_infinity  = false; //I don't know, so until I can find out, I'm saying no
  642.         static const bool has_quiet_NaN = false; //I don't know, so until I can find out, I'm saying no
  643.         static const bool has_signaling_NaN = false; //I don't know, so until I can find out, I'm saying no
  644.         static const bool has_denorm = false; //I don't know, so until I can find out, I'm saying no
  645.  
  646.         static const bool is_iec559 = false;  //I don't know, so until I can find out, I'm saying no
  647.         static const bool tinyness_before = false; // more questions
  648.         static const float_round_style round_style = round_to_nearest; // more questions
  649.         static numeric_type denorm_min () { return -1; } //How do I properly get this?
  650.         static numeric_type infinity () { return -1; } //How do I properly get this?
  651.         static numeric_type quiet_NaN () { return -1; } //How do I properly get this?
  652.         static numeric_type signaling_NaN () { return -1; } //How do I properly get this?
  653. };
  654.  
  655.  
  656.  
  657.  
  658.  
  659. }
  660.  
  661. #pragma GCC visibility pop
  662.  
  663. #endif
  664.