Coder Social home page Coder Social logo

ntdls / cmathparser Goto Github PK

View Code? Open in Web Editor NEW
21.0 21.0 6.0 92 KB

A fairly robust mathematics parsing engine for C++ projects.

License: MIT License

Batchfile 0.36% C++ 99.64%
evaluation expression-parser library math mathematics parsing showcase

cmathparser's Introduction

  • ๐Ÿ‘‹ Hi, I'm @NTDLS (AKA Josh Patterson).
  • ๐Ÿ‘€ I'm interested in C / C++ / C# and the Sea (mainly the Atlantic as I live in Charleston SC).
  • ๐Ÿ’… The line above was misleading, I also enjoy everything between assembly and SQL.
  • ๐ŸŒฑ I'm currently learning to create Change Requests and enter tickets for pretty much anything that needs to be done.
  • ๐Ÿ’ž๏ธ I'm looking to collaborate on:
  • ๐Ÿ“ซ How to reach me: โœจ [email protected] โœจ <---Yea, I posted that. Sue me.
  • My website is: http://networkdls.com/

cmathparser's People

Contributors

ntdls avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cmathparser's Issues

Nested powers

Yo, this thing is awesome, just doing some messing around with it now, this could very well be user error, but I found that "sin(pow(10,2))" gives me this error, but it works the other way round ("pow(sin(10))" for example), wondering if I'm just missing something or if something wacky is going on with powers in other functions!
Either way this is amazing, looking forward to messing around more with it!
(Edit, I did find a workaround by parsing the string for pow and solving that as a seperate expression!)
image

Compiler Error C2440

When trying to compile the code I am receiving Compiler Error C2440 at:

sOp = "!";

CMathParser/CMathParser.cpp

Lines 737 to 748 in ae5b5fe

if (pSubExp->Text[iOpPos] == '*') {
sOp = "*";
}
else if (pSubExp->Text[iOpPos] == '/') {
sOp = "/";
}
else if (pSubExp->Text[iOpPos] == '%') {
sOp = "%";
}
else if (pSubExp->Text[iOpPos] == '~') {
sOp = "~";
}

CMathParser/CMathParser.cpp

Lines 771 to 776 in ae5b5fe

if (pSubExp->Text[iOpPos] == '-') {
sOp = "-";
}
else if (pSubExp->Text[iOpPos] == '+') {
sOp = "+";
}
error C2440: '=': cannot convert from 'const char [2]' to 'char *'

I am using Visual Studio C++20 but I get the same error switching from 20 to 17 or 14 so I am not sure how you are compiling this without any issues. If you have any workarounds for this I will gladly try them out, I just thought I would create this issue incase it's the compiler I am using or maybe some other issue.

Variable support

This looks super interesting for a OSS project I'm working on (and it looks like nice, clean code). However I need to support variables. Basically I'll have a number of these expressions and some will use expressions or literals to define variables and yet other expressions will use these variables, etc. etc.
Have you thought about supporting that? If not, where would be the best place to inject variable detection and handling in this code?

Segmentation fault when using multiple variables in the expression

Hi,

I'm testing the library using expressions containing more than one variable.

These expression for example are causing segmentation fault:

X+X
X+Y
X*X
... and so on

The reason is the following code:

	//Get variable value...
	if (this->pVariableSetProc!=NULL){
		if(!this->pVariableSetProc(this, sVarName, &dVarValue))
		{
			return this->SetError(ResultInvalidToken, "Variable not defined: %s.", sVarName);
		}
	} else {
		return this->SetError(ResultInvalidToken, "Variable not defined: %s.", sVarName);
	}

	char sVarValue[64];
	//Convert double to string (must be a faster way, but this is just super safe and doesn't create infinite repeating patterns).
	//TODO: Fixed percision of 8 on variables seems inflexible.
	int iVarValLength = sprintf_s(sVarValue, sizeof(sVarValue), "%.8f", dVarValue);

	if (iSourceSz + iVarValLength >= pExp->Allocated)
	{
		pExp->Allocated = (iSourceSz + iVarValLength) + 1;
		pExp->Text = (char*)realloc(pExp->Text, sizeof(char) * pExp->Allocated);
		if (!pExp->Text)
		{
			return this->SetError(ResultMemoryAllocationError, "Memory allocation error.");
		}
	}

Have you tried to use more than one variable in the expression?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.