Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/numeric/conversion/doc/bounds.html @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 4.3 KB
Line 
1<HTML>
2  <HEAD>
3         <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
4         <LINK REL="stylesheet" TYPE="text/css" HREF="../../../../boost.css">
5         <TITLE>Boost Numeric Conversion Library - Bounds</TITLE>
6  </HEAD>
7  <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
8         <TABLE BORDER="0" CELLPADDING="7" CELLSPACING="0" WIDTH="100%"
9          SUMMARY="header">
10                <TR>
11                  <TH VALIGN="top" WIDTH="300">
12                         <H3><A HREF="../../../../index.htm"><IMG HEIGHT="86" WIDTH="277"
13                                ALT="C++ Boost" SRC="../../../../boost.png" BORDER="0"></A></H3> </TH> 
14                  <TH VALIGN="top"> 
15                         <H1 ALIGN="center">Boost Numeric Conversion Library</H1> 
16                         
17      <H1><A HREF="http://www.boost.org">Header </A><A
18                                HREF="../../../../boost/numeric/conversion/bounds.hpp">boost/numeric/conversion/bounds.hpp</A></H1>
19    </TH>
20                </TR>
21         </TABLE><HR>
22         <H2>Contents</H2>
23         <UL>
24                <LI><A HREF="#introduction">Introduction</A></LI>
25                <LI><A HREF="#bounds"><code>template class bounds&ltN&gt</CODE></A></LI>
26                <LI><A HREF="#examples">Examples</A></LI>
27                <!--<LI><A HREF="#implementation">Implementation</A></LI>-->
28                <!--<LI><A HREF="#portability">Portability</A></LI>-->
29         </UL> <HR>
30         <H2><A NAME="introduction">Introduction</A></H2>
31         <P>To determine the ranges of numeric types with std:: numeric_limits
32                [18.2.1], different syntax have to be used depending on numeric type.
33                Specifically, numeric_limits&lt;T&gt;::min() for integral types returns the
34                minimum finite value, whereas for floating point types it returns the minimum
35                positive normalized value. The difference in semantics makes client code
36                unnecessarily complex and error prone. <BR> <BR>
37  boost::numeric::bounds&lt;&gt; provides a consistent interface for retrieving
38  the maximum finite value, the minimum finite value and the minimum positive
39  normalized value (0 for integral types) for numeric types. The selection of
40  implementation is performed at compile time, so there is no runtime overhead.
41  <BR>
42   <BR> </P> <HR>
43         <H2><A NAME="bounds"><CODE>traits class bounds&lt;N&gt;</CODE></A></H2>
44         <BLOCKQUOTE>
45
46  <PRE>template&lt;class N&gt;
47struct bounds
48{
49  static N lowest  () { return <i>implementation_defined</i>; }
50  static N highest () { return <i>implementation_defined</i>; }
51  static N smallest() { return <i>implementation_defined</i>; }
52};</PRE>
53   </BLOCKQUOTE>
54         <H3>Members</H3>
55         <PRE>lowest()</PRE>
56         <P>Returns the minimum finite value, equivalent to
57                numeric_limits&lt;T&gt;::min() when T is an integral type, and to
58                -numeric_limits&lt;T&gt;::max() when T is a floating point type. </P>
59         <PRE>highest()</PRE>
60         <P>Returns the maximum finite value, equivalent to
61                numeric_limits&lt;T&gt;::max(). </P>
62         <PRE>smallest()</PRE>
63
64<P>Returns the smallest positive normalized value for floating point types with
65  denormalization, or returns 0 for integral types. <BR>
66   <BR>
67                </P> <HR>
68         <H2><A NAME="examples">Examples</A></H2>
69
70<P>The following example demonstrates the use of numeric::bounds&lt;&gt; and the
71  equivalent code using numeric_limits: </P>
72
73<BLOCKQUOTE>
74  <PRE>#include &lt;iostream&gt;
75
76#include &lt;boost/numeric/conversion/bounds.hpp&gt;
77#include &lt;boost/limits.hpp&gt;
78
79int main() {
80
81  std::cout &lt;&lt; "numeric::bounds versus numeric_limits example.\n";
82
83  std::cout &lt;&lt; "The maximum value for float:\n";
84  std::cout &lt;&lt; boost::numeric::bounds&lt;float&gt;::highest() &lt;&lt; "\n";
85  std::cout &lt;&lt; std::numeric_limits&lt;float&gt;::max() &lt;&lt; "\n";
86
87  std::cout &lt;&lt; "The minimum value for float:\n";
88  std::cout &lt;&lt; boost::numeric::bounds&lt;float&gt;::lowest() &lt;&lt; "\n";
89  std::cout &lt;&lt; -std::numeric_limits&lt;float&gt;::max() &lt;&lt; "\n";
90
91  std::cout &lt;&lt; "The smallest positive value for float:\n";
92  std::cout &lt;&lt; boost::numeric::bounds&lt;float&gt;::smallest() &lt;&lt; "\n";
93  std::cout &lt;&lt; std::numeric_limits&lt;float&gt;::min() &lt;&lt; "\n";
94
95  return 0;
96}</PRE>
97   </BLOCKQUOTE>
98
99<hr>
100<P>Back to <A HREF="index.html">Numeric Conversion library index</A></P>
101<HR>
102<P>Revised 23 June 2004</P>
103<p>© Copyright Fernando Luis Cacciola Carballal, 2004</p>
104<p> Use, modification, and distribution are subject to the Boost Software
105License, Version 1.0. (See accompanying file <a href="../../../../LICENSE_1_0.txt">
106LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
107www.boost.org/LICENSE_1_0.txt</a>)</p>
108</BODY>
109</HTML>
Note: See TracBrowser for help on using the repository browser.