feat: Floating point arithmetic
This commit is contained in:
parent
f9950a3fd3
commit
4a6850527f
13 changed files with 527 additions and 55 deletions
|
@ -1,30 +0,0 @@
|
|||
package prolog.ast.terms
|
||||
|
||||
import prolog.Substitutions
|
||||
import prolog.ast.arithmetic.Expression
|
||||
import prolog.ast.arithmetic.Simplification
|
||||
|
||||
data class Integer(val value: Int): Expression {
|
||||
// Integers are already evaluated
|
||||
override fun simplify(subs: Substitutions): Simplification = Simplification(this, this)
|
||||
|
||||
override fun toString(): String {
|
||||
return value.toString()
|
||||
}
|
||||
|
||||
operator fun plus(other: Integer): Integer {
|
||||
return Integer(value + other.value)
|
||||
}
|
||||
|
||||
operator fun minus(other: Integer): Integer {
|
||||
return Integer(value - other.value)
|
||||
}
|
||||
|
||||
operator fun times(other: Integer): Integer {
|
||||
return Integer(value * other.value)
|
||||
}
|
||||
|
||||
operator fun div(other: Integer): Integer {
|
||||
return Integer(value / other.value)
|
||||
}
|
||||
}
|
|
@ -5,8 +5,9 @@ import prolog.logic.compare
|
|||
/**
|
||||
* Value in Prolog.
|
||||
*
|
||||
* A [Term] is either a [Variable], [Atom], [Integer], float or [CompoundTerm].
|
||||
* In addition, SWI-Prolog also defines the type string.
|
||||
* A [Term] is either a [Variable], [Atom], [Integer][prolog.ast.arithmetic.Integer],
|
||||
* [Float][prolog.ast.arithmetic.Float] or [CompoundTerm].
|
||||
* In addition, SWI-Prolog also defines the type TODO string.
|
||||
*/
|
||||
interface Term : Comparable<Term> {
|
||||
override fun compareTo(other: Term): Int = compare(this, other, emptyMap())
|
||||
|
|
Reference in a new issue