A C++14-compatible physical units library with no dependencies and a single-file delivery option. Emphasis on safety, accessibility, performance, and developer experience.
Apache License 2.0
329
stars
21
forks
source link
Try reducing new units when incorporating into common units #295
int main(int, char**) {
std::cout << "1) " << (1 * cm + 1 * mi + 1 * m) << std::endl;
std::cout << "2) " << (1 * cm + 1 * m + 1 * mi) << std::endl;
}
Output:
1) 805177 COM[m, cm, mi]
2) 805177 COM[cm, mi]
In (2), the first addition does not create a common unit, because cm divides m. In (1), by contrast, we start with COM[cm, mi], and then incorporate m. It would be nice if we could check m against each of cm and mi in turn, and simply avoid adding it if it's already taken care of.
We could go even further, and produce COM[cm, mi] when adding COM[m, mi] and cm, effectively replacing m with cm.
See this example:
Output:
In (2), the first addition does not create a common unit, because
cm
dividesm
. In (1), by contrast, we start withCOM[cm, mi]
, and then incorporatem
. It would be nice if we could checkm
against each ofcm
andmi
in turn, and simply avoid adding it if it's already taken care of.We could go even further, and produce
COM[cm, mi]
when addingCOM[m, mi]
andcm
, effectively replacingm
withcm
.