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

commonMain.it.unibo.tuprolog.solve.stdlib.function.Exponential.kt Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package it.unibo.tuprolog.solve.stdlib.function

import it.unibo.tuprolog.core.Integer
import it.unibo.tuprolog.core.Numeric
import it.unibo.tuprolog.core.Real
import it.unibo.tuprolog.solve.ExecutionContext
import it.unibo.tuprolog.solve.function.UnaryMathFunction
import org.gciatto.kt.math.BigDecimal
import kotlin.math.exp

/**
 * Implementation of `exp/1` arithmetic functor
 *
 * @author Enrico
 */
object Exponential : UnaryMathFunction("exp") {
    override fun mathFunction(
        integer: Integer,
        context: ExecutionContext,
    ): Numeric = commonBehaviour(integer.decimalValue)

    override fun mathFunction(
        real: Real,
        context: ExecutionContext,
    ): Numeric = commonBehaviour(real.value)

    /** Implements the common behaviour for real and integer */
    private fun commonBehaviour(decimal: BigDecimal) =
        Numeric.of(
            exp(decimal.toDouble()),
        ) // TODO: 24/10/2019 missing "float_overflow" and "underflow" check (see the standard)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy