Skip to content

Commit

Permalink
Merge c7dd552 into d4ed169
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonConder committed Jan 31, 2021
2 parents d4ed169 + c7dd552 commit 9ed4a4d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/pkgdefaults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@dimension 𝚯 "𝚯" Temperature # This one is \bfTheta
@dimension 𝐉 "𝐉" Luminosity
@dimension 𝐍 "𝐍" Amount
@dimension 𝐛 "𝐛" Information
const RelativeScaleTemperature = Quantity{T, 𝚯, <:AffineUnits} where T
const AbsoluteScaleTemperature = Quantity{T, 𝚯, <:ScalarUnits} where T

Expand Down Expand Up @@ -60,6 +61,7 @@ const AbsoluteScaleTemperature = Quantity{T, 𝚯, <:ScalarUnits} where T
@refunit cd "cd" Candela 𝐉 true
@refunit g "g" Gram 𝐌 true
@refunit mol "mol" Mole 𝐍 true
@refunit b "b" Bit 𝐛 false

# Angles and solid angles
@unit sr "sr" Steradian 1 true
Expand Down Expand Up @@ -113,7 +115,7 @@ end
# The hectare is used more frequently than any other power-of-ten of an are.
@unit a "a" Are 100m^2 false
const ha = Unitful.FreeUnits{(Unitful.Unit{:Are, 𝐋^2}(2, 1//1),), 𝐋^2}()
@unit b "b" Barn 100fm^2 true
@unit bn "bn" Barn 100fm^2 true

# Volume
# `l` is also an acceptable symbol for liters
Expand Down Expand Up @@ -216,11 +218,29 @@ const Å = Å = angstrom
# Pressure
@unit psi "psi" PoundsPerSquareInch 1lbf/inch^2 false

# Data
@unit B "B" Byte 8b false
# deciBytes can be a problem with deciBels, and we don't actually care about orders < 1
# Instead define all units in common use
# Overflow warning:
# Gigascale and above likely exceed Int32
# Exascale likely exceeds Int64
# Omitting ZB and YB: Julia interprets literal as Float64, which causes rounding errors
@unit kB "kB" KiloByte 8_000b false
@unit MB "MB" MegaByte 8_000_000b false
@unit GB "GB" GigaByte 8_000_000_000b false
@unit TB "TB" TeraByte 8_000_000_000_000b false
@unit PB "PB" PetaByte 8_000_000_000_000_000b false
@unit EB "EB" ExaByte 8_000_000_000_000_000_000b false
# Data rate
@unit bps "bps" BitPerSecond 1b/s true
@unit Bps "Bps" BytePerSecond 8b/s true

#########
# Logarithmic scales and units

@logscale dB "dB" Decibel 10 10 false
@logscale B "B" Bel 10 1 false
@logscale bel "Bel" Bel 10 1 false
@logscale Np "Np" Neper ℯ 1//2 true
@logscale cNp "cNp" Centineper ℯ 50 true

Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Unitful:
ms, s, minute, hr, d, yr, Hz,
J, A, N, mol, V,
mW, W,
B, kB, MB, GB, TB, PB, EB,
dB, dB_rp, dB_p, dBm, dBV, dBSPL, Decibel,
Np, Np_rp, Np_p, Neper

Expand Down Expand Up @@ -300,6 +301,16 @@ end
end
end

@testset "Data prefixes" begin
# Ensure manually setting the SI prefixes was consistent
@test 1kB/B == 1_000
@test 1MB/kB == 1_000
@test 1GB/MB == 1_000
@test 1TB/GB == 1_000
@test 1PB/TB == 1_000
@test 1EB/PB == 1_000
end

@testset "Promotion" begin
@testset "> Unit preferences" begin
# Only because we favor SI, we have the following:
Expand Down

0 comments on commit 9ed4a4d

Please sign in to comment.