Numbers RequirementsWhat we call "number" is the base type of the OrderingThe numbers need to be supplied with an ordering. This ordering
expresses itself by the operators Please note that invalid numbers are not concerned by the order; it can
even be conceptually better if a comparison with these invalid numbers is
always Interval arithmetic involves a lot of comparison to zero. By default,
they are done by comparing the numbers to
namespace user { template<class T> inline bool is_zero(T const &v) { return v == static_cast<T>(0); } template<class T> inline bool is_neg (T const &v) { return v < static_cast<T>(0); } template<class T> inline bool is_pos (T const &v) { return v > static_cast<T>(0); } } Numeric limitsAnother remark about the checking policy. It normally is powerful enough
to handle the exceptional behavior that the basic type could induce; in
particular infinite and invalid numbers (thanks to the four functions
So, to summarize, if you do not rely on the default policy and do not
use Mathematical propertiesEnsuring the numbers are correctly ordered is not enough. The basic operators should also respect some properties depending on the order. Here they are:
The previous properties are also used (and enough) for
RoundingIf you work with a base type and no inexact result is ever computed, you can skip the rest of this paragraph. You can also skip it if you are not interested in the inclusion property (if approximate results are enough). If you are still reading, it is probably because you want to know the basic properties the rounding policy should validate. Whichever operation or function you consider, the following property
should be respected: ConstantsIn order for the trigonometric functions to correctly work, the library need to know the value of the π constant (and also π/2 and 2π). Since these constants may not be representable in the base type, the library does not have to know the exact value: a lower bound and an upper bound are enough. If these values are not provided by the user, the default values will be used: they are integer values (so π is bounded by 3 and 4). Operators and conversionsAs explained at the beginning, the comparison operators should be defined for the base type. The rounding policy defines a lot of functions used by the interval library. So the arithmetic operators do not need to be defined for the base type (unless required by one of the predefined classes). However, there is an exception: the unary minus need to be defined. Moreover, this operator should only provide exact results; it is the reason why the rounding policy does not provide some negation functions. The conversion from Revised 2006-12-24 Copyright © 2002 Guillaume Melquiond, Sylvain Pion, Hervé
Brönnimann, Polytechnic University Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |