![JAR search and dependency download from the Maven repository](/logo.png)
commonMain.inkapplications.spondee.measures.Power.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of measures-js Show documentation
Show all versions of measures-js Show documentation
A class set for wrapping units of measure in an application.
package inkapplications.spondee.measures
/**
* Unit of energy per unit time
*/
interface Power {
/**
* Express the power in watts.
*/
val inWatts: Double
operator fun compareTo(other: Power): Int
operator fun plus(other: Power): Power
operator fun minus(other: Power): Power
operator fun div(other: Number): Power
operator fun times(other: Number): Power
operator fun unaryPlus(): Power = this
operator fun unaryMinus(): Power
}
/**
* SI Unit of Power.
*/
internal data class Watts(override val inWatts: Double): Power {
override fun compareTo(other: Power) = inWatts.compareTo(other.inWatts)
override fun plus(other: Power): Power = Watts(inWatts + other.inWatts)
override fun minus(other: Power): Power = Watts(inWatts - other.inWatts)
override fun div(other: Number): Power = Watts(inWatts / other.toDouble())
override fun times(other: Number): Power = Watts(inWatts * other.toDouble())
override fun unaryMinus(): Power = Watts(-inWatts)
override fun toString(): String = "${inWatts}W"
}
/**
* Express a number as unit of power in Watts.
*/
val Number.watts: Power get() = Watts(toDouble())
© 2015 - 2025 Weber Informatics LLC | Privacy Policy