• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5<title>FAQ</title>
6<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
8<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
9<link rel="up" href="../boost_units.html" title="Chapter 43. Boost.Units 1.1.0">
10<link rel="prev" href="Installation.html" title="Installation">
11<link rel="next" href="Acknowledgements.html" title="Acknowledgements">
12</head>
13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
14<table cellpadding="2" width="100%"><tr>
15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
16<td align="center"><a href="../../../index.html">Home</a></td>
17<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
20<td align="center"><a href="../../../more/index.htm">More</a></td>
21</tr></table>
22<hr>
23<div class="spirit-nav">
24<a accesskey="p" href="Installation.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_units.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="Acknowledgements.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
25</div>
26<div class="section">
27<div class="titlepage"><div><div><h2 class="title" style="clear: both">
28<a name="boost_units.FAQ"></a><a class="link" href="FAQ.html" title="FAQ">FAQ</a>
29</h2></div></div></div>
30<div class="toc"><dl class="toc">
31<dt><span class="section"><a href="FAQ.html#boost_units.FAQ.Distinguishing_Quantities_With_Same_Units">How
32      does one distinguish between quantities that are physically different but have
33      the same units (such as energy and torque)?</a></span></dt>
34<dt><span class="section"><a href="FAQ.html#boost_units.FAQ.Angle_Are_Units">Angles are treated as
35      units</a></span></dt>
36<dt><span class="section"><a href="FAQ.html#boost_units.FAQ.Why_Homogeneous_Systems">Why are there
37      homogeneous systems? Aren't heterogeneous systems sufficient?</a></span></dt>
38<dt><span class="section"><a href="FAQ.html#boost_units.FAQ.NoConstructorFromValueType">Why can't
39      I construct a quantity directly from the value type?</a></span></dt>
40<dt><span class="section"><a href="FAQ.html#boost_units.FAQ.ExplicitConversions">Why are conversions
41      explicit by default?</a></span></dt>
42</dl></div>
43<div class="section">
44<div class="titlepage"><div><div><h3 class="title">
45<a name="boost_units.FAQ.Distinguishing_Quantities_With_Same_Units"></a><a class="link" href="FAQ.html#boost_units.FAQ.Distinguishing_Quantities_With_Same_Units" title="How does one distinguish between quantities that are physically different but have the same units (such as energy and torque)?">How
46      does one distinguish between quantities that are physically different but have
47      the same units (such as energy and torque)?</a>
48</h3></div></div></div>
49<p>
50        Because Boost.Units includes plane and solid angle units in the SI system,
51        torque and energy are, in fact, distinguishable (see <a href="http://en.wikipedia.org/wiki/SI_units" target="_top">torque</a>).
52        In addition, energy is a true <a href="http://mathworld.wolfram.com/Scalar.html" target="_top">scalar</a>
53        quantity, while torque, despite having the same units as energy if plane
54        angle is not included, is in fact a <a href="http://mathworld.wolfram.com/Pseudovector.html" target="_top">pseudovector</a>.
55        Thus, a value type representing pseudovectors and encapsulating their algebra
56        could also be implemented.
57      </p>
58<p>
59        There are, however, a few SI units that are dimensionally indistinguishable
60        within the SI system. These include the <a href="http://en.wikipedia.org/wiki/Becquerel" target="_top">becquerel</a>,
61        which has units identical to frequency (Hz), and the <a href="http://en.wikipedia.org/wiki/Sievert" target="_top">sievert</a>,
62        which is degenerate with the <a href="http://en.wikipedia.org/wiki/Gray_%28unit%29" target="_top">gray</a>.
63        In cases such as this, the proper way to treat this difference is to recognize
64        that expanding the set of base dimensions can provide disambiguation. For
65        example, adding a base dimension for radioactive decays would allow the becquerel
66        to be written as decays/second, differentiating it from the signature of
67        hertz, which is simply 1/second.
68      </p>
69</div>
70<div class="section">
71<div class="titlepage"><div><div><h3 class="title">
72<a name="boost_units.FAQ.Angle_Are_Units"></a><a class="link" href="FAQ.html#boost_units.FAQ.Angle_Are_Units" title="Angles are treated as units">Angles are treated as
73      units</a>
74</h3></div></div></div>
75<p>
76        If you don't like this, you can just ignore the angle units and go on your
77        merry way (periodically screwing up when a routine wants degrees and you
78        give it radians instead...)
79      </p>
80</div>
81<div class="section">
82<div class="titlepage"><div><div><h3 class="title">
83<a name="boost_units.FAQ.Why_Homogeneous_Systems"></a><a class="link" href="FAQ.html#boost_units.FAQ.Why_Homogeneous_Systems" title="Why are there homogeneous systems? Aren't heterogeneous systems sufficient?">Why are there
84      homogeneous systems? Aren't heterogeneous systems sufficient?</a>
85</h3></div></div></div>
86<p>
87        Consider the following code:
88      </p>
89<pre class="programlisting"><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">asin</span><span class="special">(</span><span class="identifier">sin</span><span class="special">(</span><span class="number">90.0</span> <span class="special">*</span> <span class="identifier">degrees</span><span class="special">));</span>
90</pre>
91<p>
92        What should this print? If only heterogeneous systems are available it would
93        print 1.5708 rad Why? Well, <code class="computeroutput"><span class="identifier">sin</span></code>
94        would return a <code class="computeroutput"><span class="identifier">quantity</span><span class="special">&lt;</span><span class="identifier">dimensionless</span><span class="special">&gt;</span></code>
95        effectively losing the information that degrees are being used. In order
96        to propogate this extra information we need homogeneous systems.
97      </p>
98</div>
99<div class="section">
100<div class="titlepage"><div><div><h3 class="title">
101<a name="boost_units.FAQ.NoConstructorFromValueType"></a><a class="link" href="FAQ.html#boost_units.FAQ.NoConstructorFromValueType" title="Why can't I construct a quantity directly from the value type?">Why can't
102      I construct a quantity directly from the value type?</a>
103</h3></div></div></div>
104<p>
105        This only breaks generic code--which ought to break anyway. The only literal
106        value that ought to be converted to a quantity by generic code is zero, which
107        should be handled by the default constructor. In addition, consider the search
108        and replace problem allowing this poses:
109      </p>
110<pre class="programlisting"><span class="identifier">quantity</span><span class="special">&lt;</span><span class="identifier">si</span><span class="special">::</span><span class="identifier">length</span><span class="special">&gt;</span>    <span class="identifier">q</span><span class="special">(</span><span class="number">1.0</span><span class="special">);</span>
111</pre>
112<p>
113        Here, the intent is clear - we want a length of one in the SI system, which
114        is one meter. However, imagine some well-intentioned coder attempting to
115        reuse this code, but to have it perform the calculations in the CGS unit
116        system instead. After searching for <code class="computeroutput"><span class="identifier">si</span><span class="special">::</span></code> and replacing it with <code class="computeroutput"><span class="identifier">cgs</span><span class="special">::</span></code> , we have:
117      </p>
118<pre class="programlisting"><span class="identifier">quantity</span><span class="special">&lt;</span><span class="identifier">cgs</span><span class="special">::</span><span class="identifier">length</span><span class="special">&gt;</span>	<span class="identifier">q</span><span class="special">(</span><span class="number">1.0</span><span class="special">);</span>
119</pre>
120<p>
121        Unfortunately, the meaning of this statement has suddenly changed from one
122        meter to one centimeter. In contrast, as implemented, we begin with:
123      </p>
124<pre class="programlisting"><span class="identifier">quantity</span><span class="special">&lt;</span><span class="identifier">si</span><span class="special">::</span><span class="identifier">length</span><span class="special">&gt;</span>	<span class="identifier">q</span><span class="special">(</span><span class="number">1.0</span><span class="special">*</span><span class="identifier">si</span><span class="special">::</span><span class="identifier">meter</span><span class="special">);</span>
125</pre>
126<p>
127        and, after search and replace:
128      </p>
129<pre class="programlisting"><span class="identifier">quantity</span><span class="special">&lt;</span><span class="identifier">cgs</span><span class="special">::</span><span class="identifier">length</span><span class="special">&gt;</span>	<span class="identifier">q</span><span class="special">(</span><span class="number">1.0</span><span class="special">*</span><span class="identifier">cgs</span><span class="special">::</span><span class="identifier">meter</span><span class="special">);</span>
130</pre>
131<p>
132        which gives us an error. Even if the code has a @using namespace boost::units::si;
133        declaration, the latter is still safe, with:
134      </p>
135<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">units</span><span class="special">::</span><span class="identifier">si</span><span class="special">;</span>
136<span class="identifier">quantity</span><span class="special">&lt;</span><span class="identifier">length</span><span class="special">&gt;</span>	<span class="identifier">q</span><span class="special">(</span><span class="number">1.0</span><span class="special">*</span><span class="identifier">meter</span><span class="special">);</span>
137</pre>
138<p>
139        going to
140      </p>
141<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">units</span><span class="special">::</span><span class="identifier">cgs</span><span class="special">;</span>
142<span class="identifier">quantity</span><span class="special">&lt;</span><span class="identifier">length</span><span class="special">&gt;</span>	<span class="identifier">q</span><span class="special">(</span><span class="number">1.0</span><span class="special">*</span><span class="identifier">meter</span><span class="special">);</span>
143</pre>
144<p>
145        The latter will involve an explicit conversion from meters to centimeters,
146        but the value remains correct.
147      </p>
148</div>
149<div class="section">
150<div class="titlepage"><div><div><h3 class="title">
151<a name="boost_units.FAQ.ExplicitConversions"></a><a class="link" href="FAQ.html#boost_units.FAQ.ExplicitConversions" title="Why are conversions explicit by default?">Why are conversions
152      explicit by default?</a>
153</h3></div></div></div>
154<p>
155        Safety and the potential for unintended conversions leading to precision
156        loss and hidden performance costs. Options are provided for forcing implicit
157        conversions between specific units to be allowed.
158      </p>
159</div>
160</div>
161<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
162<td align="left"></td>
163<td align="right"><div class="copyright-footer">Copyright © 2003-2008 Matthias Christian Schabel<br>Copyright © 2007-2010 Steven
164      Watanabe<p>
165        Distributed under the Boost Software License, Version 1.0. (See accompanying
166        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
167      </p>
168</div></td>
169</tr></table>
170<hr>
171<div class="spirit-nav">
172<a accesskey="p" href="Installation.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_units.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="Acknowledgements.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
173</div>
174</body>
175</html>
176