⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 globalfun_imp.cpp

📁 支持简单的公式推导
💻 CPP
字号:
#include "stdafx.h"
#include "tdafx.h"

double c_very_small=0.0001;

string ModifyNumber(double in,const string& m,bool IsPostfix)
{
	string y;
	
	if (fabs(in) > c_very_small && fabs(in-1) > c_very_small )
	{   
		if (!IsPostfix)
			y += m ;
	
        char tmp[20];
		//if ((in - int(in)) < c_very_small) // it is a int
	    // wrong !!!
		if (fabs(in - int(in)) < c_very_small)
		    y += itoa(in,tmp,10);
		else
		{ sprintf(tmp,"%.3f",in);
          y += tmp;
		}
		//y += ')';
		if (IsPostfix)
			y += m;
	}
    return y;
}



string ForConst(double in) 
{   
	//cout<<"in ForConst in = "<<in<<endl; 
	char tmp[10];
	//if ((in - (int)(in)) < c_very_small)
    if (fabs(in - int(in)) < c_very_small)
	{   
		return itoa(in,tmp,10);
	}

	else
	{
		sprintf(tmp,"%5.3f",in);
		string y = tmp;
		if (y[y.size() - 1] == '.')
			y.resize(y.size()-1);
		return y;
	}

}

string ForPower(const string& o,/*int times*/double times)
{   
	string y   = o;    
	string tmp = ModifyNumber(times," ^ ",false);
	if (!tmp.empty())
		//return "(" + y + tmp + ")";
		return y + tmp; // 可供选择
	else
		return y;
	
}

string ForSum(double head,const string frame)
{
	
	if( fabs(head) < c_very_small)    // head == 0
	{
		trace ("常数项为0\n");
		if (frame.empty())
			return "0";
		else
			return frame;
	    }
	else                          //head != 0                  
		{   
			if (frame.empty())
			{
				trace("变量项为0\n");
				//return Const(head).GetExpression();
				return ForConst(head);
			}
			else
				return ForConst(head) + " + " + frame;
		}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -