package org.matheclipse.core.reflection.system;

import org.matheclipse.core.eval.exception.Validate;
import org.matheclipse.core.eval.interfaces.IFunctionEvaluator;
import org.matheclipse.core.expression.F;
import org.matheclipse.core.interfaces.IAST;
import org.matheclipse.core.interfaces.IExpr;
import org.matheclipse.core.interfaces.INumber;
import org.matheclipse.core.interfaces.ISymbol;

/**
 * Gets the signum value of a complex number
 * 
 * @return 0 for this == 0;
* +1 for * real(this) > 0 || ( real(this) == 0 && imaginary(this) > 0 ) * ;
* -1 for * real(this) < 0 || ( real(this) == 0 && imaginary(this) < 0 ) */ public class SignCmp implements IFunctionEvaluator { public SignCmp() { } public IExpr evaluate(final IAST ast) { Validate.checkSize(ast, 2); if (ast.arg1().isNumber()) { final int signum = ((INumber) ast.arg1()).complexSign(); return F.integer(signum); } return null; } public IExpr numericEval(final IAST ast) { return evaluate(ast); } public void setUp(final ISymbol symbol) { symbol.setAttributes(ISymbol.LISTABLE); } }

Ads help maintain this website.