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

com.teamwizardry.librarianlib.math.MathUtils.kt Maven / Gradle / Ivy

There is a newer version: 5.0.0-alpha.10
Show newest version
@file:JvmName("MathUtils")

package com.teamwizardry.librarianlib.math

import kotlin.math.ceil
import kotlin.math.floor

public fun Int.clamp(min: Int, max: Int): Int = if (this < min) min else if (this > max) max else this
public fun Short.clamp(min: Short, max: Short): Short = if (this < min) min else if (this > max) max else this
public fun Long.clamp(min: Long, max: Long): Long = if (this < min) min else if (this > max) max else this
public fun Byte.clamp(min: Byte, max: Byte): Byte = if (this < min) min else if (this > max) max else this
public fun Char.clamp(min: Char, max: Char): Char = if (this < min) min else if (this > max) max else this
public fun Float.clamp(min: Float, max: Float): Float = if (this < min) min else if (this > max) max else this
public fun Double.clamp(min: Double, max: Double): Double = if (this < min) min else if (this > max) max else this

// kotlin-only =========================================================================================================

@Suppress("NOTHING_TO_INLINE")
public inline fun > T.clamp(min: T, max: T): T = if (this < min) min else if (this > max) max else this

@JvmSynthetic
public fun floorInt(value: Float): Int = floor(value).toInt()

@JvmSynthetic
public fun floorInt(value: Double): Int = floor(value).toInt()

@JvmSynthetic
public fun ceilInt(value: Float): Int = ceil(value).toInt()

@JvmSynthetic
public fun ceilInt(value: Double): Int = ceil(value).toInt()




© 2015 - 2024 Weber Informatics LLC | Privacy Policy