How to use okapi/units?

I read https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/#c11-string-literals
But it didn’t help much.
Where can I find related tutorials?
image
As shown in the figure above, his unit distance is always meters? Time is always seconds? Speed is always m / s?
How to use this area conversion?

I am not familiar with ncrapi, but have you look at this PROS reference pages with units example?

https://pros.cs.purdue.edu/v5/okapi/tutorials/walkthrough/clawbot.html
https://pros.cs.purdue.edu/v5/okapi/api/units/index.html

template <typename M, typename L, typename T, typename A>
constexpr RQuantity<std::ratio_divide<M, std::ratio<2>>, std::ratio_divide<L, std::ratio<2>>,
                    std::ratio_divide<T, std::ratio<2>>, std::ratio_divide<A, std::ratio<2>>>
Qsqrt(const RQuantity<M, L, T, A> &num)
{
    return RQuantity<std::ratio_divide<M, std::ratio<2>>, std::ratio_divide<L, std::ratio<2>>,
                     std::ratio_divide<T, std::ratio<2>>, std::ratio_divide<A, std::ratio<2>>>(sqrt(num.getValue()));
}

This is the implementation of sqrt. I don’t know how to implement atan2

First of all, there are some brief docs here:
https://okapilib.github.io/OkapiLib/md_docs_api_units.html

You should never use getValue(). You should always use convert(). Internally, it uses SI units, but you should not have to think of that. To convert, you use this syntax: .convert(meter) or .convert(mps).

There is a literal for _meter2, or you can do meter * meter.

For atan2, you can simply do this

atan2(y.convert(meter), x.convert(meter)) * radian;

You will have to do some more research if you want to implement a Qatan2.

1 Like