Jump to content


Photo

Calculator Dll - Evaluate User Input!


  • Please log in to reply
14 replies to this topic

#1 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 05 December 2008 - 12:37 PM

This dll can evaluate expressions and also has better functions for converting strings to reals and reals to strings.

For example, you can let the user enter something like "4*(5+6)-sin(1/3*pi)" and the dll will calculate the result.

The calculator supports:
- Standard operators: +, -, * and /
- Scientific notation (1.52e8)
- Brackets
- Functions (see function list below)
- Constants

The dll also contains functions for converting strings to reals and reals to strings, as the standard GM functions are very limited and often crash if the numbers are too large.

The syntax and functions supported by the dll work the same as in GM. The following functions are supported:
abs(x)
sign(x)
round(x)
floor(x)
ceil(x)
frac(x)
sqrt(x)
sqr(x)
power(x,n)
exp(x)
ln(x)
log2(x)
log10(x)
logn(n,x)
sin(x)
cos(x)
tan(x)
arcsin(x)
arccos(x)
arctan(x)
arctan2(y,x)
degtorad(x)
radtodeg(x)
mod(x,divisor)
div(x,divisor)
min(x1,x2,x3,...)
max(x1,x2,x3,...)
mean(x1,x2,x3,...)
median(x1,x2,x3,...)
point_distance(x1,y1,x2,y2)
point_direction(x1,y1,x2,y2)
lengthdir_x(len,dir)
lengthdir_y(len,dir)
The dll also supports constants pi and e.

Download: Calculator Dll - ZIP (38.3kb)

The zip file contains the dll (and scripts), the extension, an example (gmk) and a help file.

Edited by Maarten Baert, 17 September 2012 - 11:34 AM.

  • 1
Posted Image

#2 Recreate

Recreate

    Furry

  • GMC Member
  • 2992 posts
  • Version:GM:Studio

Posted 06 December 2008 - 07:52 PM

what does this do?
  • 0

If the post that you are reading was created prior to 2011. For the safety of the general public, It is not to be regarded under any circumstances.
Please don't ask me to join your group at anything.


#3 fire_soul453

fire_soul453

    aarons video games

  • GMC Member
  • 542 posts

Posted 06 December 2008 - 09:33 PM

Its used to evaluate expressions and to convert strings to reals and reals to strings. And according to him it can handle larger numbers than gm.
  • 0
Game maker Top sites
I'm sick of paypal. From now on I'm not buying indie games unless I can use something else...

#4 $pecter

$pecter

    GMC Member

  • GMC Member
  • 1616 posts
  • Version:GM8

Posted 07 December 2008 - 02:52 AM

I don't see the point to this. The overhead for calling the DLL would be bigger than that of calling the corresponding Game Maker function. If Game Maker can't handle the big numbers then there's not much chance of GM passing a big number to the dll or being able to receive a big number back. Please, by all means, correct me if I'm wrong.

Edited by $pecter, 07 December 2008 - 02:53 AM.

  • 0

#5 Mnementh

Mnementh

    15151

  • GMC Elder
  • 6400 posts
  • Version:GM:Studio

Posted 07 December 2008 - 03:14 AM

The overhead for calling the DLL would be bigger than that of calling the corresponding Game Maker function.

If I understand it right, the issue isn't calling the appropriate function, but parsing the expression into a format that the computer can execute. This isn't to hard to do, using the shunting-yard algorithm to convert to RPN, and them executing the result (or another method), but it may be enough to justify the overhead. I don't know how much of an overhead there actually is, so I can't say for sure.
  • 0

#6 mrsmes

mrsmes

    GMC Member

  • GMC Member
  • 1506 posts
  • Version:GM:Studio

Posted 07 December 2008 - 09:23 AM

either way, $pecter looks like we found what we need for the calculator part of our dock. We will give credits the list maybe growing but so is the features and employees then thus we make more money and sell more of the dock, and pay each employee there weight in money practically.
  • 0

Assuming I helped you out in a questions and answers topic won't you return the favour by helping me with one my coding problems, or recommend some one who can chat to me over pms about helping and how to overcome my obstacles, after all lets just say I did help you or them or many people with similar problems, in that topic.

Here i have a topic for those of you struggling with type writer text and mugshots in your games especially if it is a rpg see the link below for more info

http://gmc.yoyogames...howtopic=619103

almost no code needed, only uses two events.

click here for the l8est version of feed the alien pizza, it has some major polished up features.


#7 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 07 December 2008 - 01:04 PM

The problem is not calling the functions, but parsing the expression. If you would try to parse it in GML, it is incredibly slow (I tried :) ). This DLL was written in C++, making the parsing a lot faster. It's like execute_string, but without the dangerous functions (like script_get_text, background_save, ...) and without GM error messages.

The problem with GM's real-to-string function is that it will try to convert the real to an 4-byte integer first, and then convert the integer to a string. This will not work with numbers that are too large.
var i,number;

number = 1;
for(i=0;i<100;i+=1) { // set number to 1e100
number *= 10;
}

switch show_message_ext('Function?','string','','calc_real2str') {
case 1:
show_message('Result: "'+string(number)+'"'); // will crash
break;
case 3:
show_message('Result: "'+calc_real2str(number,0,0,8,false,false)+'"'); // will not crash
show_message('Result: "'+calc_real2str_e(number,0,0,8,false,false)+'"'); // will not crash
show_message('Result: "'+calc_real2str_best(number,0,0,8,false,false)+'"'); // will not crash
break;
}

show_message('The end of the code was reached.');
If you use the string function, the game will crash and you won't see the 'The end of the code was reached.' message.

Another problem is converting strings to reals. In Game Maker, this is the only way to let the user enter a real number, as there is no function like get_real (lol :) ), only get_string and get_integer. The real() function will display GM error messages if the string is not a valid real number, or crash if the number is too large.

This isn't to hard to do, using the shunting-yard algorithm to convert to RPN, and them executing the result (or another method), but it may be enough to justify the overhead. I don't know how much of an overhead there actually is, so I can't say for sure.

I have no idea what you are talking about :P . The DLL converts the expression to a list of values and operators, and uses recursion to calculate expressions in brackets.

Edited by matrebatre, 07 December 2008 - 01:22 PM.

  • 0
Posted Image

#8 Drara

Drara

    GMC Member

  • GMC Member
  • 325 posts

Posted 26 August 2012 - 11:23 PM

This thing looks interesting!
Could you reupload please? The link doesn't anymore (for me at least)..

Edited by Drara, 27 August 2012 - 02:46 AM.

  • 0

#9 Maarten Baert

Maarten Baert

    GMC Member

  • GMC Member
  • 750 posts
  • Version:GM8.1

Posted 17 September 2012 - 11:35 AM

Link fixed. The file itself was still there, only the domain name changed.
  • 0
Posted Image

#10 ShubhamBansod

ShubhamBansod

    ͡ ͜ʖ ͡

  • GMC Member
  • 371 posts
  • Version:GM:Studio

Posted 10 February 2014 - 03:38 AM

i am using 3d skeleten like animation by gm's model transformation it uses a huge calculation.. so if i use this dll does it increase by proformance ...
thnxx.
  • 0

If i Help u ...click the + sign below.....


#11 Dragonite

Dragonite

    GMC Member

  • GMC Member
  • 69 posts
  • Version:GM:Studio

Posted 04 October 2015 - 05:24 PM

Getting back to the conversations from seven or so years ago, this looks like it could be really useful for validating/evaluating user input (i.e. I have a command line that you can write stuff to, but currently that "stuff" is only exact values since implementing this in GM would be a whole new meaning to "slow").

In either case, looks really interesting, thanks for making it!
  • 0

zIatugK.png


#12 GrixM

GrixM

    GMC Member

  • GMC Member
  • 424 posts
  • Version:GM:Studio

Posted 04 October 2015 - 09:06 PM

Getting back to the conversations from seven or so years ago, this looks like it could be really useful for validating/evaluating user input (i.e. I have a command line that you can write stuff to, but currently that "stuff" is only exact values since implementing this in GM would be a whole new meaning to "slow").

In either case, looks really interesting, thanks for making it!

 

FYI There is a better extension for this: http://gmc.yoyogames...howtopic=616118

It is more updated and has more features than this DLL.


Edited by GrixM, 04 October 2015 - 09:06 PM.

  • 0

#13 Paolo Mazzon

Paolo Mazzon

    Has Too Much Time

  • GMC Member
  • 811 posts
  • Version:GM:Studio

Posted 10 December 2015 - 03:55 AM

 

Getting back to the conversations from seven or so years ago, this looks like it could be really useful for validating/evaluating user input (i.e. I have a command line that you can write stuff to, but currently that "stuff" is only exact values since implementing this in GM would be a whole new meaning to "slow").

In either case, looks really interesting, thanks for making it!

 

FYI There is a better extension for this: http://gmc.yoyogames...howtopic=616118

It is more updated and has more features than this DLL.

 

In case you're wondering, it's quite rude to post "there is something else better than this don't use this" on someone's post.


  • 0

#14 Lonewolff

Lonewolff

    Permanent Resident

  • GMC Member
  • 3517 posts
  • Version:GM:Studio

Posted 10 December 2015 - 04:13 AM

Why necro this just to point that out?
  • 0

#15 Paolo Mazzon

Paolo Mazzon

    Has Too Much Time

  • GMC Member
  • 811 posts
  • Version:GM:Studio

Posted 11 December 2015 - 12:04 AM

Why necro this just to point that out?

Because it's rude. Why do it to me for pointing it out? I feel that that is unjustified.

 

On top of that, why give him a point for being rude? I mean, are you just trying to prove a point to me?


Edited by Paolo Mazzon, 11 December 2015 - 12:05 AM.

  • 0