src/utilities/units/Scale.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #include "Scale.hpp" | ||
| 7 | |||
| 8 | namespace openstudio { | ||
| 9 | |||
| 10 | 144 | std::ostream& operator<<(std::ostream& os, const Scale& s) { | |
| 11 | 144 | os << s.name << ", " << s.abbr << ", 10^"; | |
| 12 |
2/2✓ Branch 0 taken 69 times.
✓ Branch 1 taken 75 times.
|
144 | if (s.exponent < 0) { |
| 13 | 69 | os << "{" << s.exponent << "}"; | |
| 14 | } else { | ||
| 15 | 75 | os << s.exponent; | |
| 16 | } | ||
| 17 | 144 | os << " = " << s.value; | |
| 18 | |||
| 19 | 144 | return os; | |
| 20 | } | ||
| 21 | |||
| 22 | 55 | bool operator==(const Scale& firstScale, const Scale& secondScale) { | |
| 23 |
4/4✓ Branch 0 taken 54 times.
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 53 times.
✓ Branch 4 taken 1 time.
|
55 | return ((firstScale.exponent == secondScale.exponent) && (firstScale.abbr == secondScale.abbr)); |
| 24 | } | ||
| 25 | |||
| 26 | 53 | bool operator!=(const Scale& firstScale, const Scale& secondScale) { | |
| 27 | 53 | return !(firstScale == secondScale); | |
| 28 | } | ||
| 29 | |||
| 30 | 1 | bool operator<(const Scale& firstScale, const Scale& secondScale) { | |
| 31 | 1 | return (firstScale.exponent < secondScale.exponent); | |
| 32 | } | ||
| 33 | |||
| 34 | 1 | bool operator>(const Scale& firstScale, const Scale& secondScale) { | |
| 35 | 1 | return (firstScale.exponent > secondScale.exponent); | |
| 36 | } | ||
| 37 | |||
| 38 | 1 | bool operator<=(const Scale& firstScale, const Scale& secondScale) { | |
| 39 | 1 | return (firstScale.exponent <= secondScale.exponent); | |
| 40 | } | ||
| 41 | |||
| 42 | 1 | bool operator>=(const Scale& firstScale, const Scale& secondScale) { | |
| 43 | 1 | return (firstScale.exponent >= secondScale.exponent); | |
| 44 | } | ||
| 45 | |||
| 46 | /** Static constant indicating that the scale was not found. To test for it, | ||
| 47 | * check that value == 0. */ | ||
| 48 | 9 | const Scale& notDefined() { | |
| 49 |
3/4✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
|
9 | static const Scale ND = {"ND", "Not Defined", 0, 0.0}; |
| 50 | 9 | return ND; | |
| 51 | } | ||
| 52 | |||
| 53 | /** Static constant defining SI prefix for 10^24. */ | ||
| 54 | 3881 | const Scale& yotta() { | |
| 55 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 1994 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3881 | static const Scale Y = {"Y", "yotta", 24, 1.0E24}; |
| 56 | 3881 | return Y; | |
| 57 | } | ||
| 58 | |||
| 59 | /** Static constant defining SI prefix for 10^21. */ | ||
| 60 | 3881 | const Scale& zetta() { | |
| 61 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 1994 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3881 | static const Scale Z = {"Z", "zetta", 21, 1.0E21}; |
| 62 | 3881 | return Z; | |
| 63 | } | ||
| 64 | |||
| 65 | /** Static constant defining SI prefix for 10^18. */ | ||
| 66 | 3881 | const Scale& exa() { | |
| 67 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 1994 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3881 | static const Scale E = {"E", "exa", 18, 1.0E18}; |
| 68 | 3881 | return E; | |
| 69 | } | ||
| 70 | |||
| 71 | /** Static constant defining SI prefix for 10^15. */ | ||
| 72 | 3885 | const Scale& peta() { | |
| 73 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 1998 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3885 | static const Scale P = {"P", "peta", 15, 1.0E15}; |
| 74 | 3885 | return P; | |
| 75 | } | ||
| 76 | |||
| 77 | /** Static constant defining SI prefix for 10^12. */ | ||
| 78 | 3881 | const Scale& tera() { | |
| 79 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 1994 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3881 | static const Scale T = {"T", "tera", 12, 1.0E12}; |
| 80 | 3881 | return T; | |
| 81 | } | ||
| 82 | |||
| 83 | /** Static constant defining SI prefix for 10^9. */ | ||
| 84 | 3916 | const Scale& giga() { | |
| 85 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 2029 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3916 | static const Scale G = {"G", "giga", 9, 1.0E9}; |
| 86 | 3916 | return G; | |
| 87 | } | ||
| 88 | |||
| 89 | /** Static constant defining SI prefix for 10^6. */ | ||
| 90 | 4487 | const Scale& mega() { | |
| 91 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 2600 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
4487 | static const Scale M = {"M", "mega", 6, 1.0E6}; |
| 92 | 4487 | return M; | |
| 93 | } | ||
| 94 | |||
| 95 | /** Static constant defining SI prefix for 10^5. */ | ||
| 96 | 3880 | UTILITIES_API const Scale& hectokilo() { | |
| 97 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 1993 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3880 | static const Scale hk = {"_hk", "hectokilo", 5, 1.0E5}; |
| 98 | 3880 | return hk; | |
| 99 | } | ||
| 100 | |||
| 101 | /** Static constant defining SI prefix for 10^4. */ | ||
| 102 | 3906 | const Scale& myria() { | |
| 103 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 2019 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3906 | static const Scale k = {"_ma", "myria", 4, 1.0E4}; |
| 104 | 3906 | return k; | |
| 105 | } | ||
| 106 | |||
| 107 | /** Static constant defining SI prefix for 10^3. */ | ||
| 108 | 4340 | const Scale& kilo() { | |
| 109 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 2453 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
4340 | static const Scale k = {"k", "kilo", 3, 1.0E3}; |
| 110 | 4340 | return k; | |
| 111 | } | ||
| 112 | |||
| 113 | /** Static constant defining SI prefix for 10^2. */ | ||
| 114 | 3896 | UTILITIES_API const Scale& hecto() { | |
| 115 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 2009 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3896 | static const Scale h = {"_h", "hecto", 2, 1.0E2}; |
| 116 | 3896 | return h; | |
| 117 | } | ||
| 118 | |||
| 119 | /** Static constant defining SI prefix for 10^1. */ | ||
| 120 | 3881 | UTILITIES_API const Scale& deka() { | |
| 121 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 1994 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3881 | static const Scale da = {"_da", "deka", 1, 1.0E1}; |
| 122 | 3881 | return da; | |
| 123 | } | ||
| 124 | |||
| 125 | /** Static constant defining no scale (1.0). */ | ||
| 126 | 228464 | const Scale& one() { | |
| 127 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 226577 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
228464 | static const Scale o = {"", "", 0, 1.0}; |
| 128 | 228464 | return o; | |
| 129 | } | ||
| 130 | |||
| 131 | /** Static constant defining SI prefix for 10^{-1} */ | ||
| 132 | 3881 | const Scale& deci() { | |
| 133 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 1994 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3881 | static const Scale d = {"_d", "deci", -1, 1.0E-1}; |
| 134 | 3881 | return d; | |
| 135 | } | ||
| 136 | |||
| 137 | /** Static constant defining SI prefix for 10^{-2} */ | ||
| 138 | 4034 | const Scale& centi() { | |
| 139 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 2147 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
4034 | static const Scale c = {"c", "centi", -2, 1.0E-2}; |
| 140 | 4034 | return c; | |
| 141 | } | ||
| 142 | |||
| 143 | /** Static constant defining SI prefix for 10^{-3} */ | ||
| 144 | 4193 | const Scale& milli() { | |
| 145 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 2306 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
4193 | static const Scale m = {"m", "milli", -3, 1.0E-3}; |
| 146 | 4193 | return m; | |
| 147 | } | ||
| 148 | |||
| 149 | /** Static constant defining SI prefix for 10^{-4} */ | ||
| 150 | 3949 | const Scale& decimilli() { | |
| 151 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 2062 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3949 | static const Scale dm = {"_dm", "decimilli", -4, 1.0E-4}; |
| 152 | 3949 | return dm; | |
| 153 | } | ||
| 154 | |||
| 155 | /** Static constant defining SI prefix for 10^{-5} */ | ||
| 156 | 3880 | const Scale& centimilli() { | |
| 157 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 1993 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3880 | static const Scale cm = {"_cm", "centimilli", -5, 1.0E-5}; |
| 158 | 3880 | return cm; | |
| 159 | } | ||
| 160 | |||
| 161 | /** Static constant defining SI prefix for 10^{-6} */ | ||
| 162 | 4414 | const Scale& micro() { | |
| 163 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 2527 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
4414 | static const Scale mu = {"\\mu", "micro", -6, 1.0E-6}; |
| 164 | 4414 | return mu; | |
| 165 | } | ||
| 166 | |||
| 167 | /** Static constant defining SI prefix for 10^{-9} */ | ||
| 168 | 3908 | const Scale& nano() { | |
| 169 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 2021 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3908 | static const Scale n = {"n", "nano", -9, 1.0E-9}; |
| 170 | 3908 | return n; | |
| 171 | } | ||
| 172 | |||
| 173 | /** Static constant defining SI prefix for 10^{-12} */ | ||
| 174 | 3890 | const Scale& pico() { | |
| 175 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 2003 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3890 | static const Scale p = {"p", "pico", -12, 1.0E-12}; |
| 176 | 3890 | return p; | |
| 177 | } | ||
| 178 | |||
| 179 | /** Static constant defining SI prefix for 10^{-15} */ | ||
| 180 | 3881 | const Scale& femto() { | |
| 181 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 1994 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3881 | static const Scale f = {"f", "femto", -15, 1.0E-15}; |
| 182 | 3881 | return f; | |
| 183 | } | ||
| 184 | |||
| 185 | /** Static constant defining SI prefix for 10^{-18) */ | ||
| 186 | 3881 | const Scale& atto() { | |
| 187 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 1994 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3881 | static const Scale a = {"a", "atto", -18, 1.0E-18}; |
| 188 | 3881 | return a; | |
| 189 | } | ||
| 190 | |||
| 191 | /** Static constant defining SI prefix for 10^{-21} */ | ||
| 192 | 3881 | const Scale& zepto() { | |
| 193 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 1994 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3881 | static const Scale z = {"z", "zepto", -21, 1.0E-21}; |
| 194 | 3881 | return z; | |
| 195 | } | ||
| 196 | |||
| 197 | /** Static constant defining SI prefix for 10^{-24} */ | ||
| 198 | 3881 | const Scale& yocto() { | |
| 199 |
3/4✓ Branch 0 taken 1887 times.
✓ Branch 1 taken 1994 times.
✓ Branch 3 taken 1887 times.
✗ Branch 4 not taken.
|
3881 | static const Scale y = {"y", "yocto", -24, 1.0E-24}; |
| 200 | 3881 | return y; | |
| 201 | } | ||
| 202 | |||
| 203 | } // namespace openstudio | ||
| 204 |