All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hnau.base.extensions.number.DoubleExtensions.kt Maven / Gradle / Ivy

There is a newer version: 2.1.9
Show newest version
package org.hnau.base.extensions.number

import org.hnau.base.extensions.*

fun Double.asPercentageInter(
        from: Number, to: Number
) = from.toDouble().let { fromDouble ->
    fromDouble + (to.toDouble() - fromDouble) * this
}

inline fun  Double.ifPositive(action: (Double) -> R) = ifLargeThan(0.0, action)
inline fun  Double.ifNegative(action: (Double) -> R) = ifLessThan(0.0, action)
inline fun  Double.ifNotNegative(action: (Double) -> R) = ifNotLessThan(0.0, action)
inline fun  Double.ifNotPositive(action: (Double) -> R) = ifNotLargeThan(0.0, action)

fun Double.takeIfPositive() = ifPositive(::it)
fun Double.takeIfNegative() = ifNegative(::it)
fun Double.takeIfNotNegative() = ifNotNegative(::it)
fun Double.takeIfNotPositive() = ifNotPositive(::it)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy