CxTranslator 4.1.264

dotnet add package CxTranslator --version 4.1.264                
NuGet\Install-Package CxTranslator -Version 4.1.264                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CxTranslator" Version="4.1.264" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CxTranslator --version 4.1.264                
#r "nuget: CxTranslator, 4.1.264"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CxTranslator as a Cake Addin
#addin nuget:?package=CxTranslator&version=4.1.264

// Install CxTranslator as a Cake Tool
#tool nuget:?package=CxTranslator&version=4.1.264                

CxTranslator implements simple data type to cover complex numbers: real and imaginary parts. You can find definition of TCalc in EquTypes.h :

	typedef double CmpBaseType;
	template<class T>  struct TCalc_t { T real; T imag; };
	typedef TCalc_t<CmpBaseType> TCalc;

Using simple structure instead of standard class library for C++ std::complex<double> it extends the number of consumers for CxTranslator and simplifies integration of the component into different programming languages and calculation environments. Imag part in math expression should have postfix i or j. For example: 3.5j

The valid math expressions should consist of:

  • Variables should start from letter and be no more than 32 characters. The math expression may have unlimited number of variables.
  • Arithmetic operations : +, -, *, / , ^.
  • Functions - set of predefined functions : abs, acos, acosh, arg, asin, asinh, atan, atanh, conj, cos, cosh, exp, imag, log, log10, norm, proj, real, sin, sinh, sqrt, tan, tanh. Also, users can define their own function to improve performance and extend functionality.

The main characteristics of CxTranslator:

  • Extremely fast.
  • Friendly interface and error handling mechanism support.
  • Safe Multithreading.
  • Supports unlimited number of variables.
  • Math expression must be double byte(UNICODE) string.
  • Can be extended by user defined functions. Target platform : x86 and x64.
#include <iostream>
#include <complex>

#define _USE_CXTRANSLATOR
#include "EquTypes.h"
#include "CxWin32.h"



// Error handler
void  ErrorHandler(EQUHANDLE hnd, int errCode, const wchar_t* message, const wchar_t* message2)
{
	std::cout << "Error: " << message << ": " << message2 << std::endl;
	throw errCode;
}


//User defined function
TCalc  pow3(const TCalc& x)
{
	//Must convert to std::Complex first
	std::complex<double> cmplx(x.real, x.imag);

	//Do calculation
	std::complex<double> tmp = cmplx * cmplx * cmplx;

	//Transform result to TCalc data type
	TCalc result = { tmp.real(), tmp.imag() };
	return result;
}


//	Operator overload example ... just for this sample
std::complex<double>& operator += (std::complex<double>& cmp, const TCalc& cx)
{
	cmp.real(cmp.real() + cx.real);
	cmp.imag(cmp.imag() + cx.imag);
	return cmp;
}

TCalc& operator += (TCalc& cmp, const TCalc& cx)
{
	cmp.real = cmp.real + cx.real;
	cmp.imag = cmp.imag + cx.imag;
	return cmp;
}


int main(int argc, char* argv[])
{
	const wchar_t* mathExp = L"x+2.3i*(1-sin(y/3.14)^2)-z";
	const wchar_t* varList = L"x,y,z";
	TCalc args[] = { { 1.1, 2.5 },{ 1.7e-2, 0.32 },{ 3.14, 2.92 } };
	TCalc res = { 0,0 };
	std::complex<double> cmpResult(0, 0);
	CXHANDLE cxHnd = NULL;


	// Initialize EquTranslator algorithm before we can use any function.
	// Return value (handle) must be used in each function call.
	cxHnd = InitCxTranslator(
		ErrorHandler   //Error callback function
	);

	try
	{
		//Evaluate math expression for a given point "args"
		res = Evaluate(cxHnd, mathExp, varList, args);

		args[0].real = 2.3; args[0].imag = 1.3;
		args[1].real = -5;	args[1].imag = 0.123;
		res = Evaluate(cxHnd, L"x/y+5-3.1j+(x^2-y^2)", L"x,y", args);

		//Add user's function to CxTranslator
		AddFunction(cxHnd, L"p3", pow3);

		//Calculate a set of points for one math expression
		//Build it first
		Build(cxHnd, L"3.14*p3(x)+sin(y)-sqrt(z+x)", L"x,y,z");


		for (int i = 0; i < 100; i++)
		{
			args[0].real = args[0].real + 1; args[0].imag = i;
			args[1].real = i / 200;	args[1].imag = 0.005 * i;
			args[2].real = -5;	args[2].imag = args[0].real * 0.123;

			// Do calculation for a given point
			cmpResult += CalcFor(cxHnd, args);
		}

		//Another functions to calculate a set of points for a given expression
		Compile(cxHnd, mathExp, varList, args);

		TCalc cxResult = { 0, 0 };
		for (int i = 0; i < 10000; i++)
		{
			args[0].real = args[0].real + 0.0001; args[0].imag = i;
			args[1].real = i / 2000;	args[1].imag = i / 10000;
			args[2].real = -5;	args[2].imag = args[0].real * 0.0123;

			// Do calculation for a given point
			cxResult += Run(cxHnd);
		}


		//Negative test
		RemoveFunction(cxHnd, L"p3");
		res = Evaluate(cxHnd, L"3.14*p3(x)+sin(y)-sqrt(z+x)", L"x,y,z", args);


	}
	catch (int errCode)
	{
		std::cout << "Error code: " << errCode << std::endl;
	}

	//Release resources
	CloseCxTranslator(cxHnd);

	return 0;
}
Product Compatible and additional computed target framework versions.
native native is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • native 0.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.1.264 415 2/26/2021
4.0.101 524 11/13/2019