Chapter 5. Calculator Modes
Prev |  | Next

# Chapter 5. Calculator Modes

Qalculate! provides flexible parsing, calculation output and result display. There are several ways in which parsing of expression and display of results can be customized. These modes can generally be changed through the mode menu. The state of each mode can be saved under a name in Mode → Meta Modes for quick access. The Preset and Default meta modes are always available and represents the state when Qalculate! is load for the first time and the mode settings automatically loaded at each startup (and by default saved on exit), respectively. Different modes are summarized below.

Number Bases

  Non-decimal bases can be selected for display of numbers in the result and parsing of numbers in expressions. This include regular number bases (binary, octal, hexadecimal, sexagesimal) as well as sexagesimal time format and roman numerals. Other number bases, as well as base for expression input, can be selected from a dialog window accessed from Mode → Number Base → Other... or Mode → Number Base → Select Result and Expression Base....

  Table 5.1. Supported Number Bases

  Radix | Digits | Comments
  --- | --- | ---
  2-10 | 1-10 |
  12 | 1-10, ↊/X/A/a, ↋/E/B/b | Support all functions, variables and units that does not conflict with digits.
  11-36 | 1-10, A-Z (case insensitive) | Support all functions, variables and units that does not conflict with digits.
  37-62 | 1-10, A-Z, a-z | Support all functions, variables and units that does not conflict with digits.
  > 62 | Unicode characters (“0” = 62) or escaped values (“\523” = 523, “\x7f” = 127) | Does not support operators, functions, variables or units. Result display only uses escaped values except for with base 1114112 (the “Unicode” base).
  Negative bases (e.g. -2) | Same as corresponding positive base | Result display only supports negative integer bases.
  Non-integer bases (e.g. √2) | Same as corresponding integer base (rounded away from zero) | Result display only supports real bases.

  The convert number bases dialog (see the section called “Convert Number Bases Dialog”) and the programming keypad (see Table 3.3, “Programming Keypad”) provides efficient conversion between common bases. For output of a single value to a specific number base use of the “to”-operator is recommended (see the section called “The “to” (and “where”) operators”). For input of single number in a specific base, the base() function, which in addition supports non-numerical bases, or base prefixes (“0b”, “0o”, “0d”, and “0x” for base 2, 8, 12, and 16, respectively) can be used.

Numerical Display

  These modes mainly control when numbers are displayed exponentially (e.g. “2.62E3” which equals “2620”). In the default normal mode, numbers are displayed in exponential format if the exponent will be greater than the current precision. In scientific mode the lowest exponent is 3. In simple numerical mode the exponential format is never used and it is always used in purely scientific mode. In the engineering mode, the exponent is always a multiple of three. This is naturally equivalently true for numbers less than one and negative exponents. When the scientific modes are selected in the keypad (not from the menubar), negative exponents are automatically activated and sort minus last deactivated, while normal and simple modes do the opposite.

Indicate Repeating Decimals

  If this option is on, Qalculate! will not round infinitely repeating digit sequences, if the digits in the sequence fits the maximum number of decimals. Instead “…” will be displayed after the repeated digits and the result indicated as exact (compare “9/11 ≈ 0,81818182” with “9/11 = 0,81 81…”).

Rounding

  By default approximately displayed numbers are rounded towards nearest decimal (e.g. “2.64 ≈ 2.6”, “2.67 ≈ 2.7”), and away from zero if the number is halfway between two values (e.g. “2.65 ≈ 2.7”, “−2.65 ≈ −2.7”). This can be changed by activating Round Halfway Numbers to Even (e.g. “2.55 ≈ 2.6”, “2.65 ≈ 2.6”) or Truncate Numbers (if activated, numbers are always rounded towards zero, e.g. “2.67 ≈ 2.6”).

Show Ending Zeroes

  If this option is on, approximate numbers in the result will be appended with zeroes, so that the number of digits (after preceding zeroes) will equal the precision.

Negative Exponents

  If negative exponents is activated, division is shown as a negative power (e.g. “x × y^-1” instead of “x / y”).

Sort Minus Last

  This option decides if minus signs should be avoided in the first positions of the result expression.

Complex Number Form

  Complex number can be displayed in rectangular/cartesian (e.g. “5i + 2”), exponential (e.g. “5.39 × e^1.19”), polar form (e.g. “5.39 × (cos(1.19) + i × sin(1.19))”), or angle/phasor notation (e.g. “5.39∠1.19”).

Rational Number Form

  This controls if rational numbers are displayed as fractions or not. The exact decimal fraction mode displays the number as a simple fraction, if the rational number does not have an exact decimal representation which can be displayed using the number of digits allowed by the current precision. The rational number “4/3” is displayed as “1.3333333” (or “1.333…” if indicate repeating decimals is activated) in decimal fractions mode, as “4/3” in both exact decimal fractions and simple fractions mode, and as “1 + 1/3” in mixed fractions mode.

Unit Display

  The automatic use of prefixes for units in results can be toggled on and off. By default prefixes are only used for a selection of units (mainly standard SI and CGS units), but this can be changed to also include currencies or all other units. By default prefixes representing a power of ten not dividable by three (centi, deci, deca and hecto), as well the new SI prefixes adopted in 2022 (ronna, quetta, ronto, and quecto), are not used automatically. If denominator prefixes are not explicitly enabled, prefixes will only be set for the numerator in a fractional unit expression (e.g. “1 Mg/m” or “1 kg/mm”), unless there is no unit in the numerator. Binary prefixes are never used automatically, unless activated for information units (bits, bytes, etc.) in the preferences dialog.

  Units can be automatically converted to base units or the optimal units in results. Optimal conversion means that the number of units in the result is reduced to as few units as possible. Only SI units are used for conversion. If Convert to Optimal SI unit is activated, non-SI units are converted to SI units, even if equally or less optimal than the original unit(s). In optimal unit mode, currencies are converted to the local currency, unless deactivated in the preferences dialog. Mixed units conversion allows certain units, such as time units and many imperial/U.S. customary units, to be converted to a combination of appropriate units, e.g. “60.2 minutes = 1 hour to 12 seconds”.

  The place units separately alternative controls the display of unit expressions in result. If it is enabled (default) units will be displayed separate from other parts of the expression at the end (compare “(5x × m)/(y × s)” and “5x/y m/s”).

Abbreviate Names

  The display of unit, prefix, variable and function names can be controlled by selecting to display abbreviations or full length names (e.g. “5 cm” or “5 centimeters”). Both abbreviations and long names can however always be entered in expressions.

Approximation

  When always exact mode is on, the calculation will not go further than what can be calculated exactly (e.g. “sqrt(2 + 3) = sqrt(5)”). The default “Try Exact” mode, will calculate the result exact as far as possible and then approximately. Approximate mode will directly calculate a approximate result, thus being a bit faster but giving a less correct approximate indication (“sin(pi/2)” return approximately one instead of exactly one). If the interval arithmetic mode is activated the precision of the final result is guaranteed by calculating an interval for every approximate value (See Chapter 6, Propagation of Uncertainty and Interval Arithmetic).

Assumptions

  This controls the default assumptions for unknown variables without explicitly defined assumptions. See Chapter 7, Variables. The assume denominators non-zero alternative makes it possible to avoid the situation where expressions such as “(x-1)/(x-1)” can not be further simplified because the denominator might be zero (if x equals 1). With this alternative activated the example can be reduced to 1.

Parsing Mode

  These options controls how expressions are interpreted. There are three main modes, which mainly controls if implicit multiplication is handled differently from explicit multiplication and if spaces are taken into account or not. See the section called “Implicit Multiplication and Parsing Modes”. If the read precsion option is activated, decimal numbers are intrepeted as approximate with precision equal to the number of digits (e.g. “1.1 × 3.20 = 1.1±0.05 × 3.20±0.005 ≈ 3.5±0.2”).

Precision

  Precision specifies the default number of significant digits displayed and determines the precision used for approximate calculations. The internal precision is higher than the one specified, but will nevertheless not completely protect against loss of significance/catastrophic cancellation (and you will not be alterted unless interval arithmetic is activated).

Decimals

  In the decimals dialog, the number of decimals displayed can be controlled. This includes minimal (will fill out with zeroes) and maximal number of decimals (will round numbers).

## The RPN Mode

The Reverse Polish Notation mode can be activated from Mode → RPN Mode, Ctrl+R or from the context menu of the expression entry. For details about what Reverse Polish Notation is and how it generally works, see for example the RPN article at Wikipedia.

Central to the RPN mode is the stack, a list of registers/values that is operated on by functions and operators. The stack has a variable number of registers which can hold an unlimited number of values. The stack size is dynamically changed when a new value is added and the first value on the stack is shown in the result display. Mathematical operators such as plus and minus then operates on the first two, last added, values on the stack. The second value is changed with input from the first value. For example, the minus operator subtracts the first value from the second.

For example, 5 ENTER 3 + 2 / adds 5 to the stack, then adds 3 to the stack and moves 5 down a step and adds 3 to 5. The first value, 3, is removed from the stack and the value left is 8. Then 2 is added to the stack and 8 is divided by 2, resulting in 4. This would in a single expression with non-RPN (infix) syntax be entered as “(5 + 3)/2”.

Functions operate on the top values of the stack. Functions which require multiply arguments, fill the arguments in reversed order from the top (e.g. 5 ENTER 2 ENTER rem equals “rem(5, 2)”). Functions with a vector argument uses all stack regsters (unless the top value is a vector). This is quite useful for statistical functions (e.g. 5 ENTER 2 ENTER 3 ENTER 4 ENTER harmmean calculates the harmonic mean of 5, 2, 3, and 4 and leaves the result, 3.1169, as the only value on the stack).

When the RPN stack is enabled, full expressions can still be entered (you can add e.g. “5x + 3 + 23 + sin(2)” directly to the stack). The buttons on the keypad do not insert operators and functions in the expression entry, but instead applies them to the stack. This is also true for the keys on the keyboard, unless deactivated in the preferences (Edit → Preferences, Use only keypad keys for RPN). Enter calculates the current expressions and adds it to the stack (calculated mathematical expressions are automatically added to the stack when the RPN stack is enabled). If the expression entry is not empty when applying an operator or function to the stack, the expression is first calculated and added to the stack. If the expression only contains an operator or a single function without arguments, the operator/function is applied to the stack.

Figure 5.1. RPN Mode

The RPN mode adds a third page to the main window, for display and manipulation of the values on the stack. This shows a list of values on the stack, with the last added value on the top.

On the right are buttons for manipulation of the stack. The buttons move the selected value up (Ctrl+Up) or down (Ctrl+Down), move it to the top (Ctrl+Right), copy it (Ctrl+Shift+C), edit it, or removes it (Ctrl+Delete), in order. If no stack row is selected, the up and down buttons rotates the stack, the swap button swaps the places of the first and second value and the copy and delete buttons acts on the the top value of the stack. The button between copy and delete enters the top value from before the last numeric operation (Ctrl+Left). The last button removes all values from the stack (Ctrl+Shift+Delete).

On the left are buttons for applying mathematical operations to the stack. The top left buttons applies addition, subtraction, multiplication, division, and exponentiation to the top two values. If only one value is available addition, multiplication, and exponentiation uses this value twice, while the subtraction button negates the value and the division button calculates the reciprocal. The buttons below negates the top value, calculates the reciprocal, and calculates the square root of the the top value. The last button calculates the sum of all values on the stack. Changes in the display of results only affects the first value on the stack.

Reverse Polish Notation can also be used directly in expression. This can be activated or deactivated separately from the RPN stack (Mode → Parsing Mode → RPN Syntax). When using RPN syntax, a temporary stack, separate from the previously mentioned stack, is created from the contents of each mathematical expression entered. To calculate “(5 + 3)/2”, as in the example above, with RPN syntax you should enter the expression “5 3 + 2 /”. Instead of actually pressing enter on the keyboard, each separate value on the stack is separated by a blank space. The RPN syntax only supports functions that require exactly one argument.

Prev |  | Next
Chapter 4. Expressions | Home | Chapter 6. Propagation of Uncertainty and Interval Arithmetic