MathEval.dll  A lightweight mathematical parser

Copyright 2010-2017 Roberto Bianchi

Softspecialists - www.softspecialists.com

Introduction

MathEval is a math parser that offers besides the traditional operators also advanced mathematicals, trigonometrics and conversion functions.

MathEval is compatible with all versions of Windows starting with version 98.

Using MathEval

MathEval is implemented as DLL that export two functions using the __stdcall calling convention like all Win32 API functions.

You can use the MATHEVAL.DLL both using dynamic or static linkage as showed in the sample code provided with the library.

Reference

 

int Evaluate(LPMATHEVAL)

Evaluate a math string espression using a provided pointer to MATHEVAL structure that holds it, see below the allowed operators and functions. The function returns zero in case of success otherwise returs the errore code (same value of wErrorCode field of the MATHEVAL structure).

 

LPSTR GetErrorText(wError)

Return a pointer to ASCIIZ string that describe the wError.

 

MATHEVAL

The structure used for data exchange, see details on examples showed below.

 

Exampleses

Here are the some code fragments for VISUAL STUDIO 2010 EXPRESS C++ and POWER BASIC compilers:

The picture below shows a C++ dynamic linking example.

C Dynamic

The picture below shows a C++ example with static linking.

C Static

The picture below shows a PowerBASIC dynamic linking example.

PB Dynamic

The picture below shows a PowerBASIC example with static linking.

PB Static

Complete sources are encloses in the appropriate download.

Operators and functions recognized by Evaluate()

MATHEMATICAL OPERATORS:

 

+

Addition.

 

Subtraction and negation.

 

*

Multiplication.

 

/

Division.

 

^

Exponentiation.

 

()

Parentheses.

 

AND

Bitwise AND arithmetic operator.

 

MOD

Calculate the remainder of the division.

 

OR

Bitwise OR arithmetic operator.

 

XOR

Bitwise XOR arithmetic operator.

MATHEMATICAL FUNCTIONS:

 

ABS

Returns the absolute value.

 

EXP

Returns e raised to the nth power.

 

EXP2

Returns 2 raised to the nth power.

 

EXP10

Returns 10 raised to the nth power.

 

FACT

Returns the factorial.

 

FRAC

Returns the fractional part.

 

INT

Returns the integer part

 

LC

Returns the value obtained by the last (valid) calculation. Available only from version 1.2.

 

LN

Returns the natural (base e) logarithm.

 

LOG

Returns the common (base 10) logarithm.

 

LOG2

Returns the base 2 logarithm.

 

MAX

Returns the maximum value between 2 values.

 

MIN

Returns the minimum value between 2 values.

 

NOT

Returns the bitwise NOT.

 

POW

Returns the power (exponentiation).

 

RND

Returns a random value.

 

ROUND

Returns then rounded value.

 

SQR

Returns the square root.

 

SUM

Returns the summatory.

TRIGONOMETRICT FUNCTIONS:

 

ACOS

Returns the inverse cosine.

 

ACOSH

Returns the inverse hyperbolic cosine.

 

ASIN

Returns the inverse sine.

 

ASINH

Returns the inverse hyperbolic sine.

 

ATAN

Returns the Inverse Tangent.

 

ATANH

Returns the Inverse Hyperbolic Tangent.

 

COS

Returns the Cosine of an angle specified in degree.

 

COSH

Returns the Hyperbolic Cosine.

 

PI

Returns the pi value.

 

SIN

Returns the Sine of an angle specified in degree.

 

SINH

Returns the Hyperbolic Sine.

 

TAN

Returns the Tangent of an angle specified in degree.

 

TANH

Returns the Hyperbolic Tangent.

CONVERSION FUNCTIONS:

 

DEG

Converts Radians To Degrees.

 

RAD

Converts Degrees To Radians.

 

METER2FEET

Converts METER to FEET.

 

FEET2METER

Converts FEET to METER.

 

MILE2FEET

Converts MILE to FEET.

 

FEET2MILE

Converts FEET to MILE.

 

INCH2CM

Converts INCH to CENTIMETRE.

 

CM2INCH

Converts CENTIMETRE to INCH.

 

MILE2YARD

Converts MILE to YARD.

 

YARD2MILE

Converts YARD to MILE.

 

MILE2KM

Converts MILE to KILOMETER.

 

KM2MILE

Converts KILOMETER to MILE.

 

GALLON2LITRE

Converts US GALLON to LITRE.

 

LITRE2GALLON

Converts LITRE to US GALLON.

 

FOOT2INCH

Converts FOOT to INCH.

 

INCH2FOOT

Converts INCH to FOOT.

 

OUNCE2GRAM

Converts OUNCE to GRAM.

 

GRAM2OUNCE

Converts GRAM to OUNCE.

 

POUND2OUNCE

Converts POUND to OUNCE.

 

OUNCE2POUND

Converts OUNCE to POUND.

 

KG2POUND

Converts KILOGRAM to POUND.

 

POUND2KG

Converts POUND to KILOGRAM.

 

FAHR2CELS

Converts FAHRENHEIT to CESIUS degree.

 

CELS2FAHR

Converts CESIUS to FAHRENHEIT degree.

OTHERS FUNCTIONS:

 

DWORD

Makes a double word and returns it.

 

HIB

Extract the hight BYTE from a WORD value.

 

HIW

Extract the hight WORD from a DWORD value.

 

LOB

Extract the low BYTE from a WORD value.

 

LOW

Extract the low WORD from a DWORD value.

 

SECINDAY

Returns the number of seconds in the whole day.

 

WORD

Makes a word and returns it.

Note

With the version 1.2 of MathEval.dll the initialization of MATHEVAL's wSize field is optional.

The current versions of CCALC.EXE and DTCALC.EXE utilities are build using the MathEval.dll.