stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r429712 - in /incubator/stdcxx/trunk/examples/manual: limits.cpp out/limits.out
Date Tue, 08 Aug 2006 16:27:36 GMT
Author: sebor
Date: Tue Aug  8 09:27:36 2006
New Revision: 429712

URL: http://svn.apache.org/viewvc?rev=429712&view=rev
Log:
2006-08-08  Martin Sebor  <sebor@roguewave.com>

	* limits.cpp: Added output for numeric_limits<int> and changed
	format to make it more readable.
	* limits.out: Same.

Modified:
    incubator/stdcxx/trunk/examples/manual/limits.cpp
    incubator/stdcxx/trunk/examples/manual/out/limits.out

Modified: incubator/stdcxx/trunk/examples/manual/limits.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/examples/manual/limits.cpp?rev=429712&r1=429711&r2=429712&view=diff
==============================================================================
--- incubator/stdcxx/trunk/examples/manual/limits.cpp (original)
+++ incubator/stdcxx/trunk/examples/manual/limits.cpp Tue Aug  8 09:27:36 2006
@@ -3,20 +3,27 @@
  * limits.cpp - Example program of numeric limits class used for 
  *              representing information about scalar types.
  *
- * $Id: //stdlib/dev/examples/stdlib/manual/limits.cpp#12 $
+ * $Id$
  *
  ***************************************************************************
  *
- * Copyright (c) 1994-2005 Quovadx,  Inc., acting through its  Rogue Wave
- * Software division. Licensed under the Apache License, Version 2.0 (the
- * "License");  you may  not use this file except  in compliance with the
- * License.    You    may   obtain   a   copy   of    the   License    at
- * http://www.apache.org/licenses/LICENSE-2.0.    Unless   required    by
- * applicable law  or agreed to  in writing,  software  distributed under
- * the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR
- * CONDITIONS OF  ANY KIND, either  express or implied.  See  the License
- * for the specific language governing permissions  and limitations under
- * the License.
+ * Licensed to the Apache Software  Foundation (ASF) under one or more
+ * contributor  license agreements.  See  the NOTICE  file distributed
+ * with  this  work  for  additional information  regarding  copyright
+ * ownership.   The ASF  licenses this  file to  you under  the Apache
+ * License, Version  2.0 (the  "License"); you may  not use  this file
+ * except in  compliance with the License.   You may obtain  a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the  License is distributed on an  "AS IS" BASIS,
+ * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
+ * implied.   See  the License  for  the  specific language  governing
+ * permissions and limitations under the License.
+ *
+ * Copyright 1998-2006 Rogue Wave Software.
  * 
  **************************************************************************/
 
@@ -29,56 +36,72 @@
 template <class T>
 void print_limits (std::ostream &strm, const char *tname, T)
 {
-#define PRINT_MEMBER(member)                                       \
-    strm << "std::numeric_limits<" << tname << ">::" #member " =
" \
-         << std::numeric_limits<T>::member << '\n';
+#define PRINT_MEMBER(type, member)                     \
+    strm << "    static " << type << " " #member " = "            \
+         << std::numeric_limits<T>::member << ";\n"
+
+    strm << "struct std::numeric_limits<" << tname << "> {\n";
+
+    PRINT_MEMBER ("const bool", is_specialized);
 
-    PRINT_MEMBER (is_specialized);
+    PRINT_MEMBER (tname, min ());
+    PRINT_MEMBER (tname, max ());
 
-    PRINT_MEMBER (min ());
-    PRINT_MEMBER (max ());
+    PRINT_MEMBER ("const int", digits);
+    PRINT_MEMBER ("const int", digits10);
 
-    PRINT_MEMBER (digits);
-    PRINT_MEMBER (digits10);
+    PRINT_MEMBER ("const bool", is_signed);
+    PRINT_MEMBER ("const bool", is_integer);
+    PRINT_MEMBER ("const bool", is_exact);
+    PRINT_MEMBER ("const int", radix);
 
-    PRINT_MEMBER (is_signed);
-    PRINT_MEMBER (is_integer);
-    PRINT_MEMBER (is_exact);
-    PRINT_MEMBER (radix);
+    PRINT_MEMBER (tname, epsilon ());
+    PRINT_MEMBER ("int", round_error ());
 
-    PRINT_MEMBER (epsilon ());
-    PRINT_MEMBER (round_error ());
+    PRINT_MEMBER ("const int", min_exponent);
+    PRINT_MEMBER ("const int", min_exponent10);
+    PRINT_MEMBER ("const int", max_exponent);
+    PRINT_MEMBER ("const int", max_exponent10);
 
-    PRINT_MEMBER (min_exponent);
-    PRINT_MEMBER (min_exponent10);
-    PRINT_MEMBER (max_exponent);
-    PRINT_MEMBER (max_exponent10);
+    PRINT_MEMBER ("const bool", has_infinity);
+    PRINT_MEMBER ("const bool", has_quiet_NaN);
+    PRINT_MEMBER ("const bool", has_signaling_NaN);
+    PRINT_MEMBER ("const bool", has_denorm);
 
-    PRINT_MEMBER (has_infinity);
-    PRINT_MEMBER (has_quiet_NaN);
-    PRINT_MEMBER (has_signaling_NaN);
-    PRINT_MEMBER (has_denorm);
+    PRINT_MEMBER ("const bool", has_denorm_loss);
 
-    PRINT_MEMBER (has_denorm_loss);
+    PRINT_MEMBER (tname, infinity ());
+    PRINT_MEMBER (tname, quiet_NaN ());
+    PRINT_MEMBER (tname, signaling_NaN ());
+    PRINT_MEMBER (tname, denorm_min ());
 
-    PRINT_MEMBER (infinity ());
-    PRINT_MEMBER (quiet_NaN ());
-    PRINT_MEMBER (signaling_NaN ());
-    PRINT_MEMBER (denorm_min ());
+    PRINT_MEMBER ("const bool", is_iec559);
+    PRINT_MEMBER ("const bool", is_bounded);
+    PRINT_MEMBER ("const bool", is_modulo);
 
-    PRINT_MEMBER (is_iec559);
-    PRINT_MEMBER (is_bounded);
-    PRINT_MEMBER (is_modulo);
+    PRINT_MEMBER ("const bool", traps);
+    PRINT_MEMBER ("const bool", tinyness_before);
 
-    PRINT_MEMBER (traps);
-    PRINT_MEMBER (tinyness_before);
+    PRINT_MEMBER ("const int", round_style);
 
-    PRINT_MEMBER (round_style);
+    strm << "};\n";
 }
 
+
 int main ()
 {
-    print_limits<double>(std::cout, "double", 0.0);
+#define PRINT_LIMITS(T) print_limits (std::cout, #T, T ())
+
+    // print bool values as "false" and "true"
+    std::cout.setf (std::cout.boolalpha);
+
+    // print the numeric limits for an integer type
+    PRINT_LIMITS (int);
+
+    std::cout << '\n';
+
+    // print the numeric limits for a floating point type
+    PRINT_LIMITS (double);
 
     return 0;
 }

Modified: incubator/stdcxx/trunk/examples/manual/out/limits.out
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/examples/manual/out/limits.out?rev=429712&r1=429711&r2=429712&view=diff
==============================================================================
--- incubator/stdcxx/trunk/examples/manual/out/limits.out (original)
+++ incubator/stdcxx/trunk/examples/manual/out/limits.out Tue Aug  8 09:27:36 2006
@@ -1,30 +1,65 @@
-std::numeric_limits<double>::is_specialized = 1
-std::numeric_limits<double>::min () = 2.22507e-308
-std::numeric_limits<double>::max () = 1.79769e+308
-std::numeric_limits<double>::digits = 53
-std::numeric_limits<double>::digits10 = 15
-std::numeric_limits<double>::is_signed = 1
-std::numeric_limits<double>::is_integer = 0
-std::numeric_limits<double>::is_exact = 0
-std::numeric_limits<double>::radix = 2
-std::numeric_limits<double>::epsilon () = 2.22045e-16
-std::numeric_limits<double>::round_error () = 0.5
-std::numeric_limits<double>::min_exponent = -1021
-std::numeric_limits<double>::min_exponent10 = -307
-std::numeric_limits<double>::max_exponent = 1024
-std::numeric_limits<double>::max_exponent10 = 308
-std::numeric_limits<double>::has_infinity = 1
-std::numeric_limits<double>::has_quiet_NaN = 1
-std::numeric_limits<double>::has_signaling_NaN = 1
-std::numeric_limits<double>::has_denorm = 1
-std::numeric_limits<double>::has_denorm_loss = 0
-std::numeric_limits<double>::infinity () = inf
-std::numeric_limits<double>::quiet_NaN () = nan
-std::numeric_limits<double>::signaling_NaN () = nan
-std::numeric_limits<double>::denorm_min () = 4.94066e-324
-std::numeric_limits<double>::is_iec559 = 1
-std::numeric_limits<double>::is_bounded = 1
-std::numeric_limits<double>::is_modulo = 0
-std::numeric_limits<double>::traps = 1
-std::numeric_limits<double>::tinyness_before = 0
-std::numeric_limits<double>::round_style = 1
+struct std::numeric_limits<int> {
+    static const bool is_specialized = true;
+    static int min () = -2147483648;
+    static int max () = 2147483647;
+    static const int digits = 31;
+    static const int digits10 = 9;
+    static const bool is_signed = true;
+    static const bool is_integer = true;
+    static const bool is_exact = true;
+    static const int radix = 2;
+    static int epsilon () = 0;
+    static int round_error () = 0;
+    static const int min_exponent = 0;
+    static const int min_exponent10 = 0;
+    static const int max_exponent = 0;
+    static const int max_exponent10 = 0;
+    static const bool has_infinity = false;
+    static const bool has_quiet_NaN = false;
+    static const bool has_signaling_NaN = false;
+    static const bool has_denorm = 0;
+    static const bool has_denorm_loss = false;
+    static int infinity () = 0;
+    static int quiet_NaN () = 0;
+    static int signaling_NaN () = 0;
+    static int denorm_min () = 0;
+    static const bool is_iec559 = false;
+    static const bool is_bounded = true;
+    static const bool is_modulo = true;
+    static const bool traps = true;
+    static const bool tinyness_before = false;
+    static const int round_style = 0;
+}
+
+struct std::numeric_limits<double> {
+    static const bool is_specialized = true;
+    static double min () = 2.22507e-308;
+    static double max () = 1.79769e+308;
+    static const int digits = 53;
+    static const int digits10 = 15;
+    static const bool is_signed = true;
+    static const bool is_integer = false;
+    static const bool is_exact = false;
+    static const int radix = 2;
+    static double epsilon () = 2.22045e-16;
+    static int round_error () = 0.5;
+    static const int min_exponent = -1021;
+    static const int min_exponent10 = -307;
+    static const int max_exponent = 1024;
+    static const int max_exponent10 = 308;
+    static const bool has_infinity = true;
+    static const bool has_quiet_NaN = true;
+    static const bool has_signaling_NaN = true;
+    static const bool has_denorm = 1;
+    static const bool has_denorm_loss = false;
+    static double infinity () = inf;
+    static double quiet_NaN () = nan;
+    static double signaling_NaN () = nan;
+    static double denorm_min () = 4.94066e-324;
+    static const bool is_iec559 = true;
+    static const bool is_bounded = true;
+    static const bool is_modulo = false;
+    static const bool traps = false;
+    static const bool tinyness_before = false;
+    static const int round_style = 1;
+}



Mime
View raw message