1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
2 // unit/quantity manipulation and conversion
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2007-2008 Steven Watanabe
7 // Distributed under the Boost Software License, Version 1.0. (See
8 // accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_UNITS_SCALE_HPP_INCLUDED
12 #define BOOST_UNITS_SCALE_HPP_INCLUDED
16 #include <boost/units/config.hpp>
17 #include <boost/units/static_rational.hpp>
18 #include <boost/units/units_fwd.hpp>
19 #include <boost/units/detail/one.hpp>
20 #include <boost/units/detail/static_rational_power.hpp>
26 template<class S
, class Scale
>
27 struct scaled_base_unit
;
29 /// class representing a scaling factor such as 10^3
30 /// The exponent should be a static rational.
31 template<long Base
, class Exponent
>
34 static const long base
= Base
;
35 typedef Exponent exponent
;
36 typedef double value_type
;
37 static value_type
value() { return(detail::static_rational_power
<Exponent
>(static_cast<double>(base
))); }
38 static std::string
name() { return ""; };
39 static std::string
symbol() { return ""; };
42 template<long Base
, class Exponent
>
43 const long scale
<Base
, Exponent
>::base
;
47 struct scale
<Base
, static_rational
<0> >
49 static const long base
= Base
;
50 typedef static_rational
<0> exponent
;
51 typedef one value_type
;
52 static one
value() { one result
; return(result
); }
53 static std::string
name() { return(""); }
54 static std::string
symbol() { return(""); }
58 const long scale
<Base
, static_rational
<0> >::base
;
60 template<long Base
,class Exponent
>
61 std::string
symbol_string(const scale
<Base
,Exponent
>&)
63 return scale
<Base
,Exponent
>::symbol();
66 template<long Base
,class Exponent
>
67 std::string
name_string(const scale
<Base
,Exponent
>&)
69 return scale
<Base
,Exponent
>::name();
72 #ifndef BOOST_UNITS_DOXYGEN
74 #define BOOST_UNITS_SCALE_SPECIALIZATION(base_,exponent_,val_,name_,symbol_) \
76 struct scale<base_, exponent_ > \
78 static const long base = base_; \
79 typedef exponent_ exponent; \
80 typedef double value_type; \
81 static value_type value() { return(val_); } \
82 static std::string name() { return(#name_); } \
83 static std::string symbol() { return(#symbol_); } \
86 #define BOOST_UNITS_SCALE_DEF(exponent_,value_,name_,symbol_) \
87 BOOST_UNITS_SCALE_SPECIALIZATION(10,static_rational<exponent_>,value_, name_, symbol_)
89 BOOST_UNITS_SCALE_DEF(-24, 1e-24 ,yocto
, y
);
90 BOOST_UNITS_SCALE_DEF(-21, 1e-21, zepto
, z
);
91 BOOST_UNITS_SCALE_DEF(-18, 1e-18, atto
, a
);
92 BOOST_UNITS_SCALE_DEF(-15, 1e-15, femto
, f
);
93 BOOST_UNITS_SCALE_DEF(-12, 1e-12, pico
, p
);
94 BOOST_UNITS_SCALE_DEF(-9, 1e-9, nano
, n
);
95 BOOST_UNITS_SCALE_DEF(-6, 1e-6, micro
, u
);
96 BOOST_UNITS_SCALE_DEF(-3, 1e-3, milli
, m
);
97 BOOST_UNITS_SCALE_DEF(-2, 1e-2, centi
, c
);
98 BOOST_UNITS_SCALE_DEF(-1, 1e-1, deci
, d
);
100 BOOST_UNITS_SCALE_DEF(1, 1e1
, deka
, da
);
101 BOOST_UNITS_SCALE_DEF(2, 1e2
, hecto
, h
);
102 BOOST_UNITS_SCALE_DEF(3, 1e3
, kilo
, k
);
103 BOOST_UNITS_SCALE_DEF(6, 1e6
, mega
, M
);
104 BOOST_UNITS_SCALE_DEF(9, 1e9
, giga
, G
);
105 BOOST_UNITS_SCALE_DEF(12, 1e12
, tera
, T
);
106 BOOST_UNITS_SCALE_DEF(15, 1e15
, peta
, P
);
107 BOOST_UNITS_SCALE_DEF(18, 1e18
, exa
, E
);
108 BOOST_UNITS_SCALE_DEF(21, 1e21
, zetta
, Z
);
109 BOOST_UNITS_SCALE_DEF(24, 1e24
, yotta
, Y
);
111 BOOST_UNITS_SCALE_SPECIALIZATION(2, static_rational
<10>, 1024.0, kibi
, Ki
);
112 BOOST_UNITS_SCALE_SPECIALIZATION(2, static_rational
<20>, 1048576.0, mebi
, Mi
);
113 BOOST_UNITS_SCALE_SPECIALIZATION(2, static_rational
<30>, 1073741824.0, gibi
, Gi
);
114 BOOST_UNITS_SCALE_SPECIALIZATION(2, static_rational
<40>, 1099511627776.0, tebi
, Ti
);
115 BOOST_UNITS_SCALE_SPECIALIZATION(2, static_rational
<50>, 1125899906842624.0, pebi
, Pi
);
116 BOOST_UNITS_SCALE_SPECIALIZATION(2, static_rational
<60>, 1152921504606846976.0, exbi
, Ei
);
118 #undef BOOST_UNITS_SCALE_DEF
119 #undef BOOST_UNITS_SCALE_SPECIALIZATION
127 #if BOOST_UNITS_HAS_BOOST_TYPEOF
129 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
131 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::units::scale
, (long)(class))