- add
Dalton
as a unit - add some more explanations for predefined constants
- minor fix to
to
such that we use exactly the type as given by the user, instead ofyCT.toNimType()
. This is to guarantee the propertyx.to(T) is T
always holds.
- fix issue #48 where the unit parsing logic accepted invalid SI
prefixes and thus code like
foo.toMeter
was valid (and looked like sensible code)
- add unit of
Barn
- BREAKING: rename short form of Gauss to
gauss
. Single capitalG
is too brittle combined with Giga prefix - improve printed unit names in error messages
- add hbar as a constant
- add note about natural unit convention used
- fix for
nnkPostfix
nodes in macro logic
- do not cache names of units anymore. Improves performance by 50% on
files with many units (i.e.
tests/tunchained.nim
)!
- add some more astronomical units:
AstronomicalUnit
,AU
LightYear
,ly
Parsec
,parsec
(notpc
due to pico coulomb)
- add degree related units:
ArcMinute
,arcmin
ArcSecond
,arcsec
- BREAKING: Change definition of 1 year from 365 days to 365.25 days (1 Julian year), matching definition of a light year. Otherwise they would disagree if computed “by hand” using our units. More precise, but of course highly dependent on your calendar / definitions -> For these time units it would probably be best to have different sets of units / unit systems, i.e. GregorianYear etc. Anyone dealing with time units should be aware that these things are tricky and best be dealt with given their specific application!
- add the unit
Erg
commonly used in astronomy - improve type extraction for element access from sequences with types
& in particular sequences whose types have been defined by a
mapIt
call - fix extra colon in unit parsing (PR #41)
- add
Torr
as a unit of pressure - fixes a regression when parsing units with unicode runes (μ)
- add submodule to help with parsing units in
cligen
program arguments
- fix parsing units possibly returning uninitialized
UnitProduct
(in particular when dealing with type aliases ofUnitLess
)
- fixes an issue with type aliases where a short name was turned into
a long name that was no undefined, due to how we simplify the units,
Works around the following:
defUnit(ft²•ft⁻³) let x = 1.m⁻¹ check x.to(ft²•ft⁻³) == 0.3048.ft⁻¹ check x.to(ft²•ft⁻³) == 0.3048.ft²•ft⁻³
now producing problems as we emit the long form of user given types later. Those were not defined, because we only define long versions of the reduced version, i.e.
Foot⁻¹
.
- emit long type names in
to
after all, due to issue withmin
(see #37 and #35). This is not a problem anymore, due to fully aliasing long and short names - works around a weird issue related to
UnitTable
where looking up aUnitProduct
of a long name can sometimes return empty data. The key is being “replaced” by data that is essentially aUnitProduct
with a not initializedDefinedUnit
.
- add
FloatBytes
intdefine
variable, which allows to change the underlying float type used at CT using-d:FloatBytes=4
. Note: it might be advisable to also change the precision used to compare two units using-d:UnitCompareEpsilon=
and setting it to some smaller value. Default is 8 corresponding to an epsilon of1e-8
. Further, usingfloat32
can be problematic if used in combination with very low / very high SI prefixes due to the lower precision available.
- add new SI prefixes defined in November 2022: https://www.bipm.org/documents/20126/77765681/Resolutions-2022.pdf/281f3160-fc56-3e63-dbf7-77b76500990f
- add “unit typedesc math” helper module, which defines procedures
working with typedescs, so that the sometimes common approach:
let x = 1 * kg * m / s^2 doAssert x == 1.kg•m•s⁻² let y = 1.kg * m^2 / s^2 doAssert y == 1.kg•m²•s⁻² let z = 1.m^2 doAssert z == 1.m²
just works.
- fixes an issue with concept quantities where they would not match, due to wrong ordering in quantity comparison
- change default generated definitions of units: Instead of generating the quantity types first and then all units, we now generate all units first as based on distinct quantities. Then for compound units we define all versions of base types as aliases to the unit name. That way we give the compound unit name “priority” in the eyes of the Nim compiler.
- add caching of user defined units (string representation and internal representation) for minor performance improvements and keeping the user desired string representation around.
- rewrite unit parser for significant performance improvements
- change precedence of units again, so that fundamental compound units
are preferred over base units. Means we write
N•m
instead ofm•N
. - make `$`, `pretty` macros to avoid Nim compiler eating alias names:
The issue with the recent changes in `defUnit` to add more aliases for
a better user experience is that generics tend to eat aliases. In a
generic setting the Nim compiler will often only give us the first non
aliased name. This is pretty annoying, as it then often gives us type
names different from what the user intended. This gets around it, as
we now perform the logic in place.
NOTE: Keep in mind that
typeof
has the same issue as generics. The type name you see will be the first non alias name! As such avoid it for most things (only use foris
calls) - also turn
to
into a macro for the same reason as$
: Also here the issue is the same. As a generic we lose access to the real type of the symbol :(.Note that this may make
toDef
partially unnecessary. We’ll see how this works out.Also note that this breaks
to
in context of locally defined units combined with generics, as the macro fordefUnit
won’t be evaluated before and thusto
won’t know the type.However, this is actually a lesser problem now, because we generate more aliases so the need for
to
has drastically gone down. - simplify dimensional analysis by adding a “fixed size” type
QuantityPowerArray
and giving eachQuantity
a unique ID - add ID fields for units to uniquely identify a unit based on that
- rewrite
simplify
procedure for better performance - add
unitOf
,quantityOf
return string representations of the unit / quantity of a given unitful variable. toBaseUnits
performs a conversion of the given unit to a combination of base units.
- concepts for each quantity to match different units of same quantity in procedure calls!
<
for CT units now sorts positive powers before negative, this can be a breaking change- in `.` define the resulting type based on what’s given, not simplified, this can be a breaking change
- add
toDef
to combine the usage ofdefUnit
withto
(this can be problematic, see docstring) - clean up
defUnit
and also always generate the short name version of a given unit - update README
- improve `^` handling for static integers (powers smaller 2 now supported as well as negative powers)
- allow to print unit names without unicode half width space and no unicode symbols in unit names, if compiled with `-d:noUnicode`.
- BREAKING: changes the default behavior of printing unitful
variables from long format to short format!
- to change the behavior you can either call
pretty
manually and handshort = false
or compile with-d:ShortFormat=false
.
- to change the behavior you can either call
- fix regression #29, multiplication / division between base and derived units (e.g. SI and an imperial) did not convert, even if they shared a common quantity
- fix resolving
ntyGenericInst
(which also effectively handlesntySequence
it seems) - add
G_Newton
constant - add
AreaDensity
quantity
- fix
to
to explicitly only work withSomeUnit
types
- fix underlying issue of #5, the loss of type information when using
unitful
const
variables in unit math. The issue was ourisUnitLessNumber
check, as forconst
variables with numbers their node kind is stillnnkFloatLit
. The type needs to be looked at instead. - bump Nim version requirement to 1.6 to reflect the real version we support
- replaces definition of quantities and units by a fully declarative setup, which allows for much easier definition of custom unit systems, see PR #24 for more details
- also see
examples/custom_unit_system.nim
for a (admittedly ridiculous) example of defining a custom unit system
defUnits
now has anexport
option to define a unit that is exported (therefore thisdefUnit
can only be used at top level!)- add
Gauss
as a unit - allow conversion of
Kelvin
to natural units - allow units with `·` instead of `•` Note: this is only for units that user hands and constructs themselves. Predefined units or those auto generated when by `*` and similar still concat units using `•`. So YMMV and all that, but it opens up the possibility of being more flexible in the future.
- add constant
m_u
, defined byM_u / N_A
- rename Boltzmann constant from
k
tok_B
- add
pretty
for units that allows ashort
parameter. That way the unit will be string converted to a name with the short unit naming, i.e. m•s⁻¹ instead of Meter•Second⁻¹. For now the default will remain the long version, but that may change in the future.
- add
sqrt
for units that are a perfect square - add
abs
for units - add
+=
,*=
, … where they make sense (e.g. only same units for+=
and only with scalars for*=
- add unary
-
- add
hash
for units - rename
toFloat
converters to a name less likely to conflict with other things (toRawFloat
) - replace basic SI unit generation by a macro call (
defineUnits
) - change
getUnitTypeImpl
logic by usingtypeKind
- fix generation of SI prefixes if
exclude
is used. Previously mapping of short to long prefixes was broken ifexclude
was used. - fix math of compound units that involved conversions SI prefixes and
conversions to base units (i.e. Tesla to kg•s⁻²•A⁻¹) by adding a
global SI prefix factor field to
CTCompoundUnit
- reorder
ukDegree
inUnitKind
enum
- emit SI prefixed versions of Bq
- add Becquerel as a unit for activity
- fix issue #16, division of compound units works correctly now
- add Planck constant as
hp
and Boltzmann constant ask
- fix issue #13, conversion of degrees and radians not possible with
to
- fix ordering of internal compile time units
- make radian and steradian distinct meter based units to avoid conversion to a meter based representation when doing additive maths with them
- fix
==
macro for same types of different names
- fix bug causing “Pound-force” parsing to fail
- support for all SI base units and most compound SI units
- experimental SI unit support for converting SI units to natural units according to HEP Lorentz-Heaviside convention
- add imperial units:
yard, foot, ounce, slug, lbf, acre