diff --git a/docs/examples.rst b/docs/examples.rst index 07876023..df7f5be3 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -259,10 +259,14 @@ with output: Fractional dimension -------------------- -Fractional dimensions are supported; they work in the same way as familiar integral dimensions. +Fractional dimensions have limited support. +Prior to c++26 we can only support fractional dimensions with denominator 2, +such as powers -3/2, -1/2, +1/2, +3/2 etc. -Only caveat is that converting between fractional units with different scales creates a floating-point conversion factor, -which may incur loss of precision based on floating-point roundoff. +c++26 will enable support for support fractional dimensions involving other ratios, +by offering constexpr ``::pow()`` + +See ``xo-unit/examples/ex6`` for code below .. code-block:: cpp :linenos: @@ -282,18 +286,23 @@ which may incur loss of precision based on floating-point roundoff. /* 10% volatility over 30 days */ auto q2 = qty::volatility30d(0.1); - static_assert(q2.basis_power == 0.5); - auto sum = q1 + q2; auto prod = q1 * q2; - static_assert(prod.basis_power == 1); + static_assert(sum.abbrev() == flatstring("yr360^(-1/2)")); + static_assert(prod.abbrev() == flatstring("yr360^-1")); - cerr << "q1: " << q1 << ", q2: " << q2 << ", q1+q2: " << sum << ", q1*q2" << prod << endl; + std::cerr << "q1: " << q1 << std::endl; + std::cerr << "q2: " << q2 << std::endl; + std::cerr << "q1+q2: " << sum << std::endl; + std::cerr << "q1*q2: " << prod << std::endl; } with output: .. code-block:: - q1: 0.2yr250^-(1/2), q2: 0.1mo^-(1/2), q1+q2: 0.488675yr250^(1/2), q1*q2: 0.057735yr250^-1 + q1: 0.2yr360^(-1/2) + q2: 0.1mo^(-1/2) + q1+q2: 0.54641yr360^(-1/2) + q1*q2: 0.069282yr360^-1 diff --git a/example/ex6/ex6.cpp b/example/ex6/ex6.cpp index 3775cf3d..f7ff86a4 100644 --- a/example/ex6/ex6.cpp +++ b/example/ex6/ex6.cpp @@ -2,7 +2,6 @@ #include "xo/unit/quantity.hpp" #include "xo/unit/quantity_iostream.hpp" -#include "xo/flatstring/int128_iostream.hpp" #include int @@ -16,8 +15,6 @@ main () { /* 10% volatility over 30 days */ auto q2 = q::volatility_30d(0.1); - //quantity q2p = q2; - /* 10% volatility per 30 days * ~ (10% * sqrt(360/30)) volatility over 360 days * ~ (10% * 3.4641)