Skip to content

nirmalpaul383/MathPad_plus_

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MathPad+

MathPad+ is a lightweight mathematical expression playground powered by the ViewPoint. It was developed to demonstrate the power of ViewPoint and its advanced expression parsing and evaluation capabilities, including:

  • Inline variable and function definitions
  • Inline variable access and function calls
  • Nested expression evaluation with nested function calls
  • Unary and ternary operators
  • Strict runtime type checking with data-type mixing prevention
  • And many more advanced features

MathPad+ supports all 85+ built-in functions provided by the ViewPoint v2.1.2 . It also supports user-defined inline custom functions, enabling powerful and flexible mathematical programming.

ViewPoint, the program behind the MathPad+, is a mathematical expression parser and evaluator written entirely in vanilla JavaScript. It features runtime data-type checking and advanced expression evaluation capabilities. Both ViewPoint and MathPad+ were originally designed and developed by me, Nirmal Paul (N Paul). For more project you can visit my GitHub Profile


Available on

  • Web:

    • Open the MathPad+ in your browser using the following link.
    • Alternatively, download or clone this repository and open the index.html in your browser.
  • Android:

    • Download the latest .apk file from the Releases section of this repository or click here.
    • Install the .apk file on your android device
    • launch the MathPad+ app.

Note:

  • Minimum Android version: Android 5.0 (API: 21)
  • Target Android version: Android 14 (API: 34)
  • Android version is developed using the Sketchware Pro v7.0.0
  • The Android version is essentially a WebView-based wrapper of the web version, so both platforms provide the same features and user experience.
Android version:
Android version: Image 1 Android version: Image 2

Tables of contents


Execution Modes

MathPad+ supports two execution modes:

  • Terminal Mode: A REPL (Read-Eval-Print Loop) console-like environment where users can enter and evaluate mathematical expressions interactively. This mode is ideal for quick calculations, experimentation, testing functions, and exploring mathematical logic in real time.
  • Interpreter Mode: A multi-statement execution environment that accepts multiple expression statements and interprets them line by line. This mode is suitable for writing larger mathematical programs involving variables, custom functions, and complex expression workflows.
Terminal Mode:
Terminal Mode: Image 1 Terminal Mode: Image 2
Interpreter Mode:
Interpreter Mode: Image 1 Interpreter Mode: Image 2

⬆ Back to the Tables of Contents ⬆


Operators

MathPad+ supports all operators available in ViewPoint v2.1.2 . Here is complete reference:

Type Operator Default precedence Details Example
Unary Operator + Highest Indicates a positive value +25 *2 returns 50
Unary Operator - Highest Indicates a negative value -25 *2 returns -50
Arithmetic Operator ^ or ** 11 calculates a base number raised to the power of an exponent 2 ** 3 returns 8
Arithmetic Operator * 10 Multiplies two operands 2 * 3 returns 6
Arithmetic Operator / 9 Multiplies two operands 6 / 3 returns 2
Arithmetic Operator % 9 Returns the remainder after division. 7 % 3 returns 1
Arithmetic Operator + 8 Adds two numbers or concatenates two strings. 7 +3 returns 10

"Hello " + "Word" returns 'Hello word'
Arithmetic Operator - 8 Subtracts the right operand from the left operand. 7 - 3 returns 4
Comparison Operator < 7 Returns true if the left operand is less than the right operand, otherwise returns false. 3 < 7 returns true
Comparison Operator > 7 Returns true if the left operand is greater than the right operand, otherwise returns false. 8 < 5 returns true
Comparison Operator <= 7 Returns true if the left operand is less than or equal to the right operand, otherwise returns false. 10 <= 50 returns true
Comparison Operator >= 7 Returns true if the left operand is greater than or equal to the right operand, otherwise returns false. 100 >= 50 returns true
Comparison Operator == 6 Returns true if both operands are equal, otherwise returns false. 100 == 100 returns true
Comparison Operator != 6 Returns true if both operands are not equal, otherwise returns false. 100 != 50 returns true
Bitwise Operator & 5 Performs a bitwise AND operation on two operands. 5 & 3 returns 1
Bitwise Operator | 4 Performs a bitwise OR operation on two operands. 5 | 3 returns 7
Logical Operator && 3 Returns true if both operands are true, otherwise returns false. true && true returns true
Logical Operator || 2 Returns true if any of one operand is true, otherwise returns false. true || false returns true
Assignment operators =
+=
-=
*=
/=
1 Performs in-line variable assignment. Explore the variable assignment operators and their usage.
New line operators \n
\r
;
0 Separates multiple expressions in terminal mode "1st string" ; "2nd string" \n "3rd string" returns ['1st string', '2nd string', '3rd string']
Comment Operator // Not Applicable Starts a single-line comment. Everything after it on the same line is ignored. 16+4 //This is 1st comment ; 21+5 //This is 2nd comment returns [ 20, 26 ]
Ternary Operator (cond) ? (what_to_do_if_true) : (what_to_do_if_false) Not Applicable If the codition is true then the what_to_do_if_true is evaluated otherwise the what_to_do_if_false is evaluated 45 > 8*5 ? "Yes" : "No" returns true
Unary Operator ! Not Applicable Returns false if the operand is true and returns true if the operand is false ! true returns false

! false returns true

⬆ Back to the Tables of Contents ⬆


Functions

MathPad+ includes all 85+ functions provided by the ViewPoint v2.1.2

Basic math and number related functions:

Function Name Details Example
abs (x) Returns the absolute value of a number. abs (-5) returns 5
sign (x) Returns -1 for negetive number, 0 for zero and 1 for positive number. sign (-45) returns -1
ceil (x) Returns the number rounded up to the nearest integer ceil (45.43) returns 46
floor (x) Returns the number rounded down to the nearest integer floor (45.43) returns 45
round (x) Returns the number rounded (up / down) to the nearest integer round (45.43) returns 45
trunc (x) Returns the number with the fractional part removed. trunc (53.75) returns 53
fract (x) returns the fractional part of the provided number by removing the integer part of that number. fract (53.75) returns 0.75

Power & Root functions:

Function Name Details Example
pow (x, y) Returns the value of x raised to the power of y. pow(5,3) returns 125
sqrt (x) Returns the square root of a number. sqrt(144) returns 12
cbrt (x) Returns the cube root of a number. cbrt(125) returns 5
hypot (x, y, ...) Returns the square root of the sum of squares of its arguments. hypot(3, 4) returns 5

Logarithmic functions:

Function Name Details Example
log (x) Returns the natural logarithm (base e). log(Const(E)) returns 1
log10 (x) Returns the base 10 logarithm. log10(100) returns 2
log2 (x) Returns the base 2 logarithm. log2(8) returns 3
log1p (x) Returns the natural logarithm of (1 + x), computed accurately for small values. log1p(1) returns 0.6931471805599453

Exponential functions:

Function Name Details Example
exp (x) Returns Euler's number e raised to the power of x exp(0) returns 1
expm1 (x) Returns Euler's number e raised to the power of x, minus one. expm1(0) returns 0

Trigonometry (angle value in radian) related functions:

Function Name Details Example
sin (x) Returns the sine (ratio) of an angle (radians). sin(0) returns 0
cos (x) Returns the cosine (ratio) of an angle (radians). cos(0) returns 1
tan (x) Returns the tangent (ratio) of an angle (radians). tan(0) returns 0
csc (x) Returns the cosecant (reciprocal sine ratio) of an angle (radians). (i.e. 1/sin(x)) csc(Const('PI')/2) returns 1
sec (x) Returns the secant (reciprocal cosine ratio) of an angle (radians). (i.e. 1/cos(x)) sec(0) returns 1
cot (x) Returns the cotangent (reciprocal tangent ratio) of an angle (radians). (i.e. 1/tan(x)) cot(Const('PI')/4) returns 1
asin (x) Returns the the angle (radians) whose sine is x asin(0) returns 0
acos (x) Returns the the angle (radians) whose cosine is x acos(1) returns 0
atan (x) Returns the the angle (radians) whose tangent is x atan(0) returns 0
atan2 (y,x) Returns the arctangent of the quotient of its arguments, using the signs of both arguments to determine the correct quadrant. atan2(0, 1) returns 0

Hyperbolic functions:

Function Name Details Example
sinh (x) Returns the hyperbolic sine of a number. sin(0) returns 0
cosh (x) Returns the hyperbolic cosine of a number. cosh(0) returns 1
tanh (x) Returns the hyperbolic tangent of a number. tanh(0) returns 0
csch (x) Returns the hyperbolic cosecant (reciprocal hyperbolic sine) of a number. (i.e. 1/sinh(x)) csch(1) returns 0.8509181282393216
sech (x) Returns the hyperbolic secant (reciprocal hyperbolic cosine) of a number. (i.e. 1/cosh(x)) sech(0) returns 1
coth (x) Returns the hyperbolic cotangent (reciprocal hyperbolic tangent) of a number. (i.e. 1/tan(x)) coth(1) returns 1.3130352854993315
asinh (x) Returns the inverse hyperbolic sine of a number. asinh(0) returns 0
acosh (x) Returns the inverse hyperbolic cosine of a number. acosh(1) returns 0
atanh (x) Returns the inverse hyperbolic tangent of a number. atanh(0) returns 0

Comparison functions:

Function Name Details Example
greaterThan (x, y) or > (x, y) greaterThan() or > () takes 2 parameters and compare if that the 1st parameter is greater than the second parameter or not > (67 , 5) returns true.
Same as the expression: 67 > 5
lessThan (x, y) or < (x, y) lessThan() or < () takes 2 parameters and compare if that the 1st parameter is less than the second parameter or not < (67 , 5) returns false.
Same as the expression: 67 < 5
isEqual (x, y) or == (x, y) isEqual () or == () takes 2 parameters and compare them and returns true if the both parameters are same, otherwise it returns false isEqual (60 , 50+10) returns true.
Same as the expression: 60 == 50 + 10
isNotEqual (x, y) or != (x, y) isNotEqual () or != () takes 2 parameters and compare them and returns false if the both parameters are same, otherwise it returns true isNotEqual (60 , 50+10) returns false.
Same as the expression: 60 != 50 + 10

Logical functions:

Function Name Details Example
and (x, y, ...) or &&(x, y, ...) and() or &&() tests each of its arguments , if all are true then it will return true and(true , false, true, false) returns false
or (x, y, ...) or ||(x, y, ...) or() or ||() tests each of its arguments , if any of its arguments is true then it will return true or (true , false, true, false) returns true
not (x) or !(x) not () or !() changes a 'true' value to a 'false' value and a 'false' value to a 'true' value not (false) returns true
if (condition, valueIfTrue, valueIfFalse) if() takes 3 parameters. 1st parameter is a condition parameter, if the condition is true then it returns 2nd parameter otherwise it returns 3rd parameter (if the 3rd parameter is not specified then its default value false will be return) if(50 < 100 , '50 is less than 100', '100 is less than 50') returns '50 is less than 100'

Bitwise functions:

Function Name Details Example
bitAnd (x , y) or & (x , y) bitAnd (x , y) or & (x , y) returns the bitwise AND ( & ) of those two parameters. bitAnd (5 , 1) returns 1
bitOr (x , y) or | (x , y) bitOr (x , y) or | (x , y) returns the bitwise OR ( | ) of those two parameters. bitAnd (5 , 1) returns 5
bitXor (x , y) or ^ (x , y) bitXor (x , y) or ^ (x , y) returns the bitwise XOR (exclusive OR) of those two parameters. bitXor (5 , 1) returns 4
bitNot (x) or ~ (x) bitNot (x) or ~ (x) returns the bitwise NOT ( ~ ) of the given parameter bitNot (5) returns -6
bitLShift (numberValue , positionValue) or << (numberValue , positionValue) bitLShift (numberValue , positionValue) or << (numberValue , positionValue) returns the Bitwise Left Shifted numberValue with respect to the positionValue. bitLShift (5 , 2) returns 20

bitLShift (-5 , 2) returns -20
bitRShift (numberValue , positionValue) or >> (numberValue , positionValue) bitRShift (numberValue , positionValue) or >> (numberValue , positionValue) returns the Bitwise Right Shifted numberValue with respect to the positionValue. bitRShift (5 , 2) returns 1

bitRShift (-5 , 2) returns -2
bitURShift (numberValue , positionValue) or >>> (numberValue , positionValue) bitURShift (numberValue , positionValue) or >>> (numberValue , positionValue) returns the Bitwise Unsigned Right Shifted numberValue with respect to the positionValue. bitURShift (5 , 2) returns 1

bitURShift (-5 , 2) returns 1073741822

Statistical functions:

Function Name Details Example
max (x, y, ...) Returns the largest number of the provided numerical arguments max (10, 20, 30, 40, 50) returns 50
min (x, y, ...) Returns the smallest number of the provided numerical arguments min (10, 20, 30, 40, 50) returns 10
count (x, y, ...) Returns the total numbers (count) of the given arguments count (10, 20, 30, 40, 50) returns 5
sum (x, y, ...) Returns the sum of all provided arguments sum (10, 20, 30, 40, 50) returns 150
avg (x, y, ...) Returns the average value (arithmetic mean) of the given parameters avg (10, 20, 30, 40, 50) returns 30
prod (x, y, ...) Returns the multiplication of all provided arguments prod (10, 20, 30, 40, 50) returns 12000000

Constants:

Name Details Example
Const ('E') Returns Euler's number, the base of natural logarithms Const('E') returns 2.718281828459045
Const ('LN2') Returns the natural logarithm of 2 Const('LN2') returns 0.6931471805599453
Const ('LN10') Returns the natural logarithm of 10 Const('LN10') returns 2.302585092994046
Const ('LOG2E') Returns the base 2 logarithm of e Const('LOG2E') returns 1.4426950408889634
Const ('LOG10E') Returns the base 10 logarithm of e Const('LOG10E') returns 0.4342944819032518
Const ('PI') Returns the ratio of the circumference of a circle to its diameter Const('PI') returns 3.141592653589793
Const ('SQRT1_2') Returns the square root of 1/2 Const('SQRT1_2') returns 0.7071067811865476
Const ('SQRT2') Returns the square root of 1/2 Const('SQRT2') returns 1.4142135623730951

String functions:

Function Name Details Example
string (x) Returns the string converted value of the given parameter string (46) returns '46'
strLen (x) Returns the length of the given string parameters strLen ('Sample') returns 6
strUpper (x) Converts all characters of the provided string to uppercase and returns the converted string strUpper ('Sample') returns 'SAMPLE'
strLower (x) Converts all characters of the provided string to lowercase and returns the converted string strLower ('SaMpLe') returns 'sample'
strTrim (x) Removes whitespace from both sides of the provided string and returns the new string strTrim (' Sample ') returns 'Sample'
strIncludes (largerString, smallerString, pos) Returns true if a larger string contains a specified smaller string otherwise it returns false
It takes 3 parameters:

1st parameter is the larger string (main string) on which the test / search to be done.

2nd parameter is the smaller string for which the test / search to be done.

3rd parameter is the start position: The starting index in the main string from which the test / search begins. This parameter is optional and default value is 0
strIncludes('This is a sample string data which contains the "sample" word','sample') returns true
strStartsWith (largerString, smallerString, pos) Returns true if a larger string starts with a specified smaller string otherwise it returns false.
It takes 3 parameters:

1st parameter is the larger string (main string) on which the test / search to be done.

2nd parameter is the smaller string for which the test / search to be done.

3rd parameter is the start position: The starting index in the main string from which the test / search begins. This parameter is optional and default value is 0
strStartsWith('This is a sample string data which contains the "sample" word','This is a') returns true
strEndsWith (largerString, smallerString, pos) Returns true if a larger string ends with a specified smaller string otherwise it returns false.
It takes 3 parameters:

1st parameter is the larger string (main string) on which the test / search to be done.

2nd parameter is the smaller string for which the test / search to be done.

3rd parameter is The length of the main string upto which point the search / test is to be performed. This parameter is optional and default value is the full length of the larger string.
strEndsWith('This is a sample string data which contains the "sample" word','the "sample" word') returns true
strIndexOf(largerString, smallerString, pos) Returns the position of the first occurrence of the specified smallerStr value in a largerStr string. This function returns -1 if there are no occurrence of the specified smallerStr value in a largerStr string.
It takes 3 parameters:

1st parameter is the larger string (main string) on which the test / search to be done.

2nd parameter is the smaller string for which the test / search to be done.

3rd parameter is the start position: The starting index in the main string from which the test / search begins. This parameter is optional and default value is 0.
strIndexOf('This is a sample string data which contains the "sample" word',"string data") returns 17
strSubStr (mainStr, startPos, endPos) Returns the extracted portion of the mainStr from the startPos up to (but not including) the endPos.
It takes 3 parameters:

1st parameter is the main string from which the substring extraction is performed.

2nd parameter: the startPosition index from which (including the index) the extraction begins.

3rd parameter is the endPosition index parameter up to (not including) which index of the extraction take places. This parameter is optional if omitted then the extraction continues to the end of the string (including last character of the main string).
strSubStr ('This is a sample string data which contains the "sample" word',10,28) returns sample string data
strRepeat (str , count) Returns a new string which contains the specified number of copies of the string, concatenated together. strRepeat ('This is a sample string! ',3) returns 'This is a sample string! This is a sample string! This is a sample string! '
strReplace (mainStr, searchValue, replacement) Searchs for a specifed sub string within the main string, replaces the first occurrence of that substring with the given replacement string, and returns the new (resulting) string. strReplace('This is a sample string data which contains the "sample" word' , 'sample','demo') returns 'This is a demo string data which contains the "sample" word'
strReplaceAll (mainStr, searchValue, replacement) Searchs for a specifed sub string within the main string, replaces all the occurrence of that substring with the given replacement string, and returns the new (resulting) string. strReplaceAll ('This is a sample string data which contains the "sample" word' , 'sample','demo') returns 'This is a demo string data which contains the "demo" word'

Miscellaneous functions:

Function Name Details Example
degToRad (x) degToRad () function takes input in degree form and returns the output in radian form tan(degToRad(45)) returns 1
random () random () returns a pseudo-random number between 0 and 1. random () may returns 0.6030318664027469
fround (x) Returns the nearest 32-bit floating-point representation of a number. fround (0.1) returns 0.10000000149011612
f16round (x) Returns the nearest 16-bit floating-point representation of a number. f16round (0.1) returns 0.0999755859375
clz32 (x) Returns the number of leading zero bits in the 32-bit binary representation of a number. clz32(1) returns 31
imul (x, y) Returns the result of the 32-bit multiplication of the two parameters. imul (2, 4) returns 8
typeof (x) Returns the data type of its parameter typeof ("String Data") returns 'string'
vpVer () Returns the current version of the ViewPoint in a string format vpVer() returns 'ViewPoint v2.1.2'

Variables and assignment operators:

MathPad+ supports assignments of in-line variables using the following operators:

Name Operator Details Example Equivalent To
Equal assignment operator = Assigns a value to a variable myVar = 10 myVar = 10
Addition assignment operator += Adds a value to a previously existing variable and assign the updated value myVar += 1 myVar = myVar + 1
Subtraction assignment operator -= Subtracts a value from a previously existing variable and assign the updated value myVar -= 1 myVar = myVar - 1
Multiplication assignment operator *= Multiplies a value with a previously existing variable and assign the updated value myVar *= 2 myVar = myVar * 2
Division assignment operator /= Divides a previously existing variable with a value and assign the updated value myVar /= 2 myVar = myVar / 2

⬆ Back to the Tables of Contents ⬆


Keywords

MathPad+ supports all keywords available in the ViewPoint v2.1.2 :

Keyword Syntax Purpose Example useage
func func name_of_function(parm1, parm2,..parmN) = ... func keyword can used to defined an in-line function func greet(x) = "Hello " + x; //Greet function defination
rest func name_of_function (rest) = ... rest keyword can be used to collect multiple parameters values in inline functions func max_plus_two(rest) = max(rest) + 2; //Will define a function which can takes any numbers of parameters and returns their maximum number + 2
clr clr variable_Name clr keyword can be used for clearing a variable by its name clr myVar2 ; //Will clear myVar2 variable (if defined early)
clrFn clrFn function_Name clrFn keyword can be used for clearing a user defined function clrFn greet ; //Will clear 'greet()` function (if defined early)
clean clean clean keyword can be used for clearing all user defined variables and all user defined functions. It can be useful for freshly running the .evaluate() or .interpret() method clean ; //Will clear all the user-defined variables and all the user-defined functions.

⬆ Back to the Tables of Contents ⬆


License:

Both ViewPoint and MathPad+ are licensed under the GNU General Public License v3.0 (GPLv3).

While not legally required, I kindly request that if you use, modify, or distribute these projects, please give credit to the original author name, Nirmal Paul (N Paul) (https://github.com/nirmalpaul383) .

I have dedicated significant time and effort to developing these projects, with a strong focus on clean, well-structured, and easy-to-understand code. Your acknowledgment of the original authorship is greatly appreciated.

⬆ Back to the Tables of Contents ⬆


Supports:

If you find these projects as useful, please consider giving those a star on GitHub:

MathPad+ , ViewPoint

For more projects, visit my GitHub profile

Thank you for your support and cooperation.

⬆ Back to the Tables of Contents ⬆


About

MathPad+ is a lightweight mathematical expression playground powered by the ViewPoint evaluator. It enables users to create, test, and evaluate mathematical expressions, variables, and custom functions in an interactive environment.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors