Version 6.0 Readme!
Calcpad is free software for mathematical and engineering calculations. It represents a flexible and modern programmable calculator with Html report generator. It is simple and easy to use, but it also includes many advanced features:
This software is developed using the C# programming language and latest computer technologies. It automatically parses the input, substitutes the variables, calculates the expressions and displays the output. All results are sent to a professional looking Html report for viewing and printing.
This software is suitable for engineers and other professionals that need to perform repetitive calculations and present them in official documentation such as calculation notes. They can automate this task efficiently by creating powerful and reliable Calcpad worksheets. It can also help teachers to prepare calculation examples, papers, manuals, books etc. Students can use it to solve various problems, prepare homeworks, phd theses etc.
Installation is performed by the automated setup program calcpadsetupenx64.exe. Follow the instruction of the setup wizard. The software requires a 64 bit computer with Windows 10 and Microsoft .NET 7.0.
This software is free for both commercial and noncommercial use. It is distributed under the MIT license:
Copyright © 2021 PROEKTSOFT EOOD®
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The source code is available on GitHub:
https://github.com/Proektsoftbg/Calcpad
or in our SourceForge repository:
https://sourceforge.net/p/calyx/code/ci/master/tree/
Any scripts, developed with Calcpad are property of the respective authors. They can be used without additional limitations except those appointed by the authors themselves.
This project uses some additional third party components, software and design. They are redistributed free of charge, under the license conditions, provided by the respective authors.
1. The new and beautiful icons are created using icons8.com.
2. The pdf export was made possible thanks to the wkhtmltopdf.org project.
3. Some symbols are displayed, using the Jost* font family by indestructible type*, under the SIL open font license. Square brackets are slightly modified to suit the application needs.
The software is quick and easy to use. Just follow these simple steps:
The program can be used in two different modes:
In "Input Form" mode, you need to fill the input data and click the button. You can create such a from very easy, directly out of the source code. Just put the "?" symbol wherever you need to enter a value. Then save the problem as "*.cpd" file. You can find additional information about forms further in this manual.
(you can skip this if you find it boring)
How does Calcpad actually work? There is a sophisticated math parser inside, that does most of the job. First, the source code is scanned and the sequence of bytes is converted into a list of tokens, using lexical analysis. Each token is represented by data and type (purpose, role).
Then the parser checks if all tokens are in the correct order. We need to know if the expression is mathematically correct and can be computed. Otherwise, a comprehensible error message should be generated. For example, "3 + a / 5" is a correct expression and "3 a + / 5" is not. For that purpose, the standard mathematical notation is represented by a formal language with contextfree grammar and syntax analysis is used.
Arithmetic expressions are usually written in infix notation. It means that each operator is located between the respective operands (e.g. "5*3 + 2"). The problem is that, unlike humans, computers are difficult to understand such expressions. The main problems are the operator precedence and the use of brackets. For example, the above expression makes "17", while "5*(3 + 2)" makes "25". That is why, the expression is converted into different type of notation, called "postfix" or Reverse Polish Notation (RPN). It is very easy for a computer to read this one. For example, the expression "5*(3 + 2)" is written in RPN as "5 3 2 + *". The main advantage is that the order of operations can be clearly specified without the need of brackets.
There is a simple and powerful algorithm for evaluation of expressions, written in reverse polish notation (RPN). It is used by almost all calculators. However, Calcpad includes additional functionality for processing parameters, functions, macros, conditional execution, loops, etc.
This was a brief and simple explanation. If you are more curious about these topic, you can find additional information in specialized books, papers or websites. Wikipedia is a good place to start with:
https://en.wikipedia.org/wiki/Parsing
https://en.wikipedia.org/wiki/Lexical_analysis
https://en.wikipedia.org/wiki/Contextfree_grammar
https://en.wikipedia.org/wiki/Shuntingyard_algorithm
https://en.wikipedia.org/wiki/Reverse_Polish_notation
Enter the code into the "Code" input window. Spacing and indent are maintained automatically. You can use the computer keyboard or the "Numeric Keypad" below. You can copy text from and to the input window or any external program (e.g. Word). There is a toolbar above the input window with some useful editing commands: Copy, Paste, Undo, Redo and Insert Image.
The source code is logically divided into lines, which are numbered automatically. Each expression should be on a separate line. By exception, it is possible to have several expressions on the same line, but they must be separated by comments. When you finish the line, press "Enter" to start a new line. Syntax highlighting is performed automatically. Different code elements are displayed with different colors depending on their type. For example, comments are colored in green and errors are colored in red. All comments must be enclosed in quotes. They can include both plain text and Html. You can use Html to add pictures, tables and format the report.
The numeric keypad is useful when you work on a tablet or laptop with touch screen. When you press a button, the respective symbols are inserted at the place of the cursor. The keypad is separated into four sections: "Numbers", "Operators", "Functions" and "Other". The "=" key does not calculate the answer as on simple calculators. This is the assignment operator (e.g. "a = 4"). If you need to check the equality of two numbers, use the "≡" operator (for example, "a ≡ b" means: "Is a equal to b?"). The "e", "π" and "g" keys insert the respective builtin constants e ≈ 2.7183, π ≈ 3.1416 and g ≈ 9.8066.
If you don't need the keypad and want to free some space, you can hide it with the button. Click again to show the keypad back.
The "C" button deletes the previous symbol and "AC" deletes a whole line. If you double click this button, you will clear the whole text. If you have done this accidentally, you can use Undo to restore.
Writing and editing text in Calcpad is not much different than any other Windows program. If you have some experience in that, you can skip this and go straight to "Expressions".
You can type at arbitrary position inside the text. The place where symbols are inserted is called "text cursor" (the blinking vertical line ""). You can change the cursor position by clicking with the mouse or using the arrows "← → ↑ ↓" from the keyboard. Arrows will move the cursor one symbol left or right and one line up or down. If you hold the "Ctrl" key and press an arrow, the cursor will move with a whole word. "Home" and "End" keys will send you to the beginning or the end of the current line, respectively. If you hold "Ctrl" beforehand, you will go to the beginning or the end of the entire text.
Most editing commands require you to select some text to which the command will be applied. The selected text is usually displayed with blue background (it may look different depending on your system settings). You can select text with the mouse as follows: Press the left mouse button at the start position of the text to be selected. Hold the button and move the mouse to the end position. Then release the button. Alternatively, you can click at the start, press Shift and then click at the end. You can also use the computer keyboard. Hold Shift and press arrows or "Home", "End", "Page Up", "Page Down".
You can delete a single symbol by pressing the "Delete" ("Del") or "Backspace" ("Bkspc") keys. The difference is that "Delete" removes the symbol after the cursor, and "Backspace"  before the cursor. If you hold "Ctrl" beforehand, you can delete a whole words instead of separate symbols. If you need to delete a larger part of the text, you can select it and press either "Delete" or "Backspace" after that.
If some part of the text is repeated, you can copy it instead of typing it again. That requires two steps: "Copy" and "Paste". At the first step (Copy), the selected text is sent to memory called Clipboard. At the second step (Paste), the text is inserted at the new places. Once copied, you can paste the text at multiple places.
You can copy the selected text to the Clipboard by pressing "Ctrl+C" or by clicking the button.
Before you paste a text from the Clipboard you have to position the cursor at the required place. Then press "Ctrl+V" or the button. You can copy text from Calcpad and paste it to other programs and viceversa. For example, you can take some formulas from Word, calculate them in Calcpad and return the results back to Word.
This command undoes the result from the last editing command and restores the previous state. You can undo up to 10 steps back. Just press "Ctrl+Z" or click the button.
"Redo" performs in the opposite way to "Undo". It restores a command that has been undone. Redo must follow immediately the last Undo. If you enter or edit some text meanwhile, you will lose the ability to redo. Click the button to redo.
You can search for a certain text inside the code and replace it with another, if needed. Select the "Edit/Find" menu, click the button or press "Ctrl+F". The "Find And Replace" dialog will appear.
Enter a word or phrase to search for and click "Find Next". The programs starts from the current position and finds the first occurrence in the selected direction. If the searched phrase is found, it is highlighted and the search is stopped. To find the next occurrence, click "Find Next" again. You can also press "F3" to continue searching even after you close the dialog.
If you need to replace the searched text, click the "Replace" tab and fill in the "Replace with" box. Then click the "Replace" button. The program will replace the current occurrence and will automatically move to the next one. If you want to replace all occurrence in the code, click the respective button instead.
There are several options that affect the search results, as follows:
Syntax highlighting applies different colors to different components of the programming language: functions, variables, operators, etc. It runs automatically in the background, each time you edit and leave the current line. All errors are highlighted in red. The program makes difference between defined and undefined variables and functions. The color palette is predefined and cannot be changed. Currently, Calcpad does not support custom styles and themes.
The indentation of the separate lines in the code is maintained automatically by the program. All lines that are inside conditional and loop blocks are indented accordingly. Additionally, you can add spaces at the beginning of each line. Although spacing is also handled automatically, the leading spaces are not affected.
When you start typing, the program displays a dropdown list with suggestions that match what you have just typed. It contains keywords, units of measurement, built in function and all custom variables and functions that are defined above the current line. The list is dynamically filtered ans sorted while you are typing. The current suggestion in the list is highlighted. If that is what you need, just press "Tab" to insert it at the current position. Click on the list to insert some of the other suggestions. Alternatively, you can press "Down Arrow" to browse the available suggestions and "Enter" to insert the selected one. If the list is above the current line, press "Up Arrow" instead.
The program can find the matching opening and closing brackets. If you position the cursor next or before one of them, both brackets are highlighted. If theere is no corresponding bracket, nothing is highlighted.
You can insert Greek letters by clicking the respective symbol bellow the code editor. Alternatively, type the Latin equivalent from the table below and press "Ctrl+G". If you press it again, you will convert the letter back from Greek to Latin. Since "j"/"J" and "V" remain unused, they are mapped to "ø"/"Ø" and "∡", respectively.
Name  greek  latin  Greek  Latin 

alpha  α  a  Α  A 
beta  β  b  Β  B 
gamma  γ  g  Γ  G 
delta  δ  d  Δ  D 
epsilon  ε  e  Ε  E 
zeta  ζ  z  Ζ  Z 
eta  η  h  Η  H 
theta  θ  q  Θ  Q 
thetaalt  ϑ  v  ∡  V 
iota  ι  i  Ι  I 
kappa  κ  k  Κ  K 
lambda  λ  l  Λ  L 
mu  μ  m  Μ  M 
nu  ν  n  Ν  N 
xi  ξ  x  Ξ  X 
omicron  ο  o  Ο  O 
pi  π  p  Π  P 
rho  ρ  r  Ρ  R 
sigma  σ  s  Σ  S 
tau  τ  t  Τ  T 
upsilon  υ  u  Υ  U 
phi  φ  f  Φ  F 
chi  χ  c  Χ  C 
psi  ψ  y  Ψ  Y 
omega  ω  w  Ω  W 
phidiam  ø  j  Ø  J 
Notepad++ is a popular text/code editor. It is free and open source and can be downloaded from the official website https://notepadplusplus.org. It supports many programming or scripting languages. Its text editing capabilities are much more powerful than Calcpad. It is also very useful for writing Html code. Calcpad syntax can be also used with Notepad++. It is predefined as an XML file that can be inserted in Notepad++. You can do this by selecting the "Language" menu, then click "Define your language" and then, "Import…". Find the Calcpad folder inside your Program Files directory or wherever Calcpad is installed and select the file named CalcpadsyntaxforNotepad++.xml.
The main purpose of Calcpad is to perform calculations. That is why, everything inside the input window is assumed to be mathematical expressions, unless it is enclosed in quotes. Then it is treated as comments. By default, each expression has to be in a separate line, e.g.:
2 + 3
5*(3+1)
15/2
You must not add "=" at the end of each expression. This is the assignment operator. It is used to assign values to variables, e.g. "a = 2". Press the button, to see the results in the output window:
2 + 3 = 5
5∙(3 + 1) = 20
15/2 = 7.5
Alternatively, you can have several expressions in a single line, but they must be separated by comments, e.g.:
'Length 'a = 3m', Width 'b = 2*a', Height 'c = 5m
Each expression can include constants (numbers), variables, operators, functions and brackets. They must be arranged properly in order to represent a valid expression. The commonly accepted mathematical notation and operator precedence is used as it is taught in school. Detailed description of the expression components is provided bellow.
You can calculate separate unrelated expressions as with simple calculator or write a complete program that solves a specific problem. You can define variables and assign values to them. Further, you can use them to define other variables and so on until you reach the final result. You can also add text, Html and images to create detailed and professionallooking calculation report. You can save it to a file and use it multiple times to solve similar problems. Bellow, you can see a sample program for solving a quadratic equation:
Real constants can be positive and negative integer and decimal numbers. They can include digits "0"  "9" and decimal point ".". You can also enter numbers as fractions like "3/4". However, the program will treat them as expressions (division of two numbers). You cannot define numbers in floating point format: "3.4e+6". You have to use an expression like "3.4*10^6" instead.
All constants and variables are internally stored as "doubleprecision floating point" numbers. Their values are ranged from 1.7976931348623157E+308 to 1.7976931348623157E+308. If a result is out of the above interval, the program returns "∞" or "+∞, respectively". Division by zero gives the same result, but "0/0" = "Undefined". The smallest positive number is 4.94065645841247E324. Smaller values are rounded exactly to 0.
If you select "Complex" mode, you can use complex numbers in calculations. Otherwise, only real arithmetic is applied. Each complex number is represented by the ordered couple (a; b), where "a" is real number, and "b = bi" is called "imaginary". It can be written in so called algebraic form: ±a ± bi (e.g. "2 + 3i"). You can also use other forms, such as polar or exponential from, by entering the respective expressions. In Calcpad, the imaginary unit can be entered either as "i" or "1i" in case you have a variable named "i". The imaginary unit is a special number that satisfies the expression i^{ 2} = 1.
A variable is defined by its name and value using expressions like "a = 4". The "=" symbol is the assignment operator. On the left side, only a single variable name is allowed. On the right side, you can have any valid mathematical expression, e.g. "b = a + 4". A variable "lives" from the place of its definition to the end of the program. That is why you cannot use a variable before it is defined. This will raise an error. If you redefine an existing variable with a new value, it will replace the old one and the new value will be used further on.
Variable names can include small or capital Latin letters "a"  "z", "A"  "Z", Greek letters "α"  "ω", "Α"  "Ω" and digits. Names are case sensitive. For example "a" and "A" are different variables. A name must start with a letter or ∡. You can also use "," (comma), "‾" (overline), "_" (underscore), superscripts: " ⁰ "  " ⁹ ", " ⁿ ", " ⁺ ", " ⁻ " and other symbols: " ′ ", " ″ ", " ‴ ", " ⁗ ", " ø ", "Ø", " ° ", "∡". The first occurrence of an underscore in a name starts a subscript. For example, "a_1_1" will be formatted as "a_{1_1}". Variables can store either real or complex numbers (in "Complex" mode).
The following operators are supported by the Calcpad language:
Instead of "≡", "≠", "≤" and "≥", you can use the respective Cstyle equivalent operators, as follows: "==", "!=", "<=" and ">=". They will be automatically replaced by the corresponding Calcpad operators. The shortcut “%%” will be converted to the modulo operator “⦼”. This is necessary because “%” is reserved for the percent units. Since this symbol is not very common, it is rendered as “mod” in the output, e.g. “7 mod 5 = 2”, instead of “7 ⦼ 5 = 2”.
The above operators are listed in the order of their precedence. This is the order they will be evaluated in an expression. When you have different types of operators in a single expression, exponentiation will be evaluated first, then division and multiplication, subtraction and addition and comparison will be the last. When we have a unary minus and exponentiaton, the exponentiaton is evaluated first. For example: "2^2 = (2^2) = 4" All relational operators are of equal precedence. If you need to change the order of evaluation, you can use brackets. For example, "5 + 2∙3" makes "11". If the addition have to be first, write "(5 + 2)∙3". You will get "7∙3 = 21". Operators with equal precedence are evaluated from left to right. This is called operator associativity. For example, "3  2 + 1" makes "(3  2) + 1 = 2" and not "3  (2 + 1) = 0". Another good example is "2∙3 / 2∙3", which makes "9" and not "1".
All operators in Calcpad are leftassociative (calculations are performed from left to right). The only exception is exponentiation, which is rightassociative. It is performed from right to left, which means that x^a^b will be evaluated as x^{ab}. However, many hand calculators and spreadsheet software like Excel use left associativity for exponentiation. In this case x^a^b will be evaluated as x^{a·b}. If you need to have x^{ab}, you will have to add brackets: x^(a^b).
Relational operators can return only two values: "1" for "true" and "0" for "false". You can use them in expressions along with arithmetic operators. For example, you can get the greater of two numbers a and b by the expression: "a*(a ≥ b) + b*(a < b)". But you need to be careful. If you use "≤" instead of "<", for the case of a equal to b, you will get a + b, which may be not exactly what you want. For that special purpose, it is better to use the builtin function max(a; b), logical operators or conditional execution (look further in this manual). Arithmetic operators are of higher precedence than relational, and both are evaluated before logical ones.
Calcpad operates only with numerical data, and does not have special types for boolean data. Similar to relational ones, logical operators also uses "1" for "true" and "0" for "false". Any input value, different than 0 is also assumed to be "true". You can build logical expressions by using logical operators and/or logical functions (see further in this manual). They work as follows:
The results from both operators are presented in the following tables:
And

Or

Xor

All operators support complex numbers except for factorial "!", integer division "\", reminder "%" and comparison: "<", "≤", ">", "≥". The evaluation of a complex expression is a little bit more difficult than real. The rules for the basic complex operations are given bellow:
(a + bi) + (c + di) = (a + c) + (b + d)i
;(a + bi) − (c + di) = (a − c) + (b − d)i
;(a + bi)·(c + di) = (ac − bd) + (bc + ad)i
;(a + bi)/(c + di) = (ac + bd)/(c^{2} + d^{2}) + (bc − ad)/(c^{2} + d^{2})i
;Brackets are used in two cases: to change the order of calculations and to enclose arguments of functions. Only round brackets are allowed: "(" and ")". The software checks if the following rules are satisfied for each expression:
Calcpad uses "smart" bracket insertion while rendering the output. It means that brackets, which are duplicate or do not affect the order of calculations, are omitted from the output. On the other hand, there are places where brackets are added for clarity, although not required in the input. It happens mostly when negative or complex variables are substituted. For example:
Calcpad includes a library with common math functions, ready to use:
sin(x)
 sine;cos(x)
 cosine;tan(x)
 tangent = sin(x)/cos(x)
, for each x ≠ kπ, k=1, 2, 3…;csc(x)
 cosecant = 1/sin(x)
, for each x ≠ kπ, k=1, 2, 3…;sec(x)
 secant = 1/cos(x)
, for each x ≠ π/2 + kπ, k=1, 2, 3…;cot(x)
 cotangent = cos(x)/sin(x)
, for each x ≠ π/2 + kπ, k=1, 2, 3…;sinh(x)
 hyperbolic sine = (e^{x}  e^{x})/2
;cosh(x)
 hyperbolic cosine = (e^{x} + e^{x})/2
;tanh(x)
 hyperbolic tangent = (e^{x}  e^{x})/(e^{x} + e^{x})
;csch(x)
 hyperbolic cosecant = 1/sinh(x)
;sech(x)
 hyperbolic secant = 1/cosh(x)
;coth(x)
 hyperbolic cotangent = (e^{x} + e^{x})/(e^{x}  e^{x}), for x ≠ 0
;asin(x)
 inverted sine, defined for 1 ≤ x ≤ 1;acos(x)
 inverted cosine, defined for 1 ≤ x ≤ 1;atan(x)
 inverted tangent;atan2(x; y)
 the angle whose tangent is the quotient of y and x;acsc(x)
 inverted cosecant = asin(1/x)
;asec(x)
 inverted secant = acos(1/x)
;acot(x)
 inverted cotangent;asinh (x)
 inverted hyperbolic sine = ln(x + √x^{2} + 1)
, defined for ∞ ≤ x ≤ +∞;acosh(x)
 inverted hyperbolic cosine = ln(x + √x + 1·√x  1)
, defined for x ≥ 1;atanh(x)
 inverted hyperbolic tangent = 1/2·ln[(1 + x)/(1  x)]
, for 1 < x < 1;acsch(x)
 inverted hyperbolic cosecant = atanh(1/x)
;asech(x)
 inverted hyperbolic secant = acosh(1/x)
;acoth(x)
 inverted hyperbolic cotangent = 1/2·ln[(x + 1)/(x  1)]
, for x > 1;log(x)
 decimal logarithm (with base 10), for each x > 0;ln(x)
 natural logarithm (with base e ≈ 2.7183), for each x > 0;log_2(x)
 binary logarithm (with base 2), for each x > 0;exp(x)
 exponential function = e ˣ;sqr(x)
or sqrt(x)
 square root (√x ), defined for each x ≥ 0;cbrt(x)
 cubic root ( ^{3}√x );root(x; n)
 nth root ( ^{n}√x );round(x)
 rounds to the nearest integer;floor(x)
 rounds to the smaller integer (towards ∞);ceiling(x)
 rounds to the greater integer (towards +∞);trunc(x)
 rounds to the smaller integer (towards zero);mod(x; y)
 the reminder of an integer division;gcd(x; y)
 the greatest common divisor of two integers;lcm(x; y)
 the least common multiple of two integers;abs(x)
 absolute value (modulus) of a real number  x ;abs(a + bi)
 complex modulus = sqrt(a^{2} + b^{2});re(a + bi)
 returns the real part only, re(a + bi) = a;im(a + bi)
 returns the imaginary part as a real number, im(a + bi) = b;phase(a + bi)
 complex number phase (argument) = atan2(a; b).min(x; y; z…)
 the smallest of multiple values;max(x; y; z…)
 the greatest of of multiple values;sum(x; y; z…)
 sum of multiple values = x + y + z…
;sumsq(x; y; z…)
 sum of squares = x² + y² + z²…
;srss(x; y; z…)
 square root of sum of squares = sqrt(x² + y² + z²…)
;average(x; y; z…)
 average of multiple values = (x + y + z…)/n
;product(x; y; z…)
 product of multiple values = x·y·z…;
mean(x; y; z…)
 geometric mean = nth root(x·y·z…)
;take(n; a; b; c…)
 returns the nth element from the list;line(x; a; b; c…)
 performs linear interpolation among the specified values for parameter x;spline(x; a; b; c…)
 performs Hermite spline interpolation;if(<cond>; <valueiftrue>; <valueiffalse>)
 if the condition cond is satisfied, the function returns the first value, otherwise it returns the second value. The condition is satisfied when it evaluates to any nonzero number;switch(<cond1>; <value1>; <cond2>; <value2>;…; <defaultvalue>)
 returns the value for which the respective condition is satisfied. Conditions are checked from left to right. If none is satisfied, it returns the default value in the end;not(x)
 logical "not";and(x; y; z…)
 logical "and";or(x; y; z…)
 logical "or";xor(x; y; z…)
 logical "xor";sign(x)
 sign of a number = 1, if x < 0; 1, if x > 0, 0 if x = 0;random(x)
 a random number between 0 and x.Arguments must be enclosed in round brackets. They can be constants, variables or any valid expression. Multiple arguments must be separated by semicolons ";". When arguments are out of range, the function returns "Undefined". Exceptions from this rule are "cot(0)" and "coth(0)", which return "+∞".
Arguments of trigonometric functions can be in degrees, radians or grades. The units for angles can be specified in three different ways:
1. By the radio buttons above the output window (🔘D, 🔘R, 🔘G).
2. By compiler switches inside the code. You have to insert a separate line containing: #deg for degrees, #rad for radians or #gra for grades. This will affect all expressions after the current line to the end or until an alternative directive is found.
3. By attaching native units to the value itself: deg, °, ′, ″, rad, grad, rev (see the “Units” section, further in this manual).
Native units are of highest priority, followed by compiler switches in source code. Both override radio buttons settings, which are of lowest priority.
All functions are also defined in the complex domain, except for mod(x; y), gcd(x; y), lcm(x; y), min(x; y) and max(x; y).
Logical functions accept numerical values and return “0” for “false” and “1” for “true”. The results for two arguments (one for “not”) are presented in the following tables:




Any numerical value, different from 0, is treated as 1 (true). Multiple arguments are evaluated in couples, from left to right, starting from the first two. Then, the obtained result and the next value are evaluated in turn.
Rounding of midpoint values with round() evaluates to the neares integer away from zero. The floor() function rounds to the smaller value (towards ∞). The ceiling() function rounds in the opposite direction to the larger value (towards +∞). Unlike floor(), trunc() rounds towards zero, which is equivalent to simply truncating the fractional part. Some examples for rounding negative and positive numbers are provided in the table bellow:
Positive

Negative

Rounding of complex numbers affects both real and imaginary parts.
You can define your own functions, and use them further in the calculations. Custom functions can have unlimited number of parameters. They are specified after the function name, enclosed in brackets "(" … ")" and separated by semicolons ";". Each function is defined, using the following format: "f ( x; y; z; … ) = expression", where "f" is the function name and "x", "y" and "z" are function parameters. On the right side you can have any valid expression including constants, operators, variables and even other functions, e.g.:
f(x) = x^2 + 2*x*sin(x)
g(x; y) = f(x)/(y  4)
Once defined, you can use a function in any expression by inserting a function call. Just write the function name and then specify the arguments in brackets, e. g. b = g(a + 2; 3) + 3. Function names must conform to the same rules as variable names. Arguments can be any valid expressions. You have to provide as many arguments as the number of function parameters. The life cycle of a function is from the place of definition to the end of the code. If you define a new function with the same name, the old one will be replaced. You cannot redefine a library function. For example, sin(x) = x^2 will return an error.
It is not necessary to predefine the variables that are used for parameters. However, if other variables are used inside the function body, they must be defined before the first call to the function. Parameters work as local level variables inside the function body. If a variable with the same name exists outside the function, a call to that function will not rewrite the value of the global variable. For example:
User defined functions support both real and complex numbers.
Besides functions, Calcpad provides special commands for advanced operations. They accept functions and expressions as arguments and perform plotting, iterative solutions and numerical methods. Their names start with "$" to be distinguished from normal functions. Their parameters must be enclosed in curly brackets: "{" and "}". Such is the plotting command $Plot. It can plot a function of one variable in the specified interval. It has the following format:
$Plot{y(x) @ x = a : b}
, where:
For example, if you enter: $Plot{x^2  5*x + 3 @ x = 1:6}
, you will get the following result:
The above command plots only one function of one variable at a time. There are also other formats that you can use:
$Plot{x(t)y(t) @ t = a : b}
 parametric plot: both coordinates are functions of a parameter;
$Plot{y_{1}(x) & y_{2}(x) & … @ x = a : b}
 multiple: plots several functions on a single graph;
$Plot{x_{1}(t)y_{1}(t) & x_{2}(t)y_{2}(t) & … @ t = a : b}
 multiple parametric;
$Map{f(x; y) @ x = a : b & y = c : d}
 draws a 2D color map of a 3D surface, defined by f(x; y).
The $Plot{…} function must be the first thing in a line. You can have only spaces and tabs before, not even comments. Otherwise, the program will return an error. Any text after the closing bracket "}" will be ignored. Plotting supports only real numbers. You can use it in complex mode, only if x and y are real and the function returns real result along the plotting interval.
You can specify the size of the plot area by defining two variables: PlotWidth and PlotHeight in pixels. The default values are PlotWidth = 400 and PlotHeight = 250.
The $Map{…} function can work with different color palettes. Select the preferred one from the "Palette" combo box on the bottom of the program window. If you select the "Smooth" checkbox, the scale will be displayed as a smooth gradient. Otherwise, the program will draw color strips. You can also add 3D effects to the graph by selecting the "Shadows" checkbox. You can also specify light direction by the respective combo.
Examples of different plotting methods are provided bellow:
Parametric Equation: r(θ) = cos(5/2*θ) $Plot{r(θ)*cos(θ)r(θ)*sin(θ) @ θ = 0:6*π}

Multiple Equation: y_{1}(θ) = cos(θ)  sin(θ) y_{2}(θ) = cos(θ) + sin(θ) $Plot{cos(θ) & y_{1}(θ) & y_{2}(θ) @ θ = 0:π}

Result: "rose" curve 
Result: leaf by three trigonometric functions 
Multiple parametric Equation: x(θ) = sqr(θ)*cos(θ) y(θ) = sqr(θ)*sin(θ) $Plot{x(θ)y(θ) & x(θ)y(θ) @ θ = 0:3*π}

Color map Equation: f(x; y) = cos(x/3) + sin(y)  sin(x)*cos(y/4) $Map{f(x; y) @ x = 15 : 15 & y = 15 : 15}

Result: double Fermat spiral 
Result: 2D waves 
Calcpad has a built in "Solver" module, which can solve more difficult problems using numerical methods. It can work only with real numbers but not complex. It includes the following functions:
$Root{f(x) = const @ x = a : b}
$Root{f(x) @ x = a : b}
It finds a single root for an equation of type "f(x) = const" within the interval [a, b]. If "const" is zero, you can omit "= const". The program uses hybrid bracketing method, which is a combination of Bisecton and AndersonBjork's method. It subsequently narrows the interval around the root, until it gets smaller than the specified precision. It is required that the function "f(x)  const" has opposite signs at the ends of the interval. According to the Boltzano's theorem, if the function is continuous within the interval, at least one root exist. The bracketing algorithm will find an approximation after a finite number of iterations.
With this method, you can find only roots where the function crosses the line at "y = const". When "f(x)  const" is entirely positive or negative and only "touches" the line from one side, you cannot find the root by any bracketing method.
If no roots exist inside the initial interval, the program returns an error. If there are several roots, it will find only one of them. In such case, it is better to plot the function first. Then, you can see the approximate location of roots and divide the interval into several parts  one for each root. Finally, you can call the function several times to find all the roots. In some cases, it is possible to develop an automated procedure for interval splitting.
$Inf{f(x) @ x = a : b}
It finds the smallest value for a function f(x) within the specified interval [a, b]. The golden section search method is applied for that purpose. If the function contains a local minimum within the interval, it will be returned as a result. Otherwise, the function will return the smaller of the values at the ends of the interval: f(a) or f(b). If there are several local minimums, the program will return only one of them, but not necessarily the smallest one. In such cases, it is better to split the interval. The value of x where the minimum is found is stored into a variable x_{inf}. If you use different name for the argument, instead of x, it will add "_inf" at the end of that name.
$Sup{f(x) @ x = a : b}
It works like the minimum finding function, but it finds the greatest value instead. The value of x where the maximum is located is stored in a variable named x_{sup}.
$Area{f(x) @ x = a : b}
It calculates the value of the definite integral of a function f(x) within the specified interval [a, b]. Adaptive GaussLobbato quadrature with Kronrod extension is applied for that purpose (Gander & Gautschi, 2000).
$Integral{f(x) @ x = a : b}
This command is similar to the above, but it uses the TanhSinh quadrature (Takahasi & Mori, 1974) which has been additionally improved by Michashki & Mosig (2016) and Van Engelen (2022). Further improvements has been made in Calcpad, by precomputing and caching the abscissas and weights. This algorithm significantly outperforms $Area
for continuous and smooth functions. However, if the function does not satisfy these requirements, you should not use the $Integral
method. Then, you have two options:
$Area
method instead.$Slope{f(x) @ x = a}
It finds the value of the first derivative of a function f(x) at x = a. The derivative represents the slope of the tangent to the function at the respective point. The Richardson extrapolation method is used on a two point stencil.
Unlike the plotting command, you can include numerical methods in expressions. They return values which can be used for further calculations. For example, you can store the result into a variable:
y_{min} = $Inf{f(x) @ x = a : b}
Similarly to standard functions, "x" is local for all numerical methods and its global value is not modified after the method is called.
There are some other commands that allows you to calculate the result iteratively. Unlike numerical methods, they can work with complex numbers.
$Sum{f(k) @ k = a : b}
It sums the values of f(k) for all integer k between a and b. The values of k can only grow, so it should be satisfied that a < b. Instead of f(k) you can put any valid expression that includes k. Otherwise, it will simply sum the same value k times. For example, you can use series to calculate constants. Such is the Leibniz formula for calculation of π:
4*$Sum{(1)^{k+1}/(2*k  1) @ k = 1:1000}= 3.1406
You can also use series to define functions. Of course, they cannot be infinite. The number of iterations should be sufficient to provide the required precision of the result. The following pattern can be applied to approximate a function with Fourier series:
f(x) = a_{0}/2 + $Sum{a(k)*cos(k*x*π/l) @ k = 1:n} + $Sum{b(k)*sin(k*x*π/l) @ k = 1:n}
As an example, we can take a straight line within the interval (0; 2*l), withs equation: f(x) = x/(2*l). The integration constants are a(k) = 0 and b(k) = 1/(k*π). If we plot the Fourier approximation for n = 5, we will get the following result:
$Product{f(k) @ k = a : b}
It works like "Sum", but it multiplies the terms instead of adding them. For example, you can define your own factorial function:
F(n) = $Product {k @ k = 1 : n}
$Product{(i + n  k)/i @ i = 1:k}
Also, the later will not overflow together with the factorials for greater values of n.
$Repeat{f(k) @ k = a : b}
This is a general inline iterative procedure that repeatedly calculates f(k). It can be used for sums and products instead of the respective procedures, but it is not so efficient. However, there are expressions that can be calculated only by the "Repeat" command. Normally, such expressions will make sense if you assign the result to a variable to be used in the next iteration. So, the following pattern is more likely to be applied in practice:
$Repeat{x = f(x; k) @ k = a : b}
For example, you can use this command to define the Mandelbrot set in a single line:
f(z; c) = $Repeat{z = z^2 + c @ i = 1:100}
You should not forget to switch to "Complex" mode. Then you can plot the result:
$Map{abs(f(0; x + 1i*y)) @ x = 1.5:0.5 & y = 1:1}
Calcpad provides a comprehensive support for physical units of measurement. The current version, supports metric (SI and compatible), US and Imperial units. There are seven basic units that correspond to the seven physical dimensions:
All other units are derivative. They are obtained by the respective laws of physics. For example, force = mass·acceleration, so Newton is obtained by N = kg·m/s^{2}. Multiples of units are also supported by adding the respective prefixes to units names. For example, kN = 10^{3}N, MN = 10^{6}N and so on.
Additionally, there are some "dimensionless" units like percents, permilles and angles (degrees, radians, etc.) that do not include any physical dimensions. However, angles use a special (eighth) nonphysical dimension, in order not to cancel and convert to percents, when mixed (which would be weird).
You can attach units to numbers by typing the unit name after the value, e.g. 15kg. Then, you can use them in expressions, just like any other values. Unit cancellation and conversion is performed automatically during calculations. For example, the following expression will be evaluated as:
1.23m + 35cm + 12mm = 1.59m
(and not: 1.23 + 35 + 12 = 48.23)
The result is usually obtained into the first unit in the expression. If you want to use particular units, write a vertical bar "" followed by the target units at the end:
1.23m + 35cm + 12mmcm
The above expression will evaluate to 159.2cm. If you simply want to convert units, just write the source and the target units, separated by a vertical bar, like: mmcm or 10m/skm/h.
Unit consistency is also verified automatically. For example, you cannot add m and s(e.g. 6m + 2s), but you can multiply and divide them 6m/2s = 3m/s.
Arguments for trigonometric, hyperbolic, logarithmic and exponential functions, must be unitless by definition. However, you can use units an any custom defined functions, if it makes any sense. You can also attach units to variables. If you specify the target units in a variable definition, they will be stored permanently inside the variable. Then, the selected units will be used further in the calculations with the respective value. In the next example, speed is calculated in m/s, but it is converted and stored as km/h:
Code  Output 

'Distance 's_1 = 50m 'Time 't_1 = 2s 'Speed 'V = s_1/t_1km/h 'What distance you will travel for't_2 = 5s'? s _2 = V*t_2m

Distance  s_{1} = 50m Time  t_{1} = 2s Speed  V = s_{1}/t_{1} = 50m/2s = 90km/h What distance you will travel for t_{2} = 5s ? s_{2} = V·t_{2} = 90km/h·5s = 125m 
Calcpad includes a large collection of predefined units as follows:
Dimensionless:
Metric units (SI and compatible):
Nonmetric units (Imperial/US):
Angle units are accepted by trigonometric functions and they override all other settings. Inverse trigonometric functions return unitless values by default. If you want them to return the result in the current units, you have to define a variable: ReturnAngleUnits = 1.
Literals that are written immediately after numbers are recognized as units by the parser, e.g. "2m". Standalone literals can be either units or variables, e.g. "N*m". The rules for parsing are as follows: If a literal has not been defined as a variable, it is parsed as a unit. Otherwise, it is parsed as a variable, even if a unit with the same name exists. If you put a dot before the literal, you will force ir to be parsed as a unit, even if a variable with the same name exists, e.g. ".N*.m".
You can define your own "custom" units and use them like any others in your code. Defining a unit is similar to defining a variable, but the name must be prefixed with a dot ".":
.Name = expression
The name can include som currency symbols like: €, £, ₤, ¥, ¢, ₽, ₹, ₩, ₪. If you need to create a unit, that derive from others, you can write an expression with numbers and units on the right side. You can also define dimensionless units, like currency (USD, EUR, €, ₤) or information (bit, byte, KiB, etc), by specifying "= 1" for the first unit and setting the others as multiples. For example:
.bit = 1
.byte = 8*bit
.KiB = 1024*byte
...
Custom dimensionless units exist in a special (ninth) nonphysical dimension. That is how they do not cancel or convert to other dimensionless units, like percents or angles, when mixed. However, if you have two types of dimensionless units in a single file, they will exist in the same dimension, so you will have to avoid mixing them.
All calculations are automatically collected into professionally formatted calculation report. You can print it or open it with MS Word for editing. Besides math expressions, you can add headings, comments, tables and images.
A heading is a text, enclosed in double quotes ("). It is bold and larger than the main text.
Comments are enclosed in single quotes ('). You can skip the closing quote, if it is the last symbol in the line. Headings and comments can contain any symbols without restrictions. Everything outside them is assumed to be math expressions. However, if you put any formulas inside comments, they will not be calculated or formatted. Since the final output is rendered to an Html document, you can use Html and CSS in comments to provide your calculation report with additional formatting .
Alternatively to native units, you can enter all values to be unitless and then put the units in the comments. In this case, you will have to include all unit conversion factors in the equations. Also, there is an option to generate a selection box for length units  m, cm and mm. You only need to insert %u in comments wherever you want the units to appear. When the program generates the input form (see further) it checks whether %u exists somewhere in the code. If so, it automatically adds a unit selection combo box, at the topright corner. When you change the units from the combo, they will be filled in all occurrences of %u in the code. You can try it bellow:
Code  Output 

"Units in comments 'Length 'l = ?'%u 'Area 'l = ? %u<sup>2</sup> 'Volume 'l = ?'%u<sup>3</sup> 'Scale factor 'Units 
Units in comments Length  l = m Area  l = m^{2} Volume  V = m^{3} Scale factor  Units 
When you run the calculations, the "Units" combo will disappear from the output. Only the units will remain as filled. The program will also create a variable Units, which will contain the conversion factor from the selected units to meters. Its value is 1, 100 and 1000 for m, mm and cm, respectively. You can use it for units conversion inside the calculations. For example, you can create a conditional block for displaying the selected units in the report:
#if Units ≡ 1
'The selected units are meters
#else if Units ≡ 100
'The selected units are centimeters
#else if Units ≡ 1000
'The selected units are millimeters
#end if
Calcpad can be used as a development platform for professional engineering programs. If you are not going to do that, you can skip this chapter.
Html (Hyper Text Markup Language) is a markup language which is created for formatting web pages. You can change the font type, size and weight, the color of the text and to insert tables, images, etc. This is performed by adding special elements called "tags". Each tag is enclosed in angular brackets: "<tag>". Some tags are used in pairs  opening "<tag>" and closing "</tag>". The contents is going in between. For example, if you want to make some text bold, you can use the following tags: <b>Bold text</b>. Even if you are not a professional programmer, you can easily learn some basic Html, to use with Calcpad:
Html code  Output 

<b>Bold</b>

Bold 
<i>Italic</i>

Italic 
<u>Underline</u>

Underline 
<span style="color:red;">Red</span>

Red 
x<sup>superscript</sup>

x^{superscript} 
x<sub>subscript</sub>

x_{subscript} 
<span style="font:16pt TimesNewRoman;">

Times New Roman, 16pt 
You can put Html tags only in comments, but you can also make them to affect expressions. For example:
'<span style="color:red;"> as simple as ' 2 + 2 '</span>'
will give the following output:
as simple as 2 + 2 = 4
We simply enclosed the expression with two comments. The first comment contains the opening tag '<span style="color:red;">
' and the second  the closing tag '</span>'
. Everything between the two tags is colored in red. Make sure not to forget the quotes. Otherwise, the program will try to parse the Html code as math expression and will return an error. The following code: style="color:red" is called "inline CSS" (Cascading Style Sheets). It is used to format the look of Html documents. You can learn more about Html and CSS from the following links:
http://www.w3schools.com/html/
You can also use some of the many free WYSIWYG Html editors available on the Internet.
If you have some long and detailed calculations, you can fold them optionally in the output. They will be hidden by default, except for the first line, which can be used for the section heading. All you need to do is to enclose the folding section into a Html "div" element with class "fold", as follows:
'<div class="fold">
'<b>Heading</b> (click to unfold)
'Content to be folded
'</div>
The result will look as follows:
Heading (click to unfold)
Content to be folded
Before inserting an image into Calcpad document, you need to have it already as a file. You can create it by some image editing software and save it to a *.png, *.gif or *.jpg file. You can use some freeware programs like Paint, Gimp, InkScape, DraftSight or others. Then you can insert it using Html. All you need to do is to put the following text at the required place, inside a comment:
'<img style="float:right" src="c:/Users/Me/Pictures/Picture1.png" alt="Picture1.png">
Of course, instead of "c:/Users/Me/Pictures/Picture1.png" you must specify the actual path to your image. The file can be local, network or on the Internet. Always use forward slashes "/", even if the file is local. If the image is located in the same folder as the current worksheet, you can specify a relative path as follows: "./Picture1.png". The text style="float:right;" aligns the image to the right allowing the text to float at left. Otherwise, the image will become part of the text flow and will make it split. Alternatively to style="float:right", you can use class="side" for the same purpose.
You can also insert an image using the button from the toolbar. You will be prompted to select a file. When you click "Open", the required record will be inserted at the beginning of the code. When you run the calculations, the picture will appear in the output window.
If you have long and complicated problem or you want to share your solution with others, it is a good idea to create an input form. It is very easy to do that with Calcpad. Just replace the values that need to be entered with question marks "?", e.g. "a = ?". Please note that after that, you will not be able to calculate the results directly by clicking . You must compile it first to an input form. For that purpose, click the button or press F4 from the keyboard.
The code will hide and the form will be loaded into the "Input" box at the full width of the main window. All texts and formulas will be rendered in Html format, protected from modification. Input boxes will be generated at every occurrence of the "?" symbol except those in comments. The readytouse input form will look as follows:
Now you have to fill the input boxes and click to calculate the results. They are displayed in the "Output" box.
In order to return to input mode, click again to switch the button off. Input data will remain unchanged since the last input. If you need to modify the source code, you have to unlock it by clicking the button. The "Code" box will show again at the left side of the main window. Input data will be attached to the question marks. If you hover the mouse over one of them, you will see the respective value. Click on the question mark to change it. When you finish editing the code, you can compile it back to input form. The input values will be filled in the respective fields. Finally, you can save the document as a "*.cpd" file. When you open such file, it will be displayed directly into input form mode. This format is more convenient to use than a simple text file due to the following advantages:
If you save the document as a "*.cpdz" file, you will make the source code completely inaccessible. It will not be possible to unlock it inside Calcpad anymore. Also, no one could edit the file in external text editor, because it is encoded. That is how you can protect your source code from unauthorized coping, viewing and modification.
You can put question marks "?" not only in variable definitions, but at any place in the code e.g.:
2 + ?
2 +
Then, you can enter a value and calculate the result. This approach is not recommended for complicated problems, because the program logic gets unclear and difficult to understand.
Besides simple input boxes, you can use some advanced UI elements like "select" (combo box), "radio" buttons and "checkboxes" in your worksheets. Since all the output from Calcpad is rendered as an Html document, you can use Html and CSS for that purpose. However, Calcpad accepts input only from text boxes. That is why, it is required to map every other UI element to some text box. This is performed by enclosing the text box into an outer html element (paragraph or div) with a certain id. The same id must be assigned as a name or datatarget attribute of the source UI element. Then, the content of the source element's value attribute will be automatically filled in the target text box. You can use the following sample code:
Selection box:
Code:
'Select an option: <select name="target1"> '<option value="11;12">x1; y1</option> '<option value="21;22">x2; y2</option> '<option value="31;32">x3; y3</option> '</select> '... '<p id="target1"> Values:'x = ? {21}','y = ? {22}'</p>
Output:
Select an option:
...
Values: x = , y =
Radio buttons:
Code:
'<p>Select: '<input name="target2" type="radio" id="opt1" value="1"/> '<label for="opt1">option 1</label> '<input name="target2" type="radio" id="opt2" value="2"/> '<label for="opt2">option 2</label> '... '<p id="target2">Value 'opt = ? {2}'</p>
Output:
Select:
...
opt =
CheckBox:
Code:
'<p><input name="target3" type="checkbox" id="chk1" value="3"/> '<label for="chk1">Checkbox 1</label></p> '... '<p id="target3">Value 'chk = ? {3}'</p>
Output:
...
chk =
As you can see from the first example, one "value" attribute can contain multiple values, separated by semicolons ";". In this case, you have to provide the respective number of text boxes in the target paragraph. You can copy the above code, add as many options as you like and write your own labels and values. You can also change names and ids, but make sure that all source names match exactly the target ids and no duplicate ids exist.
You can easily specify which parts of the code should be visible or hidden in the output. Unlike conditional execution, the hidden code is always calculated. It is just not displayed. The following keywords can be used for that purpose:
Each of the above keywords affects the content after the current line and overrides the previous one. You can use them to hide long and repetitive calculations that should not be visible. You can use the #Pre command to add some directions about filling the input data and #Post to hide the calculation algorithm during data input.
You can also modify the display of the equations as follows:
Each of the above keywords overrides the other. You can use #Val to create a table with values, but without the formulas, like in Excel.
Sometimes the solution have to continue in different ways, depending on some intermediate values. Such feature is included in Calcpad, similarly to other programming languages. It is called "conditional execution block" and has the following general form:
#If condition1
#Else If condition2
#Else If condition3
#Else
#end if
Shorter forms are also possible:
#If condition
#Else
#end if
or:
#If condition
#end if
Condition blocks affect not only the calculation path but also the report content like text and images. The "#" symbol must be the first one in the line. At the place of "condition" you can put any valid expression. Normally, a comparison is used like "#If a < 0", but it is not obligatory. If it evaluates to any nonzero number, the condition is assumed to be satisfied. Otherwise, it is not satisfied. Any result which absolute value is ≤ 0.00000001 is assumed to be zero.
Let us look again at the quadratic equation example that we used earlier. If we enter "c = 5", the discriminant will be negative and the result will be NaN. This is not a very intelligent way to finish a program. What we need to do is to check if "D < 0" and if so, to provide a comprehensible message. Otherwise, we have to calculate the roots. We can do this, using conditional execution, as follows:
You can have simple iterations inside a Calcpad program. For that purpose, you have to define a "repeatloop" block:
The symbol n stands for the number of repetitions. Instead of n, you can put a number, variable or any valid expression. If the result of the expression is not integer, it is rounded to the nearest one. You can exit the repeatloop cycle prematurely by putting #Break inside the block. It will make sense only if you combine it a conditional block. Otherwise, it will always break at the same line, without performing any loops. A typical "repeatbreakloop" will look like this:
#Repeat
#If
condition#Break
#End if
#Loop
You can use #Continue
instead of #Break
. The program will skip the remaining lines, return to the top of the conditional block and continue with the next iteration. You can omit the number of repetitions n only if you are sure that the condition will be satisfied and the loop will brake sooner or later. Anyway, to avoid infinite loop, the number of iterations is limited to 100 000 if nothing else is specified.
Besides repetitive calculations, you can use loops to generate repetitive report content (like table rows). If you want to hide the iteration details, you can use output control directives (see the previous section). For example, you can enclose the "repeatloop" block with #Hide and #Show statements.
You can make a Calcpad worksheet to execute interactively (stepbystep) by defining "breakpoints" at certain lines. It will allow the user to review the intermediate results and enter some additional input data if needed. There are two special keywords, you can use for that purpose:
#Pause
 calculates down to the current line, displays the results and waits for the user to resume;#Input
 renders an input form to the current line and waits the user to enter data and resume.When the execution is paused, the program renders a message at the bottom of the report:
Paused! Press F5 to continue or Esc to cancel.
You can resume the execution by pressing F5, clicking the link or the button again. You can have several breakpoints in a single worksheet. WHen you use the #Input
keyword, the previous section is calculated before the current input form is displayed. In this way, the stages of calculation overlap as shown in the following example:
Additionally, the user can press "Pause/Break" or "Ctrl + Alt + P" any time from the keyboard to pause the execution. The execution will pause at the current line as if #Pause
is detected.
Calcpad allows you to include contents from external files in your worksheet. If you have pieces of code that is repeated in different worksheets, you can organize it in modules and reuse it multiple times. Also, if you have a longer worksheet, you can split it into modules that will be easier to maintain. Then, you can include them into the main file by using the following statement:
#include filename
The "filename" must contain the full path to a local file. If the file is the same folder as the current one, you can specify only the filename.
By default, Calcpad will include the whole contents of the external module. However, you can prevent some parts from inclusion, by making them local. To start a "local" section in a module, add a new line, containing the #local keyword. To end a "local" section (or start a "global" one), add a new line with the #global keyword. Calcpad supports multiple levels of inclusions. That means that the included file, in its turn, can reference other files and so on.
Macros and string variables are convenient ways to organize your code inside a single file and prevent repetitions. They can be inline or multiline. Unlike string variables, macros can have parameters. You can define them, by using the following statements:
Inline string variable:
#def
variable_name$ = content
Multiline string variable:
#def variable_name$
content line 1
content line 2
...
#end def
Inline string macro:
#def
macro_name$(param1$; param2$;...) = content
Multiline string macro:
#def macro_name$(param1$; param2$;...)
content line 1
content line 2
...
#end def
Names of string variables, macros, and their parameters can contain small and capital latin letters and underscore "_". They must b with the "$" symbol. The contents can be virtually any string. It is not necessary to be a valid Calcpad expression, since it is not processed by the parser at this stage. However, other macro/string variable definitions are not allowed inside. You can insert only references to previously defined ones. Also, input fields "?" are not supported in macros yet. This feature will be developed in the next versions. You can use #include inside macros, but only if the included file does not contain other macros.
After a string variable is defined, you can use it anywhere in the code, by writing its name (with the ending "$"). The same is for macros, but you also need to specify values for parameters. Macros and string variables are preprocessed and rewritten before the actual parsing is performed. As a result, intermediate (unwrapped) code is generated. You can review it by checking the "Unwrapped code" checkbox bellow the "Output" window.
If any errors occur during macro preprocessing, the unwrapped code is displayed, together with the errors. Line numbers in error descriptions refer to your initial code. If preprocessing is completed successfully, the unwrapped code is parsed and calculated as normal. If errors are detected at this stage, they are displayed in the output. Line numbers in error descriptions refer to the unwrapped code. You can go to the respective line, by clicking the link on the line number.
You can run the solution by pressing F5 or clicking the button. The results will appear in the "Output" box. You cannot edit the output content, but you can select, copy and print it. For that purpose, you can use the toolbar over the "Output" box on the right. You can also use additional commands from the context menu, that is displayed If you rightclick inside the "Output" box, you will see a popup menu with additional commands. Detailed description is provided further in this manual.
Since version 6.5.3, you can use the "☑ AutoRun" mode. While it is checked, the results will refresh each time you change the code and move to another line. If you need to synchronize the results manually, you can press "Ctrl + Enter". Additionally, the output window will scroll to match the current position in the source code. You can do the same by double clicking into the input window.
Calcpad can substitute the values of variables in all formulas in the output, just before the answer:
x_{1} = b – √D2·a = 3 – √892·4 = 1.55
For that purpose, you need to check the "Substitution" checkbox at the bottom of the program window. That makes the results easy to review and check. This is important when calculations have to be checked by supervisors, teachers etc. This is also an advantage over the spreadsheet software where the actual formulas are hidden in the cells.
If you do not need the substitution, you can uncheck this option. Then the answers will follow directly the calculation formulas:
x_{1} = b – √D2·a = 1.55
After that, if you position the mouse over any variable, you will see a tooltip with the respective value.
Rounding is specified by the number of digits n after the decimal point. It is entered into the "Rounding" input box at the bottom of the program window. The value of n can be between "0" and "15". If you enter "0", all results will be rounded to integers. If the value is less than "0" or greater than "15", the respective limit will be taken.
However, rounding can come across some potential problems. If the result is less than 10^{n} and you round it to n digits after the decimal point, the result will contain only zeros. That is why, Calcpad incorporates some advanced rules: If the output contains less than n significant digits after rounding, it is expanded up to n significant digits. Even then, if the number is too small, it will be difficult to count the zeros after the decimal point. So, in such cases, the output is converted to floating point format with n digits. When the total number of digits becomes greater than 2n, the factional part is being truncated. In this way, the output becomes easier to read, still providing at least 2n significant digits. You can see several examples bellow, obtained for (n = 3).
Rounding affects only the way in which numbers are displayed in the output. Internally, all numbers are stored with the maximum possible precision. That is why, if you print the output and try to repeat the calculations with the numbers from the report, you probably will get some little differences. This is because you use the rounded values instead of the actual ones.
You can override the global rounding inside a worksheet by using the #Round
n keyword, where n is the number of digits after the decimal point (from "0" to "15").
Calcpad does not simply calculate formulas. It also builds a professional looking report out of your source code. It uses Html to format the output. It is widely recognized and allows you to publish your calculations in the web. You can select between two different styles for equation formatting: "professional" and "inline". The professional style uses division bar, large and small brackets, radical, etc. Numerator and denominator are displayed one above the other. The inline style uses slash for displaying division and all symbols are arranged into a single line. The following formatting rules are applied:
Several examples of formatting in different cases are provided in the table bellow:
Text  Html 

x + 3 
x + 3 
x3 
x – 3 
3*x 
3∙x 
(x + 1)/3 
(x + 1)/3 or x + 13 
x+3 * y 
x + 3∙y 
sqr(x+3) 
√x + 3 
x_1^3 
x_{1}^{3} 
sin(x) 
sin(x) 
Html formatting makes the report easier to read and check than the respective plain text. You can also insert additional Html code inside the comments that will affect the final appearance. In this way, you can use Calcpad code to build professional Web applications. You will also need the cloud version of Calcpad for that purpose.
You can scale up and down the text size in the output window. Hold the "Ctrl" button and rotate the mouse wheel. The forward rotation will scale up and the backward will scale down.
You can save the output to an Html file . Unlike the input file, it cannot be modified with Calcpad. On the other side, everyone will be able to view and print your calculations without Calcpad. Html files can be opened on any computer using web browser or office program like Word.
You can save the file by clicking the button over the output box. Then select a file name and click "Save".
You can print the output by clicking the button. Normally, printing is performed after calculations. When you click the button, the print preview dialog will be displayed:
It allows you to set the printing layout and margins. Click the button to change the paper size and type. Finally, press the button. A printer selection dialog will appear. Choose the preferred printer and click "Print".
Printing in Calcpad uses the builtin functionality of Windows and Edge. The above screenshots may look differently on your computer, depending on the versions you use. Alternatively, you can right click in the output window and select "Print preview…" from the context menu. If you select "Print", you will skip the preview and proceed directly to printing.
You can copy the entire output at once by clicking the button over the output window. Then, you can paste it in any other program. If the target program supports Html, like Word, the formatting will be preserved. Otherwise, the content will be pasted as plain text.
You can open the results directly with MS Word by clicking . It must be installed on the computer, but it is not necessary to be preliminary opened. This approach is easier than copypaste and provides some additional benefits. If the output is obtained with the professional equation formatting option, Calcpad will use the "*.docx" file format for the export. This is the native format for the latest versions of MS Word and will open automatically. If you have Open Office or Libre office, the respective program will be used instead. If you do not have any text editor currently installed, the file will be saved to the disk, but not opened. You can go to the respective folder later and open it manually. Formulas are exported as MathType objects and can be modified inside Word. However, it is possible to loose part of the Html formatting. Images, tables and most common tags are supported. If you have selected inline equation formatting, Calcpad will use an Html file for the export. It will preserve most of the formatting, but formulas will be part of the document text.
A good alternative to Html is to save the report as pdf file. It is another way to make a hard copy of your calculations. Click the button and select the name and the location of the file. The program will save the output to the specified file and open it with the default viewer. The pdf is always generated in A4 page size.
Alternatively, you can use a pdf printer. There are a lot of free pdf printers over the Internet. Just download and install one. After that, the process of printing is not much different than any other printer. Detailed description of printing from Calcpad is provided above.
Input data in Calcpad can be saved to disk and reused multiple times. The supported file formats are "*.txt", "*.cpd" and "*.cpdz". Input forms have to be saved to "*.cpd" and "*.cpdz" files and text scripts to "*.txt" files. Both "*.cpd" and "*.cpdz" file types are associated with Calcpad and can be opened with double click. The main difference between the two formats is that "*.cpd" is a text file and can be edited while "*.cpdz" is binary and can be only executed. The source code inside is protected from viewing, coping and modification.
You can start a new file by clicking the button. This will clear the file name and the source code. If the current file is not saved, you will be prompted to do that.
If you answer "Yes", the "File Save" dialog will appear. Enter file name and click "Save". Thus, you will preserve your data before being cleared. If you select "Cancel" you will interrupt the command and everything will remain unchanged.
You can open an existing file with the button. A file selection dialog will appear. The active file extension is "*.cpd", by default. If you search for "*.txt" or "*.cpdz" files, select the corresponding type at the bottom of the dialog. Then find the required file and press "Open" or double click on the file. It will be loaded into Calcpad and the file name will be displayed in the title bar.
You can save the current file by clicking the button. If the file has not been saved so far, you will be prompted to select path and name. Otherwise, it will be rewritten at the current location.
If you need to save the current file with a different name, select the "File/Save As…" menu command. A file selection dialog will be displayed. Select file path and name and click "Save"
Last edited on 12.07.2023 by eng. Nedelcho Ganchovski.