鼎元C++量化程式码指标与函数模块系列之【max2(a,b)、max3(a,b,c)、min2(a,b)、min3(a,b,c)】
1、头文件声明变量:[code]double max2(double a, double b);//返回a,b中较大值
double max3(double a, double b, double c);//返回a,b,c中最大值
double min2(double a, double b); //返回a,b中较小值
double min3(double a, double b, double c);//返回a,b,c中最小值
[/code]2、在源文件中公式模块区增加下列计算公式函数:[code]
double test::max2(double a, double b)
{
double c = 0;
if (a >= b)
{
c = a;
}
else
{
c = b;
}
return c;
}
double test::max3(double a, double b, double c)
{
double d = 0;
if (a >= b)
{
d = a;
}
else if (a < b)
{
d = b;
}
if (d < c)
{
d = c;
}
return d;
}
double test::min2(double a, double b)
{
double c = 0;
if (a >= b)
{
c = b;
}
else
{
c = a;
}
return c;
}
double test::min3(double a, double b, double c)
{
double d = 0;
if (a >= b)
{
d = b;
}
else if (a < b)
{
d = a;
}
if (d > c)
{
d = c;
}
return d;
}
[/code]3、使用方法:[code]
max2(8,10) 返回10;max3(8,5,9)返回9;
[/code]
页:
[1]