Added extension to field to use numbers as first class citizens
This commit is contained in:
parent
c344380120
commit
3576ddaf31
@ -101,6 +101,9 @@ interface Field<T> : Ring<T> {
|
||||
|
||||
operator fun T.div(b: T): T = divide(this, b)
|
||||
operator fun Number.div(b: T) = this * divide(one, b)
|
||||
|
||||
operator fun T.plus(b: Number) = this.plus(b * one)
|
||||
operator fun Number.plus(b: T) = b + this
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,7 +10,7 @@ class FieldExpressionContextTest {
|
||||
val context = FieldExpressionContext(DoubleField)
|
||||
val expression = with(context) {
|
||||
val x = variable("x", 2.0)
|
||||
x * x + 2 * x + 1.0 * one
|
||||
x * x + 2 * x + 1.0
|
||||
}
|
||||
assertEquals(expression("x" to 1.0), 4.0)
|
||||
assertEquals(expression(), 9.0)
|
||||
|
Loading…
Reference in New Issue
Block a user