com.scudata.expression.fn.math.Gcd Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of esproc Show documentation
Show all versions of esproc Show documentation
SPL(Structured Process Language) A programming language specially for structured data computing.
package com.scudata.expression.fn.math;
import java.util.ArrayList;
import java.util.Arrays;
import com.scudata.common.MessageManager;
import com.scudata.common.RQException;
import com.scudata.dm.Context;
import com.scudata.dm.Sequence;
import com.scudata.expression.Function;
import com.scudata.expression.IParam;
import com.scudata.resources.EngineMessage;
import com.scudata.util.Variant;
/**
* ?????г?Ա?????????????Լ??,????ֵ??Ա?????ԣ???ֵ??Ա???Զ?ȡ??,????С??0?ij?Ա???ش???ֵ0
* @author yanjing
*
*/
public class Gcd extends Function {
/**
* ??????ʽ????Ч?ԣ???Ч???׳??쳣
*/
public void checkValidity() {
if (param == null) {
MessageManager mm = EngineMessage.get();
throw new RQException("gcd" + mm.getMessage("function.missingParam"));
}
}
public Object calculate(Context ctx) {
ArrayList num=new ArrayList();
if(param.isLeaf()) {
Object result = param.getLeafExpression().calculate(ctx);
if (result != null && result instanceof Number) {
num.add((Number)result);
} else if (result != null && result instanceof Sequence) {
int n=((Sequence)result).length();
for (int i=1;i<=n;i++) {
Object tmp=((Sequence)result).get(i);
if (tmp!=null && tmp instanceof Number) {
num.add((Number)tmp);
}
}
}
} else {
int size = param.getSubSize();
for (int j=0; j max) {
long tmp=min;
min=max;
max=tmp;
}
if(min==0) {
return max;//??Ϊ0?ܱ??κ????????????ݰٶȰٿ?
} else {
return gcd(min,max%min);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy