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<N></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<T>::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<> 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<N></CODE></A></H2> |
---|
44 | <BLOCKQUOTE> |
---|
45 | |
---|
46 | <PRE>template<class N> |
---|
47 | struct 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<T>::min() when T is an integral type, and to |
---|
58 | -numeric_limits<T>::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<T>::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<> and the |
---|
71 | equivalent code using numeric_limits: </P> |
---|
72 | |
---|
73 | <BLOCKQUOTE> |
---|
74 | <PRE>#include <iostream> |
---|
75 | |
---|
76 | #include <boost/numeric/conversion/bounds.hpp> |
---|
77 | #include <boost/limits.hpp> |
---|
78 | |
---|
79 | int main() { |
---|
80 | |
---|
81 | std::cout << "numeric::bounds versus numeric_limits example.\n"; |
---|
82 | |
---|
83 | std::cout << "The maximum value for float:\n"; |
---|
84 | std::cout << boost::numeric::bounds<float>::highest() << "\n"; |
---|
85 | std::cout << std::numeric_limits<float>::max() << "\n"; |
---|
86 | |
---|
87 | std::cout << "The minimum value for float:\n"; |
---|
88 | std::cout << boost::numeric::bounds<float>::lowest() << "\n"; |
---|
89 | std::cout << -std::numeric_limits<float>::max() << "\n"; |
---|
90 | |
---|
91 | std::cout << "The smallest positive value for float:\n"; |
---|
92 | std::cout << boost::numeric::bounds<float>::smallest() << "\n"; |
---|
93 | std::cout << std::numeric_limits<float>::min() << "\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 |
---|
105 | License, Version 1.0. (See accompanying file <a href="../../../../LICENSE_1_0.txt"> |
---|
106 | LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt"> |
---|
107 | www.boost.org/LICENSE_1_0.txt</a>)</p> |
---|
108 | </BODY> |
---|
109 | </HTML> |
---|