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

com.tecacet.math.extensions.BooleanExtensions.kt Maven / Gradle / Ivy

Go to download

Koltin extensions for matrix and vector algebra, random number generation, and arithmetic on boolean arrays.

The newest version!
package com.tecacet.math.extensions

import java.util.*

fun Boolean.toInt() = if (this) 1 else 0
fun Boolean.toDouble() = if (this) 1.0 else 0.0

operator fun BooleanArray.not(): BooleanArray = this.map { !it }.toBooleanArray()

infix fun BooleanArray.and(b: BooleanArray) =
        (this.indices).map { this[it] && b[it] }.toBooleanArray()

infix fun BooleanArray.or(b: BooleanArray) =
        (this.indices).map { this[it] || b[it] }.toBooleanArray()

infix fun BooleanArray.xor(b: BooleanArray) =
        (this.indices).map { this[it] xor b[it] }.toBooleanArray()

fun toString(b: BooleanArray): String = Arrays.toString(b)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy