2017-09-23 17:13:56 -07:00
|
|
|
package org.nwapw.abacus.plugin.standard.operator
|
2017-09-23 16:19:45 -07:00
|
|
|
|
2017-11-23 02:21:06 -08:00
|
|
|
import org.nwapw.abacus.context.PluginEvaluationContext
|
2017-09-23 16:19:45 -07:00
|
|
|
import org.nwapw.abacus.function.OperatorAssociativity
|
|
|
|
import org.nwapw.abacus.function.OperatorType
|
2017-11-14 23:03:12 -08:00
|
|
|
import org.nwapw.abacus.function.interfaces.NumberOperator
|
2017-09-23 16:19:45 -07:00
|
|
|
import org.nwapw.abacus.number.NumberInterface
|
|
|
|
|
2017-09-23 17:11:05 -07:00
|
|
|
/**
|
|
|
|
* The negation operator.
|
|
|
|
*
|
|
|
|
* This is a standard operator that negates a number.
|
|
|
|
*/
|
2018-01-30 21:10:02 -08:00
|
|
|
class OperatorNegate: NumberOperator(OperatorAssociativity.LEFT, OperatorType.UNARY_PREFIX, 1) {
|
2017-09-23 16:19:45 -07:00
|
|
|
|
2017-11-23 02:21:06 -08:00
|
|
|
override fun matchesParams(context: PluginEvaluationContext, params: Array<out NumberInterface>) =
|
2017-09-23 16:19:45 -07:00
|
|
|
params.size == 1
|
|
|
|
|
2017-11-23 02:21:06 -08:00
|
|
|
override fun applyInternal(context: PluginEvaluationContext, params: Array<out NumberInterface>) =
|
2017-09-23 16:19:45 -07:00
|
|
|
-params[0]
|
|
|
|
|
|
|
|
}
|