Skip to content

Commit

Permalink
add ounces to mass
Browse files Browse the repository at this point in the history
  • Loading branch information
sswadkar committed Jan 24, 2023
1 parent f53a162 commit 6a5651c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ publishing {
release(MavenPublication) {
groupId = 'org.team4099'
artifactId = 'falconutils'
version = '1.1.2'
version = '1.1.3'

from(components["kotlin"])
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/org/team4099/lib/units/base/Mass.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,35 @@ typealias Mass = Value<Kilogram>

const val GRAMS_PER_POUND = 453.5924

const val GRAMS_PER_OUNCE = 28.3495

inline val Double.grams: Mass
get() = Mass(this / 1000)

inline val Double.pounds: Mass
get() = Mass(this * GRAMS_PER_POUND / 1000)

inline val Double.ounces: Mass
get() = Mass(this * GRAMS_PER_OUNCE / 1000)

inline val Number.grams: Mass
get() = toDouble().grams

inline val Number.pounds: Mass
get() = toDouble().pounds

inline val Number.ounces: Mass
get() = toDouble().ounces

inline val Mass.inGrams: Double
get() = value * Magnitude.KILO

inline val Mass.inPounds: Double
get() = (value * Magnitude.KILO) / GRAMS_PER_POUND

inline val Mass.inOunces: Double
get() = (value * Magnitude.KILO) / GRAMS_PER_OUNCE

inline val Mass.inYottagrams: Double
get() = (value * Magnitude.KILO) * 1.yottainverse

Expand Down

0 comments on commit 6a5651c

Please sign in to comment.