hpmath.java
来自「一个简单的visio程序。」· Java 代码 · 共 1,723 行 · 第 1/4 页
JAVA
1,723 行
}
/*-------- FUNCTION:Rnd(seed) -------*/
public static float RND(Variant varseed) throws HpException
{
float value = 0;
double tmp = hpstring.get_db(varseed);
int seed = (int)Math.round(tmp);
java.util.Random rd = new java.util.Random();
if( seed==0 )
seed=-1;
if( seed<0 )
{ //seed<0 return same value
rd.setSeed(seed);
value = rd.nextFloat();
}
/*
else if( seed==0 )
{ //seed=0 The number most recently generated.
Date dt = new Date();
long time;
time = dt.getTime();
rd.setSeed(time);
value = (float)Math.random();
}*/
else
{ //seed>0 the next rand
rd.setSeed( seed + (int)Math.random() );//
value = (float)Math.random();
}
return value ;
}
public static float RND(boolean bool_seed) throws HpException
{
float value = 0;
int seed = bool_seed==true ? -1:0;
java.util.Random rd = new java.util.Random();
if( seed==0 )
seed=-1;
if( seed<0 )
{ //seed<0 return same value
rd.setSeed(seed);
value = rd.nextFloat();
}
/*
else if( seed==0 )
{ //seed=0 The number most recently generated.
Date dt = new Date();
long time;
time = dt.getTime();
rd.setSeed(time);
value = (float)Math.random();
}*/
else
{ //seed>0 the next rand
rd.setSeed( seed + (int)Math.random() );//
value = (float)Math.random();
}
return value ;
}
public static float RND(HByte byte_seed) throws HpException
{
float value = 0;
int seed = (int)(byte_seed.byteValue());
java.util.Random rd = new java.util.Random();
if( seed==0 )
seed=-1;
if( seed<0 )
{ //seed<0 return same value
rd.setSeed(seed);
value = rd.nextFloat();
}
/*
else if( seed==0 )
{ //seed=0 The number most recently generated.
Date dt = new Date();
long time;
time = dt.getTime();
rd.setSeed(time);
value = (float)Math.random();
}*/
else
{ //seed>0 the next rand
rd.setSeed( seed + (int)Math.random() );//
value = (float)Math.random();
}
return value ;
}
public static float RND(short sh_seed) throws HpException
{
float value = 0;
int seed = (int)sh_seed;
java.util.Random rd = new java.util.Random();
if( seed==0 )
seed=-1;
if( seed<0 )
{ //seed<0 return same value
rd.setSeed(seed);
value = rd.nextFloat();
}
/*
else if( seed==0 )
{ //seed=0 The number most recently generated.
Date dt = new Date();
long time;
time = dt.getTime();
rd.setSeed(time);
value = (float)Math.random();
}*/
else
{ //seed>0 the next rand
rd.setSeed( seed + (int)Math.random() );//
value = (float)Math.random();
}
return value ;
}
public static float RND(int seed) throws HpException
{
float value = 0;
java.util.Random rd = new java.util.Random();
if( seed==0 )
seed=-1;
if( seed<0 )
{ //seed<0 return same value
rd.setSeed(seed);
value = rd.nextFloat();
}
/*
else if( seed==0 )
{ //seed=0 The number most recently generated.
Date dt = new Date();
long time;
time = dt.getTime();
rd.setSeed(time);
value = (float)Math.random();
}*/
else
{ //seed>0 the next rand
rd.setSeed( seed + (int)Math.random() );//
value = (float)Math.random();
}
return value ;
}
public static float RND(float f_seed) throws HpException
{
float value = 0;
int seed = (int)f_seed;
java.util.Random rd = new java.util.Random();
if( seed==0 )
seed=-1;
if( seed<0 )
{ //seed<0 return same value
rd.setSeed(seed);
value = rd.nextFloat();
}
/*
else if( seed==0 )
{ //seed=0 The number most recently generated.
Date dt = new Date();
long time;
time = dt.getTime();
rd.setSeed(time);
value = (float)Math.random();
}*/
else
{ //seed>0 the next rand
rd.setSeed( seed + (int)Math.random() );//
value = (float)Math.random();
}
return value ;
}
public static float RND(double d_seed) throws HpException
{
float value = 0;
int seed = (int)d_seed;
java.util.Random rd = new java.util.Random();
if( seed==0 )
seed=-1;
if( seed<0 )
{ //seed<0 return same value
rd.setSeed(seed);
value = rd.nextFloat();
}
/*
else if( seed==0 )
{ //seed=0 The number most recently generated.
Date dt = new Date();
long time;
time = dt.getTime();
rd.setSeed(time);
value = (float)Math.random();
}*/
else
{ //seed>0 the next rand
rd.setSeed( seed + (int)Math.random() );//
value = (float)Math.random();
}
return value ;
}
public static float RND(HCurr vc_seed) throws HpException
{
float value = 0;
double tmp = vc_seed.dblValue();
int seed = (int)Math.round(tmp);
java.util.Random rd = new java.util.Random();
if( seed==0 )
seed=-1;
if( seed<0 )
{ //seed<0 return same value
rd.setSeed(seed);
value = rd.nextFloat();
}
/*
else if( seed==0 )
{ //seed=0 The number most recently generated.
Date dt = new Date();
long time;
time = dt.getTime();
rd.setSeed(time);
value = (float)Math.random();
}*/
else
{ //seed>0 the next rand
rd.setSeed( seed + (int)Math.random() );//
value = (float)Math.random();
}
return value ;
}
public static float RND(HDate vd_seed) throws HpException
{
float value = 0;
double tmp = vd_seed.dblValue();
int seed = (int)Math.round(tmp);
java.util.Random rd = new java.util.Random();
if( seed==0 )
seed=-1;
if( seed<0 )
{ //seed<0 return same value
rd.setSeed(seed);
value = rd.nextFloat();
}
/*
else if( seed==0 )
{ //seed=0 The number most recently generated.
Date dt = new Date();
long time;
time = dt.getTime();
rd.setSeed(time);
value = (float)Math.random();
}*/
else
{ //seed>0 the next rand
rd.setSeed( seed + (int)Math.random() );//
value = (float)Math.random();
}
return value ;
}
public static float RND(fixedString fixedstr_seed) throws HpException
{
float value = 0;
double tmp = hpstring.strtodbl( fixedstr_seed.strValue() );
int seed = (int)Math.round(tmp);
java.util.Random rd = new java.util.Random();
if( seed==0 )
seed=-1;
if( seed<0 )
{ //seed<0 return same value
rd.setSeed(seed);
value = rd.nextFloat();
}
/*
else if( seed==0 )
{ //seed=0 The number most recently generated.
Date dt = new Date();
long time;
time = dt.getTime();
rd.setSeed(time);
value = (float)Math.random();
}*/
else
{ //seed>0 the next rand
rd.setSeed( seed + (int)Math.random() );//
value = (float)Math.random();
}
return value ;
}
public static float RND(String strseed) throws HpException
{
float value = 0;
double tmp = hpstring.strtodbl(strseed);
int seed = (int)Math.round(tmp);
java.util.Random rd = new java.util.Random();
if( seed==0 )
seed=-1;
if( seed<0 )
{ //seed<0 return same value
rd.setSeed(seed);
value = rd.nextFloat();
}
/*
else if( seed==0 )
{ //seed=0 The number most recently generated.
Date dt = new Date();
long time;
time = dt.getTime();
rd.setSeed(time);
value = (float)Math.random();
}*/
else
{ //seed>0 the next rand
rd.setSeed( seed + (int)Math.random() );//
value = (float)Math.random();
}
return value ;
}
/*--- Function: Round(expression)
public static Variant ROUND( Variant expression ) throws HpException
{
double d = hpstring.get_db(expression);
return new Variant( (double)Math.round(d) );
} ---*/
/*--- Function: Round(expression, numdecimalplaces )
public static Variant ROUND( Variant expression ,Variant numdecimalplaces) throws HpException
{
String str;
double d, powd=0;
int position;
position = (int)Math.round( hpstring.get_db(numdecimalplaces) );
if( position>17 && position<0 )
throw new HpException(5, "Invalid procedure call");
double expr = hpstring.get_db(expression) ;
d = Math.floor(expr * Math.pow((double)10,(double)position ) + 0.5 ) / (Math.pow((double)10,(double)position ) );
/*
position = (int)Math. hpstring.get_db(numdecimalplaces) );
if( position>17 && position<0 )
throw new HpException(5, "Invalid procedure call");
d = hpstring.get_db(expression);
str = Double.toString(d);
int E_char = str.indexOf('E');
if( E_char!=-1 ) //the value is float type by stored
{
String substr2, substr3="" ,substr1="" ;
int substr1_len, substr2_len, digit;
if( str.charAt(0)=='-' || str.charAt(0)=='+' )
substr1 = str.substring(0,2);
else
substr1 = str.substring(0,1);
substr1_len = substr1.length();
substr2 = str.substring(substr1_len+1, E_char);
substr2_len = substr2.length();
digit = Integer.parseInt( str.substring(E_char+1) );
//redjust
if( substr2_len>digit )
{
substr2 = str.substring(substr1_len+1, substr1_len+1+digit);
substr3 = '.' + str.substring(substr1_len+1+digit, E_char);
}
else if( substr2_len<digit )
{
int i = digit - substr2_len;
while( (i--) !=0 )
substr3 = substr3.concat("0");
}
str = substr1 + substr2 + substr3;
}
int dot = str.indexOf('.');
String tmpstr = str;
try
{
if( dot!=-1 )
str = str.substring(0,dot) + str.substring(dot, dot + (int)position+1) ;
}catch(StringIndexOutOfBoundsException err)
{
; // if dot = str.length()
}
Double dbl = new Double( str);
d = dbl.doubleValue();
if( position+dot+1 <= tmpstr.length() )
{
if( tmpstr.charAt( position+dot+1)>='5' )
{
powd = d>0 ? Math.pow((double)10, -(position) )
: (-Math.pow((double)10, -(position) ) );
d += powd;
}
}
/
return new Variant( d);
} ---*/
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?