📄 vnumber.java
字号:
package HECore.stddata;
import HPCore.Exception.*;
public class VNumber extends Variant {
private double value = 0;
public VNumber(double db)
{
value =db;
}
public VNumber(boolean b)
{
if(b)
value=-1;
}
private short dealArithmeticalType(short type1,short type2){
if(type1==V_DATE || type2==V_DATE)
return V_DBL;
if(type1==V_CURR || type2==V_CURR)
return V_DBL;
if(type1>V_DBL || type2>V_DBL)
return V_DBL;
short last_type = type1 > type2 ? type1:type2;
return last_type;
}
/**
Used to perform a arithmetical addition operation on two expressions.
Returns a Variant whose value is (this - b)
**/
public Variant Add(Variant b) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
short last_type = dealArithmeticalType(b.getType(),getType()) ;
double value = this.value + b.dblValue();
Variant result = newVariant(last_type,value);
return result;
}
/**
Used to perform a arithmetical subtraction operation on two expressions.
Returns a Variant whose value is (this - b)
**/
public Variant Sub(Variant b) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
short last_type = dealArithmeticalType(b.getType(),getType()) ;
double value = this.value - b.dblValue();
Variant result = newVariant(last_type,value);
return result;
}
/**
Used to perform a arithmetical multiplication operation on two expressions.
Returns a Variant whose value is (this / b)
**/
public Variant Mult(Variant b) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
//if(b instanceof VOBject)
// return Add((VObject)b).getProperty("Default");
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
short last_type = dealArithmeticalType(b.getType(),getType()) ;
double value = this.value * b.dblValue();
Variant result = newVariant(last_type,value);
return result;
}
/**
Used to perform a arithmetical division operation on two expressions.
Returns a Variant whose value is (this / b)
**/
public Variant DDiv(Variant b) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
//if(b instanceof VOBject)
// return Add((VObject)b).getProperty("Default");
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
if(b.dblValue() ==0.0)
throw new HpException(11,"Division by Zero.");
short last_type = dealArithmeticalType(b.getType(),getType()) ;
double value = (this.value / b.dblValue());
return newVariant(last_type,value);
}
/**
Used to perform a arithmetical division operation on two expressions.
Returns a Variant whose value is (this / b)
**/
public Variant Div(Variant b) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
//if(b instanceof VOBject)
// return Add((VObject)b).getProperty("Default");
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
if(b.dblValue() ==0.0)
throw new HpException(11,"Division by Zero.");
short last_type = dealArithmeticalType(b.getType(),getType()) ;
double value = (this.value / b.dblValue());
return newVariant(last_type,value);
}
private short dealType(short type1,short type2){
short last_type=0;
//if(type1==V_DBL || type2==V_DBL || type2==V_SINGLE || type1==V_SINGLE|| type1==V_STR || type2==V_STR)
if(type1==V_BYTE || type2==V_BYTE)
last_type=V_INT;
else
if(type1>V_LONG || type2>V_LONG)
last_type=V_LONG;
else
last_type = type2 > type1 ? type2:type1;
return last_type;
}
/**
Returns a Variant whose value is (this & b)
**/
public Variant And(Variant b) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
short last_type=dealType(b.getType(),getType());
double value = ((int)this.value & (int)b.dblValue());
if(last_type<V_LONG)
{
if(last_type!=V_BOL)
{
return newVariant(last_type,value);
}
else
{
return newVariant(V_BOL,value);
}
}
else
return newVariant(V_LONG,value);
}
/**
Returns a Variant whose value is (this | b)
**/
public Variant Or(Variant b) throws HpException
{
if(b.getType()==V_NULL){
double value=((int)this.value | (int)b.dblValue());
if(getType() < V_LONG)
return newVariant(getType(),value);
else
return newVariant(V_LONG,value);
}
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
short last_type=dealType(b.getType(),getType());
double value = ((int)this.value | (int)b.dblValue());
if(last_type<V_LONG)
{
if(last_type!=V_BOL)
{
return newVariant(last_type,value);
}
else
{
return newVariant(V_BOL,value);
}
}
else
return newVariant(V_LONG,value);
}
/**
Returns a Variant whose value is (this ^ b)
**/
public Variant Xor(Variant b) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
short last_type=dealType(b.getType(),getType());
double value = ((int)this.value ^ (int)b.dblValue());
if(last_type<V_LONG)
{
if(last_type!=V_BOL)
{
return newVariant(last_type,value);
}
else
{
return newVariant(V_BOL,value);
}
}
else
return newVariant(V_LONG,value);
}
/**
Used to perform a logical implication on two expressions.
Returns a Variant whose value is (~this & ~b)
**/
public Variant Imp(Variant b) throws HpException
{
if(b.getType()==V_NULL)
return new VInt(-5);
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
short last_type=dealType(b.getType(),getType());
int bvalue= (int)b.dblValue();
double value = (double)(~((int)this.value &(~bvalue)));
if(last_type<V_LONG)
{
if(last_type!=V_BOL)
{
return newVariant(last_type,value);
}
else
{
return newVariant(V_BOL,value);
}
}
else
return newVariant(V_LONG,value);
}
public Variant Not(Variant b) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
return null;
}
public Variant Eqv(Variant b,boolean flag) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
int bvalue= (int)b.dblValue();
double value = (double)(~((int)this.value ^ bvalue));
short last_type=dealType(b.getType(),getType());
Variant result = newVariant(last_type,value);
return result;
}
public Variant Pow(Variant b) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
int bvalue= (int)b.dblValue();
short last_type=dealType(b.getType(),getType());
double value = (double)Math.pow(this.value,bvalue);
if(last_type==V_BOL)
return newVariant(V_SINGLE,value);
else
return newVariant(V_DBL,value);
}
public Variant Mod(Variant b) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
if(b.dblValue() ==0.0 )
throw new HpException(11,"Division by Zero.");
short last_type=dealType(b.getType(),getType());
double value = (double)((int)this.value % (int)b.dblValue());
if(last_type<V_LONG)
{
return newVariant(V_INT,value);
}
else
return newVariant(V_LONG,value);
}
public Variant Great(Variant b,boolean flag) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
if( b.getType()==V_STR )
{
if(this.getType()==V_STR)
return new VBoolean(Operator.Great(this.toString() ,b.toString(),flag));
else
return new VBoolean(false);
}
else
{
if(this.dblValue()>b.dblValue())
return new VBoolean(true);
else
return new VBoolean(false);
}
}
public Variant Less(Variant b,boolean flag) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
if( b.getType()==V_STR )
{
if(this.getType()!=V_STR)
return new VBoolean(true);
else
return new VBoolean(Operator.Less(this.toString() ,b.toString(),flag));
}
else
{
if(this.dblValue()<b.dblValue())
return new VBoolean(true);
else
return new VBoolean(false);
}
}
public Variant Equal(Variant b,boolean flag) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
if( b.getType()==V_STR )
{
if(this.getType()==V_STR)
return new VBoolean(Operator.Equal(this.toString() ,b.toString(),flag));
else
return new VBoolean(false);
}
else
{
if(this.dblValue()==b.dblValue())
return new VBoolean(true);
else
return new VBoolean(false);
}
}
public Variant GreatEqual(Variant b,boolean flag) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
if(b.getType()==V_STR )
{
if(this.getType()==V_STR)
return new VBoolean(Operator.GreatEqual(this.toString() ,b.toString(),flag));
else
return new VBoolean(false);
}
else
{
if(this.dblValue()>=b.dblValue())
return new VBoolean(true);
else
return new VBoolean(false);
}
}
public Variant LessEqual(Variant b,boolean flag) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
if( b.getType()==V_STR )
{
if(this.getType()==V_STR)
return new VBoolean(Operator.LessEqual(this.toString() ,b.toString(),flag));
else
return new VBoolean(false);
}
else
{
if(this.dblValue()<=b.dblValue())
return new VBoolean(true);
else
return new VBoolean(false);
}
}
public Variant NotEqual(Variant b,boolean flag) throws HpException
{
if(b.getType()==V_NULL)
return new VNull();
if(b.getType()==V_ERR)
throw new HpException( 13," Type mismatch");
if( b.getType()==V_STR )
{
if(this.getType()==V_STR)
return new VBoolean(Operator.NotEqual(this.toString() ,b.toString(),flag));
else
return new VBoolean(true);
}
else
{
if(this.dblValue()!=b.dblValue())
return new VBoolean(true);
else
return new VBoolean(false);
}
}
public short intValue() throws HpException
{
if(value>32767 || value<-32768)
throw new HpException(6,"Overflow");
return (short)value;
}
public short byteValue() throws HpException
{
if(value>255 || value<0)
throw new HpException(6,"Overflow");
return (short)value;
}
public double dblValue()
{
return value;
}
public float sglValue() throws HpException
{
if((value>= -3.402823E38 && value<=-1.401298E-45) || (value<= 3.402823E38 && value>=1.401298E-45))
return (float)value;
else
throw new HpException(6,"Overflow");
}
public int lngValue() throws HpException
{
if(value>2147483647 || value<-2147483648)
throw new HpException(6,"Overflow");
return (int)value;
}
public boolean boolValue()
{
if(value==0)
return false;
else
return true;
}
/**
*Returns the type of this object
**/
public String toString()
{
return new Double(value).toString();
}
public Variant Like(Variant b,boolean mode) throws HpException {
return new VBoolean(Operator.Like(toString(),b.strValue(),mode));
}
public VString Link(Variant b)
{
//if(b instanceof VOBject)
// return Add((VObject)b).getProperty("Default");
String s="";
s=toString()+b.toString();
return new VString(s);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -