From 4830351e616d2c5691ad94d33869b4cc8e41c657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20A=2E=20Michel=C3=A9n=20Str=C3=B6fer?= Date: Sun, 3 Dec 2023 16:31:31 -0700 Subject: [PATCH] Convert between `Unitful` and `DimensionfulAngles` (#34) --- Project.toml | 2 + README.md | 26 +- docs/Project.toml | 6 +- docs/make.jl | 37 +- ...ve_diagram_of_harmonic_wave_properties.svg | 2213 +++++++++++++++++ docs/src/assets/citations.css | 18 + docs/src/guide/base.md | 9 +- docs/src/guide/derived.md | 51 +- docs/src/guide/intro.md | 50 +- docs/src/index.md | 5 +- docs/src/motivation.md | 11 +- docs/src/proposed.md | 30 +- src/DimensionfulAngles.jl | 32 +- src/convert.jl | 165 ++ src/derived.jl | 22 +- src/uamacro.jl | 2 +- src/units.jl | 36 +- test/Project.toml | 1 + test/test_base_functions.jl | 1 + test/test_core_package.jl | 77 +- 20 files changed, 2703 insertions(+), 91 deletions(-) create mode 100644 docs/src/assets/Commutative_diagram_of_harmonic_wave_properties.svg create mode 100644 docs/src/assets/citations.css create mode 100644 src/convert.jl diff --git a/Project.toml b/Project.toml index c0e3734..2a30e23 100644 --- a/Project.toml +++ b/Project.toml @@ -5,9 +5,11 @@ version = "0.2.0" [deps] Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" +UnitfulAngles = "6fb2a4bd-7999-5318-a3b2-8ad61056cd98" UnitfulEquivalences = "da9c4bc3-91c8-4f02-8a40-6b990d2a7e0c" [compat] Unitful = "1.10" +UnitfulAngles = "0.7" UnitfulEquivalences = "0.2" julia = "1.7" diff --git a/README.md b/README.md index 33942a3..3381330 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Michelén Ströfer, C. A. (2022). DimensionfulAngles.jl (Version 0.1.0) [Compute Use *DimensionfulAngles.jl* for units containing angles and *Unitful.jl* for all other units. The units in *DimensionfulAngles.jl* are differentiated from their dimensionless counterparts with a superscript `ᵃ`. -Simply add this superscript to any angle units to make it dimensionful. +Simply add this superscript to any angle units to make it dimensionful. In Julia environments this can be typed as `\^a`. ```julia @@ -125,8 +125,30 @@ julia> using DimensionfulAngles.DefaultSymbols julia> angular_velocity = 1.2rad / s ``` +### Converting to/from `Unitful.jl` +To convert a quantity to or from `Unitful.jl` use the `uconvert` function with first +argument either `:Unitful` or `:DimensionfulAngles`. +For example: + +```julia +julia> using Unitful, DimensionfulAngles + +julia> ω = 3.2u"radᵃ/s" +3.2 rad s⁻¹ + +julia> ω̄ = uconvert(:Unitful, ω) +3.2 rad s⁻¹ + +julia> dimension(ω) +𝐀 𝐓⁻¹ + +julia> dimension(ω̄) +𝐓⁻¹ +``` + + ## Contributing -