GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 77.7% 199 / 0 / 256
Functions: 91.1% 41 / 0 / 45
Branches: 52.5% 227 / 0 / 432

src/utilities/units/Quantity.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 "Quantity.hpp"
7
8 #include "UnitFactory.hpp"
9 #include "ScaleFactory.hpp"
10 #include "IPUnit.hpp"
11 #include "IPUnit_Impl.hpp"
12 #include "TemperatureUnit.hpp"
13 #include "TemperatureUnit_Impl.hpp"
14
15 #include "../math/FloatCompare.hpp"
16
17 #include "../core/Assert.hpp"
18
19 #include <cmath>
20
21 namespace openstudio {
22
23 18497 Quantity::Quantity(const UnitSystem& system) : m_value(0.0), m_units(createDimensionlessUnit(system)) {}
24
25 10395 Quantity::Quantity(double value, const UnitSystem& system) : m_value(value), m_units(createDimensionlessUnit(system)) {}
26
27 631994 Quantity::Quantity(double value, const Unit& units) : m_value(value), m_units(units.clone()) {}
28
29 1842759 Quantity::Quantity(const Quantity& q) : m_value(q.value()), m_units(q.units()) {}
30
31 28198 Quantity& Quantity::operator=(const Quantity& q) {
32
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28198 times.
28198 if (this == &q) {
33 ✗ return *this;
34 }
35
36 28198 m_value = q.value();
37
1/1
✓ Branch 1 taken 28198 times.
28198 m_units = q.units();
38 28198 return *this;
39 }
40
41 2000197 double Quantity::value() const {
42 2000197 return m_value;
43 }
44
45 117785 void Quantity::setValue(double newValue) {
46 117785 m_value = newValue;
47 117785 }
48
49 1872036 Unit Quantity::units() const {
50 1872036 return m_units.clone();
51 }
52
53 29522 UnitSystem Quantity::system() const {
54 29522 return m_units.system();
55 }
56
57 9269 bool Quantity::isTemperature() const {
58
1/1
✓ Branch 1 taken 9269 times.
9269 return m_units.optionalCast<TemperatureUnit>().has_value();
59 }
60
61 837 std::vector<std::string> Quantity::baseUnits() const {
62 837 return m_units.baseUnits();
63 }
64
65 254927 int Quantity::baseUnitExponent(const std::string& baseUnit) const {
66 254927 return m_units.baseUnitExponent(baseUnit);
67 }
68
69 138008 void Quantity::setBaseUnitExponent(const std::string& baseUnit, int exponent) {
70 138008 m_units.setBaseUnitExponent(baseUnit, exponent);
71 138008 }
72
73 10569 std::string Quantity::standardUnitsString(bool withScale) const {
74 10569 return m_units.standardString(withScale);
75 }
76
77 548 std::string Quantity::prettyUnitsString(bool withScale) const {
78 548 return m_units.prettyString(withScale);
79 }
80
81 252 void Quantity::setPrettyUnitsString(const std::string& str) {
82 252 return m_units.setPrettyString(str);
83 }
84
85 20603 Scale Quantity::scale() const {
86 20603 return m_units.scale();
87 }
88
89 240 bool Quantity::setScale(int scaleExponent) {
90
2/2
✓ Branch 1 taken 240 times.
✓ Branch 4 taken 240 times.
240 ScaleConstant candidate = ScaleFactory::instance().createScale(scaleExponent);
91
1/1
✓ Branch 1 taken 240 times.
240 double candidateValue = candidate().value;
92
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 if (candidateValue == 0.0) {
93 ✗ return false;
94 }
95
1/1
✓ Branch 1 taken 240 times.
240 m_value = m_value * (scale().value / candidateValue);
96
1/1
✓ Branch 1 taken 240 times.
240 bool ok = m_units.setScale(scaleExponent);
97
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
✗ Branch 3 not taken.
240 OS_ASSERT(ok);
98 240 return true;
99 240 }
100
101 ✗ bool Quantity::setScale(const std::string& scaleAbbreviation) {
102 ✗ ScaleConstant candidate = ScaleFactory::instance().createScale(scaleAbbreviation);
103 ✗ double candidateValue = candidate().value;
104 ✗ if (candidateValue == 0.0) {
105 ✗ return false;
106 }
107 ✗ m_value = m_value * (scale().value / candidateValue);
108 ✗ bool ok = m_units.setScale(scaleAbbreviation);
109 ✗ OS_ASSERT(ok);
110 ✗ return true;
111 ✗ }
112
113 75 bool Quantity::isAbsolute() const {
114
1/1
✓ Branch 1 taken 75 times.
75 OptionalTemperatureUnit tu = m_units.optionalCast<TemperatureUnit>();
115
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 75 times.
75 if (!tu) {
116 ✗ LOG_AND_THROW("Could not evaluate Quantity::isAbsolute for quantity " << *this << " because it is in system " << system().valueName()
117 << ", not Celsius or Fahrenheit.");
118 }
119
2/2
✓ Branch 1 taken 75 times.
✓ Branch 4 taken 75 times.
150 return tu->isAbsolute();
120 75 }
121
122 14 bool Quantity::isRelative() const {
123 14 return !isAbsolute();
124 }
125
126 7 void Quantity::setAsAbsolute() {
127
1/1
✓ Branch 1 taken 7 times.
7 OptionalTemperatureUnit tu = m_units.optionalCast<TemperatureUnit>();
128
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
7 if (!tu) {
129 ✗ LOG_AND_THROW("Could not Quantity::setAsAbsolute for quantity " << *this << " because it is in system " << system().valueName()
130 << ", not Celsius or Fahrenheit.");
131 }
132
2/2
✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
7 tu->setAsAbsolute();
133 7 }
134
135 13 void Quantity::setAsRelative() {
136
1/1
✓ Branch 1 taken 13 times.
13 OptionalTemperatureUnit tu = m_units.optionalCast<TemperatureUnit>();
137
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
13 if (!tu) {
138 ✗ LOG_AND_THROW("Could not Quantity::setAsRelative for quantity " << *this << " because it is in system " << system().valueName()
139 << ", not Celsius or Fahrenheit.");
140 }
141
2/2
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
13 tu->setAsRelative();
142 13 }
143
144 ✗ void Quantity::lbmToLbf() {
145 ✗ OptionalIPUnit iu = m_units.optionalCast<IPUnit>();
146 ✗ if (!iu) {
147 ✗ LOG_AND_THROW("Cannot convert non-IP quantity " << *this << " in system " << system().valueName() << " from pound-mass to pound-force.");
148 }
149
150 // convert from (value * lb_m^x * ...) to (value * lb_f^x * ...)
151 // lb_m^x * (1/gc)^x = lb_f^x * s^{2x} / ft^x
152 ✗ int x = baseUnitExponent("lb_m");
153 ✗ if (x != 0) {
154 ✗ iu->lbmToLbf();
155 ✗ m_value /= std::pow(IPUnit::gc(), x);
156 }
157 ✗ OS_ASSERT(baseUnitExponent("lb_m") == 0);
158 ✗ }
159
160 ✗ void Quantity::lbfToLbm() {
161 ✗ OptionalIPUnit iu = m_units.optionalCast<IPUnit>();
162 ✗ if (!iu) {
163 ✗ LOG_AND_THROW("Cannot convert non-IP quantity " << *this << " in system " << system().valueName() << " from pound-force to pound-mass.");
164 }
165
166 // convert from (value * lb_f^x * ...) to (value * lb_m^x * ...)
167 // lb_f^x * gc^x = lb_m^x * ft^x / s^{2x}
168 ✗ int x = baseUnitExponent("lb_f");
169 ✗ if (x != 0) {
170 ✗ iu->lbfToLbm();
171 ✗ m_value *= std::pow(IPUnit::gc(), x);
172 }
173 ✗ OS_ASSERT(baseUnitExponent("lb_f") == 0);
174 ✗ }
175
176 // cppcheck-suppress funcArgNamesDifferent
177 16 Quantity& Quantity::operator+=(const Quantity& temp) {
178
179
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 14 times.
16 if (this == &temp) {
180 2 m_value *= 2.0;
181 2 return *this;
182 }
183
184 // copy input reference so we can change its properties
185
1/1
✓ Branch 1 taken 14 times.
14 Quantity rQuantity(temp);
186
187
7/8
✓ Branch 1 taken 14 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 8 times.
✓ Branch 6 taken 6 times.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6 times.
✓ Branch 11 taken 8 times.
14 if (isTemperature() && rQuantity.isTemperature()) {
188
8/8
✓ Branch 1 taken 6 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 6 taken 3 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 1 time.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 4 times.
6 if (!isAbsolute() && rQuantity.isAbsolute()) {
189
1/1
✓ Branch 1 taken 2 times.
2 setAsAbsolute();
190
8/8
✓ Branch 1 taken 4 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1 time.
✓ Branch 6 taken 3 times.
✓ Branch 8 taken 1 time.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 1 time.
✓ Branch 11 taken 3 times.
4 } else if (isAbsolute() && !rQuantity.isAbsolute()) {
191
1/1
✓ Branch 1 taken 1 time.
1 rQuantity.setAsAbsolute();
192 }
193 }
194
195
3/3
✓ Branch 1 taken 14 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 11 times.
14 if (m_units != rQuantity.m_units) {
196
13/13
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
✓ Branch 19 taken 3 times.
✓ Branch 22 taken 3 times.
✓ Branch 25 taken 3 times.
✓ Branch 28 taken 3 times.
✓ Branch 31 taken 3 times.
✓ Branch 34 taken 3 times.
✓ Branch 38 taken 3 times.
✓ Branch 41 taken 3 times.
3 LOG_AND_THROW("Cannot add quantities with different units.");
197 }
198
199
4/5
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 11 times.
11 if (scale() != rQuantity.scale()) {
200 ✗ Quantity wRQuantity(rQuantity);
201 ✗ wRQuantity.setScale(scale().exponent);
202 ✗ m_value += wRQuantity.value();
203 ✗ } else {
204
1/1
✓ Branch 1 taken 11 times.
11 m_value += rQuantity.value();
205 }
206
207 11 return *this;
208 14 }
209
210 // cppcheck-suppress funcArgNamesDifferent
211 14 Quantity& Quantity::operator-=(const Quantity& temp) {
212
213
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (this == &temp) {
214 ✗ m_value = 0.0;
215 ✗ return *this;
216 }
217
218 // copy input reference so we can change its properties
219
1/1
✓ Branch 1 taken 14 times.
14 Quantity rQuantity(temp);
220
221
7/8
✓ Branch 1 taken 14 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 6 times.
✓ Branch 6 taken 8 times.
✓ Branch 8 taken 8 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 8 times.
✓ Branch 11 taken 6 times.
14 if (isTemperature() && rQuantity.isTemperature()) {
222
8/8
✓ Branch 1 taken 8 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 3 times.
✓ Branch 6 taken 5 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 1 time.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 4 times.
8 if (isAbsolute() && rQuantity.isAbsolute()) {
223 // units must be the same, check that exponent on this is 1
224
1/1
✓ Branch 1 taken 4 times.
4 std::vector<std::string> bus = baseUnits();
225
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 4 not taken.
4 OS_ASSERT(bus.size() == 1);
226
3/3
✓ Branch 2 taken 4 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 1 time.
4 if (baseUnitExponent(bus[0]) == 1) {
227
1/1
✓ Branch 1 taken 3 times.
3 setAsRelative();
228
1/1
✓ Branch 1 taken 3 times.
3 rQuantity.setAsRelative();
229 }
230
7/8
✓ Branch 2 taken 4 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 1 time.
✓ Branch 7 taken 3 times.
✓ Branch 9 taken 3 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
✓ Branch 12 taken 1 time.
8 } else if (!isAbsolute() && rQuantity.isAbsolute()) {
231
1/1
✓ Branch 1 taken 3 times.
3 setAsAbsolute();
232
5/8
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 time.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 time.
✗ Branch 11 not taken.
1 } else if (isAbsolute() && !rQuantity.isAbsolute()) {
233
1/1
✓ Branch 1 taken 1 time.
1 rQuantity.setAsAbsolute();
234 }
235 }
236
237
3/3
✓ Branch 1 taken 14 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 12 times.
14 if (m_units != rQuantity.m_units) {
238
13/13
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 19 taken 2 times.
✓ Branch 22 taken 2 times.
✓ Branch 25 taken 2 times.
✓ Branch 28 taken 2 times.
✓ Branch 31 taken 2 times.
✓ Branch 34 taken 2 times.
✓ Branch 38 taken 2 times.
✓ Branch 41 taken 2 times.
2 LOG_AND_THROW("Cannot subtract quantities with different units.");
239 }
240
241
4/5
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 7 taken 12 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 12 times.
12 if (scale() != rQuantity.scale()) {
242 ✗ Quantity wRQuantity(rQuantity);
243 ✗ wRQuantity.setScale(scale().exponent);
244 ✗ m_value -= wRQuantity.value();
245 ✗ } else {
246
1/1
✓ Branch 1 taken 12 times.
12 m_value -= rQuantity.value();
247 }
248
249 12 return *this;
250 14 }
251
252 12 Quantity& Quantity::operator*=(const Quantity& rQuantity) {
253
254 12 ScaleOpReturnType resultScale;
255
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 11 times.
12 if (this == &rQuantity) {
256 1 m_value = std::pow(m_value, 2);
257
1/1
✓ Branch 1 taken 1 time.
1 m_units.pow(2);
258
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 resultScale = openstudio::pow(scale(), 2);
259 } else {
260 // unit *= will throw if m_units is not base-class and rQuantity.m_units is different system
261
9/10
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 9 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 2 times.
✓ Branch 19 taken 9 times.
11 if ((system() != rQuantity.system()) && (system() != UnitSystem::Mixed)) {
262
1/1
✓ Branch 1 taken 2 times.
2 m_units = m_units.cloneToMixed();
263 }
264 // ETH@20100517 ugly workaround for temperature units
265
1/1
✓ Branch 1 taken 11 times.
11 OptionalTemperatureUnit tu1 = m_units.optionalCast<TemperatureUnit>();
266
1/1
✓ Branch 1 taken 11 times.
11 OptionalTemperatureUnit tu2 = rQuantity.m_units.optionalCast<TemperatureUnit>();
267
5/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 9 times.
13 if (tu1 && tu2) {
268
3/3
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
2 *tu1 *= *tu2;
269 } else {
270
1/1
✓ Branch 1 taken 9 times.
9 m_units *= rQuantity.m_units;
271 }
272
1/1
✓ Branch 1 taken 11 times.
11 m_value *= rQuantity.value();
273
3/3
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
11 resultScale = scale() * rQuantity.scale();
274 11 }
275 12 m_value *= resultScale.second;
276
277 12 return *this;
278 12 }
279
280 11 Quantity& Quantity::operator/=(const Quantity& rQuantity) {
281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (this == &rQuantity) {
282 // result = 1
283 ✗ m_units /= rQuantity.m_units;
284 ✗ m_value = 1.0;
285 } else {
286 // unit /= will throw if m_units is not base-class and rQuantity.m_units is different system
287
9/10
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 10 times.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
✗ Branch 17 not taken.
✓ Branch 18 taken 1 time.
✓ Branch 19 taken 10 times.
11 if ((system() != rQuantity.system()) && (system() != UnitSystem::Mixed)) {
288
1/1
✓ Branch 1 taken 1 time.
1 m_units = m_units.cloneToMixed();
289 }
290 // ETH@20100517 ugly workaround for temperature units
291
1/1
✓ Branch 1 taken 11 times.
11 OptionalTemperatureUnit tu1 = m_units.optionalCast<TemperatureUnit>();
292
1/1
✓ Branch 1 taken 11 times.
11 OptionalTemperatureUnit tu2 = rQuantity.m_units.optionalCast<TemperatureUnit>();
293
5/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 8 times.
14 if (tu1 && tu2) {
294
3/3
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
3 *tu1 /= *tu2;
295 } else {
296
1/1
✓ Branch 1 taken 8 times.
8 m_units /= rQuantity.m_units;
297 }
298
1/1
✓ Branch 1 taken 11 times.
11 m_value /= rQuantity.value();
299
3/3
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
11 ScaleOpReturnType resultScale = scale() / rQuantity.scale();
300 11 m_value *= resultScale.second;
301 11 }
302
303 11 return *this;
304 }
305
306 7 Quantity& Quantity::operator*=(double d) {
307 7 m_value *= d;
308 7 return *this;
309 }
310
311 5 Quantity& Quantity::operator/=(double d) {
312 5 m_value /= d;
313 5 return *this;
314 }
315
316 8 Quantity& Quantity::pow(int expNum, int expDenom) {
317 // try unit first--may throw
318
1/1
✓ Branch 1 taken 8 times.
8 m_units.pow(expNum, expDenom);
319
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 ScaleOpReturnType resultScale = openstudio::pow(scale(), expNum, expDenom);
320 8 m_value = std::pow(m_value, double(expNum) / double(expDenom));
321 8 m_value = m_value * resultScale.second;
322
323 8 return *this;
324 8 }
325
326 35 std::ostream& operator<<(std::ostream& os, const Quantity& q) {
327
2/2
✓ Branch 1 taken 35 times.
✓ Branch 4 taken 35 times.
35 os << q.value();
328
1/1
✓ Branch 1 taken 35 times.
35 std::stringstream unitString;
329
1/1
✓ Branch 1 taken 35 times.
35 unitString << q.m_units;
330
3/3
✓ Branch 1 taken 35 times.
✓ Branch 5 taken 30 times.
✓ Branch 6 taken 5 times.
35 if (!unitString.str().empty()) {
331
3/3
✓ Branch 1 taken 30 times.
✓ Branch 4 taken 30 times.
✓ Branch 7 taken 30 times.
30 os << " " << unitString.str();
332 }
333 35 return os;
334 35 }
335
336 2 Quantity operator-(const Quantity& rQuantity) {
337 2 Quantity result(rQuantity);
338
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 result.setValue(-result.value());
339 2 return result;
340 ✗ }
341
342 13 Quantity operator+(const Quantity& lQuantity, const Quantity& rQuantity) {
343 13 Quantity result(lQuantity);
344
1/1
✓ Branch 1 taken 10 times.
13 result += rQuantity;
345 10 return result;
346 3 }
347
348 11 Quantity operator-(const Quantity& lQuantity, const Quantity& rQuantity) {
349 11 Quantity result(lQuantity);
350
1/1
✓ Branch 1 taken 9 times.
11 result -= rQuantity;
351 9 return result;
352 2 }
353
354 9 Quantity operator*(const Quantity& lQuantity, const Quantity& rQuantity) {
355 9 Quantity result(lQuantity);
356
1/1
✓ Branch 1 taken 9 times.
9 result *= rQuantity;
357 9 return result;
358 ✗ }
359
360 9 Quantity operator/(const Quantity& lQuantity, const Quantity& rQuantity) {
361 9 Quantity result(lQuantity);
362
1/1
✓ Branch 1 taken 9 times.
9 result /= rQuantity;
363 9 return result;
364 ✗ }
365
366 5 Quantity pow(const Quantity& rQuantity, int expNum, int expDenom) {
367 5 Quantity result(rQuantity);
368 // cppcheck-suppress ignoredReturnValue
369
1/1
✓ Branch 1 taken 5 times.
5 result.pow(expNum, expDenom);
370 5 return result;
371 ✗ }
372
373 6 Quantity operator*(const Quantity& lQuantity, double d) {
374 6 Quantity result(lQuantity);
375
1/1
✓ Branch 1 taken 6 times.
6 result *= d;
376 6 return result;
377 ✗ }
378
379 3 Quantity operator*(double d, const Quantity& rQuantity) {
380 3 return rQuantity * d;
381 }
382
383 5 Quantity operator/(const Quantity& lQuantity, double d) {
384 5 Quantity result(lQuantity);
385
1/1
✓ Branch 1 taken 5 times.
5 result /= d;
386 5 return result;
387 ✗ }
388
389 2 Quantity operator/(double d, const Quantity& rQuantity) {
390
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 Quantity result(d, rQuantity.system());
391
1/1
✓ Branch 1 taken 2 times.
2 result /= rQuantity;
392 2 return result;
393 ✗ }
394
395 36 bool operator==(const Quantity& lQuantity, const Quantity& rQuantity) {
396
10/19
✓ Branch 1 taken 36 times.
✓ Branch 4 taken 36 times.
✓ Branch 7 taken 36 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 36 times.
✓ Branch 13 taken 36 times.
✓ Branch 16 taken 36 times.
✓ Branch 18 taken 36 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 36 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 36 times.
✗ Branch 24 not taken.
✓ Branch 26 taken 36 times.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
36 if ((lQuantity.system() == rQuantity.system()) && (lQuantity.units() == rQuantity.units())) {
397
1/1
✓ Branch 1 taken 36 times.
36 Quantity wl(lQuantity);
398
1/1
✓ Branch 1 taken 36 times.
36 Quantity wr(rQuantity);
399
1/1
✓ Branch 1 taken 36 times.
36 wl.setScale(0);
400
1/1
✓ Branch 1 taken 36 times.
36 wr.setScale(0);
401
2/2
✓ Branch 2 taken 36 times.
✓ Branch 5 taken 36 times.
36 return equal(wl.value(), wr.value());
402 36 }
403 ✗ return false;
404 }
405
406 ✗ bool operator!=(const Quantity& lQuantity, const Quantity& rQuantity) {
407 ✗ return !(lQuantity == rQuantity);
408 }
409
410 } // namespace openstudio
411