
std::numeric_limits needs to be implemented for quantity. I think this should work: namespace std { template< typename T, typename U > class numeric_limits< boost::units::quantity<U, T> > : public numeric_limits<T> { typedef numeric_limits<T> type_limits; typedef boost::units::quantity<U, T> qty; public: static qty denorm_min() { return qty(type_limits::denorm_min() * U()); } static qty epsilon() { return qty(type_limits::epsilon() * U()); } static qty infinity() { return qty(type_limits::infinity() * U()); } static qty max() { return qty(type_limits::max() * U()); } static qty min() { return qty(type_limits::min() * U()); } static qty round_error() { return qty(type_limits::round_error() * U()); } static qty quiet_NaN() { return qty(type_limits::quiet_NaN() * U()); } static qty signalizing_NaN() { return qty(type_limits::signaling_NaN() * U()); } }; }

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Noah Roberts Sent: 30 November 2007 21:58 To: boost@lists.boost.org Subject: [boost] units: need limits
std::numeric_limits needs to be implemented for quantity.
Indeed where possible, std::numeric_limits needs to be implemented for ALL types.
I think this should work:
namespace std { template< typename T, typename U > class numeric_limits< boost::units::quantity<U, T> > : public numeric_limits<T> { typedef numeric_limits<T> type_limits; typedef boost::units::quantity<U, T> qty; public: static qty denorm_min() { return qty(type_limits::denorm_min() * U()); } static qty epsilon() { return qty(type_limits::epsilon() * U()); } static qty infinity() { return qty(type_limits::infinity() * U()); } static qty max() { return qty(type_limits::max() * U()); } static qty min() { return qty(type_limits::min() * U()); } static qty round_error() { return qty(type_limits::round_error() * U()); } static qty quiet_NaN() { return qty(type_limits::quiet_NaN() * U()); } static qty signalizing_NaN() { return qty(type_limits::signaling_NaN() * U()); } }; }
What about the has_* things like has_infinity? Should these be 'propagated'? One might use NTL RR arbitrary precision for example with units, or even an integral type, for which some of these things are not defined - and difficult to define? (Actually it would nice if someone could implement units for NTL or implement a higher precision floating point type with limits). Paul --- Paul A Bristow Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB +44 1539561830 & SMS, Mobile +44 7714 330204 & SMS pbristow@hetp.u-net.com

Steven Watanabe wrote:
AMDG
std::numeric_limits needs to be implemented for quantity. Indeed where possible, std::numeric_limits needs to be implemented for ALL t
Done.
#include <boost/units/limits.hpp>
I don't see boost::units in either the SVN nor the CVS repository. The one in the vault is old, probably what I'm using. Where do we get updates?

Done.
#include <boost/units/limits.hpp>
I don't see boost::units in either the SVN nor the CVS repository. The one in the vault is old, probably what I'm using. Where do we get updates?
It has not yet been committed to the pre-release branch, so you have to get it from the Sandbox SVN repository. Matthias

Paul A Bristow wrote:
What about the has_* things like has_infinity?
Should these be 'propagated'?
I would think it would just follow whatever exists for the type the quantity is in. If you wanted some other kind of limits and such you could always implement a new type and override limits for that type. In my case, for instance, I am using a "strange_double" that performs floating point comparison in a more sane manner than double.
participants (4)
-
Matthias Schabel
-
Noah Roberts
-
Paul A Bristow
-
Steven Watanabe