数值带物理单位的c++库

本文介绍了一系列C++库,这些库支持编译时单位分析、单位转换及物理量操作,适用于不同场景的需求,包括Boost Units、Units、PhysUnits等。文章探讨了选择特定库的理由,比如对类型安全的需求、运行时性能考量以及特定单位的支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

If you are looking for compile time and prevention of unit errors in equations for dimensional analysis one of these libraries might work for you.

  • boost units -Zero-overhead dimensional analysis and unit/quantity manipulation and conversion in C++
  • Units -A compile-time, header-only, dimensional analysis library built on with no dependencies.C++14
  • Units -Another compile time library
  • PhysUnits-CT A C++ library for compile-time dimensional analysis and unit/quantity manipulation and conversion.
  • PhysUnits-RT -A C++ library for run-time dimensional analysis and unit/quantity manipulation and conversion.
  • Libunits -The ultimate shared library to do calculations(!) and conversions with any units! Includes all SI and pseudo SI units and thousands of US, Imperial and other units.
  • unitscpp -A lightweight C++ library for physical calculation with units.
  • mpusz/units -A compile-time enabled Modern C++ library that provides compile-time dimensional analysis and unit/quantity manipulation.
  • bernedom/SI -A header only C++ library that provides type safety and user defined literals for handling physical values defined in the International System of Units

These libraries will work well if the number of units being dealt with is known at compile time. Many also produce zero overhead operations and checking. Therefore in situations where this is possible other libraries are a preferred alternative.

Reasons to choose this units library over another option

  1. Conversions to and from regular strings are required
  2. The number of units in use is large
  3. A specific single unit or measurement type is required to handle many different kinds of units or measurements
  4. Uncertainties are needed to be included with the measurements
  5. Working with per unit values
  6. Dealing with commodities in addition to regular units. i.e. differentiate between a gallon of water and a gallon of gasoline
  7. Dealing with equation type units
  8. Complete C++ type safety is NOT a critical design requirement.
  9. Support is needed for some funky custom unit with bizarre base units.

Reasons to choose something else

  1. Type safety and dimensional analysis IS a design requirement
  2. Performance is absolutely critical (many other libraries are zero runtime overhead)
  3. You are only working with a small number of known units
  4. You cannot use C++11 yet.
  5. You need to operate on arbitrary or general fractional powers of base units
  6. You need support for arbitrary datum shifts in the unit library
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值