File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -534,6 +534,9 @@ macro toBaseUnits*[T: SomeUnit](x: T): untyped =
534534 let resType = xCT.flatten ().toBaseType (true ).simplify (mergePrefixes = true ).toNimType
535535 result = quote do :
536536 `x`.toDef (`resType`)
537+ template simplify * [T: SomeUnit ](x: T): untyped =
538+ # # Alias for `toBaseUnits`. Converts the given input to base SI units
539+ toBaseUnits (x)
537540
538541# # Natural unit stuff
539542proc toNaturalUnitImpl (t: UnitProduct ): UnitProduct
@@ -594,13 +597,3 @@ macro toNaturalUnit*[T: SomeUnit](t: T): untyped =
594597 result = quote do :
595598 defUnit (`resType`)
596599 `resType` (`t`.FloatType * `scale`)
597-
598- macro simplify * [T: SomeUnit ](t: T): untyped =
599- # # Returns the simplest form in SI base units of the given input.
600- var typ = t.parseDefinedUnit ()
601- let resType = typ.flatten ().simplify ()
602- let scale = typ.toBaseTypeScale () / resType.toBaseTypeScale ()
603- let resTypeNim = resType.toNimType ()
604- result = quote do :
605- defUnit (`resTypeNim`)
606- `resTypeNim` (`t`.FloatType * `scale`)
Original file line number Diff line number Diff line change @@ -481,6 +481,7 @@ suite "Unchained - Conversion between units":
481481 let x = 1 .kJ
482482 check typeof (x.simplify ()) is kg•m²•s⁻²
483483 check x.simplify () == 1000 .kg•m²•s⁻²
484+ check x.toBaseUnits () == 1000 .kg•m²•s⁻²
484485
485486suite " Unchained - CT errors" :
486487 test " Error on regular digit as exponent" :
You can’t perform that action at this time.
0 commit comments