package prolog.ast.arithmetic

import prolog.Substitutions

class Float(override val value: kotlin.Float): Number {
    // Floats are already evaluated
    override fun simplify(subs: Substitutions): Simplification = Simplification(this, this)

    override fun toString(): String = value.toString()

    override operator fun plus(other: Number): Number = when (other) {
        is Float   -> Float(value + other.value)
        is Integer -> Float(value + other.value.toFloat())
        else -> throw IllegalArgumentException("Cannot add $this and $other")
    }

    override operator fun minus(other: Number): Number = when (other) {
        is Float   -> Float(value - other.value)
        is Integer -> Float(value - other.value.toFloat())
        else -> throw IllegalArgumentException("Cannot subtract $this and $other")
    }

    override operator fun div(other: Number): Number = when (other) {
        is Float   -> Float(value / other.value)
        is Integer -> Float(value / other.value.toFloat())
        else -> throw IllegalArgumentException("Cannot divide $this and $other")
    }

    override operator fun times(other: Number): Number = when (other) {
        is Float   -> Float(value * other.value)
        is Integer -> Float(value * other.value.toFloat())
        else -> throw IllegalArgumentException("Cannot multiply $this and $other")
    }

    override fun applySubstitution(subs: Substitutions): Float = this

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other !is Float) return false
        if (value != other.value) return false
        return true
    }

    override fun hashCode(): Int {
        return super.hashCode()
    }
}