nholthaus / units

a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.
http://nholthaus.github.io/units/
MIT License
934 stars 134 forks source link

Need help implementing resistance as a new custom unit. #319

Closed jcracine-cimeq closed 1 year ago

jcracine-cimeq commented 1 year ago

Required Specs:

Problem: I'm trying to add ohms as a new units to help calculating formulas with NTC Thermistors for a project, and it's the first time I'm trying to implement a new custom unit using the available macros. I tried using the UNIT_ADD_WITH_METRIC_PREFIXES() macro to do that, but I'm not sure which base unit I should base it when I create my definition. So far, I have UNIT_ADD_WITH_METRIC_PREFIXES(resistance, ohm, ohms, ohms, units::unit<std::ratio<1,1>, ?>).

Also, I'm not sure if I understood correctly but could it work if I used a compound_unit instead like this: using resistance = units::compound_unit<units::voltage::volts,units::inverse<units::current::amperes>>?

JohelEGP commented 1 year ago

Maybe this will help you: https://github.com/nholthaus/units/blob/3ca0e22c5e5088a93f930617d193e895eb538bca/include/units.h#L3823

jcracine-cimeq commented 1 year ago

Maybe that can do the trick, but technically there's a distinct difference between resistance and impedance as the first one applies to DC and the latter to AC.