Giter Site home page Giter Site logo

unitfulus.jl's Introduction

UnitfulUS

Build Status Coverage Status codecov.io

A supplemental units package for Unitful.jl.

Defined units

All units defined are suffixed with _us.

  • U.S. survey units (length) are also prefixed by s: sinch_us (inch), sft_us (foot), sli_us (link), syd_us (yard), srd_us (rod), sch_us (chain), sfur_us (furlong), smi_us (statute mile), slea_us (league).

  • U.S. survey units (area) are prefixed by s where ambiguous: sac_us (acre), town_us (township).

  • U.S. dry volumes: drypt_us (dry pint), dryqt_us (dry quart), pk_us (dry peck), bushel_us (bushel).

  • U.S. liquid volumes: gal_us (gallon), qt_us (quart), pt_us (pint), cup_us (cup), gill_us (gill / half cup), floz_us (fluid ounce), tbsp_us (culinary tablespoon), tsp_us (culinary teaspoon), fldr_us (fluid dram), minim_us (minim)

  • U.S. mass units: cwt_us (hundredweight), ton_us (ton)

Special features

This package defines a string macro @us_str that only searches for units from this package. @u_str is the only exported symbol from the package. When using the string macro, omit the _us suffix from units, as the macro will append it for you.

Usage examples:

julia> using Unitful.DefaultSymbols, UnitfulUS

julia> us"gal" == UnitfulUS.gal_us
true

julia> 1us"gal" |> m^3
473176473//125000000000 m^3

As can be seen, the us string macro aids in the distinction of U.S. gallons from other possible definitions of the gallon (Imperial gallon). Note that because this package registers with the @u_str macro, you can mix units from this package and the Unitful defaults so long as you include the _us suffix on units from this package:

julia> using Unitful, UnitfulUS

julia> 1.0u"kg/gal_us"
1.0 kg galᵘˢ

unitfulus.jl's People

Contributors

ajkeller34 avatar benelsen avatar briochemc avatar cstjean avatar giordano avatar juliatagbot avatar staticfloat avatar vchuravy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

unitfulus.jl's Issues

Tag a release compatible with the latest Unitful

UnitfulUS is currently incompatible with Unitful v1.0.0

(DummyEnv) pkg> st
    Status `~/DummyEnv/Project.toml`
  (empty environment)

(DummyEnv) pkg> add Unitful
  Updating registry at `~/.julia/registries/General`
  Updating git-repo `https://github.com/JuliaRegistries/General.git`
  Updating registry at `~/.julia/registries/R2Julia`
  Updating git-repo `[email protected]:R2-inc/R2Julia.git`
 Resolving package versions...
 Installed Unitful ─ v1.0.0
  Updating `~/DummyEnv/Project.toml`
  [1986cc42] + Unitful v1.0.0
  Updating `~/DummyEnv/Manifest.toml`
  [187b0558] + ConstructionBase v1.0.0
  [1986cc42] + Unitful v1.0.0
  [8f399da3] + Libdl 
  [37e2e46d] + LinearAlgebra 
  [9a3f8284] + Random 
  [9e88b42a] + Serialization 

(DummyEnv) pkg> add UnitfulUS
 Resolving package versions...
ERROR: Unsatisfiable requirements detected for package UnitfulUS [7dc9378f]:
 UnitfulUS [7dc9378f] log:
 ├─possible versions are: 0.1.0 or uninstalled
 ├─restricted to versions * by an explicit requirement, leaving only versions 0.1.0
└─restricted by compatibility requirements with Unitful [1986cc42] to versions: uninstalled — no versions left
   └─Unitful [1986cc42] log:
     ├─possible versions are: [0.9.0, 0.10.0, 0.11.0, 0.12.0, 0.13.0, 0.14.0, 0.15.0, 0.16.0, 0.17.0, 0.18.0, 1.0.0] or uninstalled
     └─restricted to versions 1.0.0 by an explicit requirement, leaving only versions 1.0.0

Overflow errors in 32-bit operating system

This issue came up for a small number of the students in my class. I admit it took me awhile to figure out what their error was, because I couldn't recreate it on my own computer. I don't actually know how many (or which) of the unit definitions in UnitfulUS lead to this error, but here is an example of what happens when one defines a US gallon:

julia> @unit gal "gal" USGallon 231Unitful.inch^3 false

ERROR: LoadError: LoadError: OverflowError: 5000 * 25000000 overflowed for type Int32
Stacktrace:
[1] throw_overflowerr_binaryop(op::Symbol, x::Int32, y::Int32)
@ Base.Checked .\checked.jl:154
[2] checked_mul
@ .\checked.jl:288 [inlined]
[3] *(x::Rational{Int32}, y::Rational{Int32})
@ Base .\rational.jl:311
[4] power_by_squaring(x_::Rational{Int32}, p::Int32)
@ Base .\intfuncs.jl:279
[5] ^
@ .\rational.jl:453 [inlined]
[6] dpow
@ ~.julia\packages\Unitful\PcVKX\src\units.jl:205 [inlined]
[7] basefactor(inex::Float64, ex::Rational{Int32}, eq::Int32, tens::Int32, p::Rational{Int32})
@ Unitful ~.julia\packages\Unitful\PcVKX\src\units.jl:234
[8] basefactor
@ ~.julia\packages\Unitful\PcVKX\src\units.jl:258 [inlined]
[9] map
@ .\tuple.jl:213 [inlined]
[10] basefactor(x::Unitful.FreeUnits{(inch^3,), 𝐋^3, nothing} )
@ Unitful ~.julia\packages\Unitful\PcVKX\src\units.jl:261
[11] top-level scope
@ ~.julia\packages\Unitful\PcVKX\src\user.jl:220
[12] include(mod::Module, _path::String)
@ Base .\Base.jl:386
[13] include(x::String)

I'm sure this error is exceedingly rare: it is still unclear why students in my class are using 32-bit versions of Julia. Might be old architectures, but might also be their mistake.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.