![]() |
Home | Libraries | People | FAQ | More |
Because Boost.Units includes plane and solid angle units in the SI system,
torque and energy are, in fact, distinguishable (see torque).
In addition, energy is a true scalar
quantity, while torque, despite having the same units as energy if plane
angle is not included, is in fact a pseudovector.
Thus, a value type representing pseudovectors and encapsulating their algebra
could also be implemented.
因為Boost.Units包含SI系統中平面和立體的角度單位,所以實際上,力矩和能量是可分辨的(見力矩(torque))。
實際上,能量(energy)是一個純粹的標量(scalar),而力矩(torque)雖然如果不包含平面角度的話擁有與能量相同的單位,但實際上是偽矢量(pseudovector)。
於是,一個表示偽矢量並封裝其代數運算的數值類型是可以被實現的。
There are, however, a few SI units that are dimensionally indistinguishable
within the SI system. These include the becquerel,
which has units identical to frequency (Hz), and the sievert,
which is degenerate with the gray.
In cases such as this, the proper way to treat this difference is to recognize
that expanding the set of base dimensions can provide disambiguation. For
example, adding a base dimension for radioactive decays would allow the becquerel
to be written as decays/second, differentiating it from the signature of
hertz, which is simply 1/second.
確實是有一些SI單位的量綱是無法區分的。
這其中包括貝克(becquerel),和頻率的單位是一樣的(Hz),又比如sievert,is degenerate with the gray(???)。
這種情況下,對待這種差異的合適方法是識別和增加基礎量綱來消除這種模稜兩可的情況。
例如,增加一種放射衰減的基礎量綱可以使得貝克(becquerel)被寫成decays/second,用來區分赫茲(hertz),1/second。
If you don't like this, you can just ignore the angle units and go on your
merry way (periodically screwing up when a routine wants degrees and you
give it radians instead...)
如果你不喜歡,就忽略它好了(當需要角度而你給了弧度的時候再想起好了...)
Consider the following code:
考慮下面的代碼:
cout << sin(asin(180.0 * degrees));
What should this print? If only heterogeneous systems are available it would
print 3.14159+ rad Why? Well, asin
would return a quantity<dimensionless>
effectively losing the information that degrees are being used. In order
to propogate this extra information we need homogeneous systems.
應該打印什麼呢?如果只有異構系統,那麼應該打印3.14159+ rad,不是嗎?
asin應該返回quantity<dimensionless>,丟失了角度的信息。
為了傳遞這個額外的信息我們需要同構系統。
This only breaks generic code--which ought to break anyway. The only literal
value that ought to be converted to a quantity by generic code is zero, which
should be handled by the default constructor. In addition, consider the search
and replace problem allowing this poses:
這會中斷泛型代碼--本應該中斷所有。泛型代碼唯一接受的字面數值是0,被默認構造函數處理。另外,看一下下面的搜索和替換問題:
quantity<si::length> q(1.0);
Here, the intent is clear - we want a length of one in the SI system, which
is one meter. However, imagine some well-intentioned coder attempting to
reuse this code, but to have it perform the calculations in the CGS unit
system instead. After searching for si:: and replacing it with cgs:: , we have:
意圖很明顯 - 我們需要一個SI系統的長度,也就是1米。但是,想像一下,當有人想用重用這段代碼,但需要用CGS單位系統替代。
用cgs::替換了si::以後:
quantity<cgs::length> q(1.0);
Unfortunately, the meaning of this statement has suddenly changed from one
meter to one centimeter. In contrast, as implemented, we begin with:
不幸的是,這段代碼的意義變了,從1米變成了1分米。相反,就像現在實現的,我們這樣寫:
quantity<si::length> q(1.0*si::meter);
and, after search and replace:
經過搜索和替換後:
quantity<cgs::length> q(1.0*cgs::meter);
which gives us an error. Even if the code has a @using namespace boost::units::si;
declaration, the latter is still safe, with:
會有一個編譯錯誤。即使是使用@using namespace boost::units::si;聲明的代碼,也是安全的:
using namespace boost::units::si; quantity<length> q(1.0*meter);
going to
using namespace boost::units::cgs; quantity<length> q(1.0*meter);
The latter will involve an explicit conversion from meters to centimeters,
but the value remains correct.
會導致一個從米到分米的顯式轉換,但值仍然是正確的。
Safety and the potential for unintended conversions leading to precision
loss and hidden performance costs. Options are provided for forcing implicit
conversions between specific units to be allowed.
安全,防止無意間的精度損失,防止性能損失。提供選項使得特定單位之間的顯式轉換被允許。