PyCalc

Calculate better

PyCalc Help

Input Modes


PyCalc can enhance standard Python behavior using two sets of user-configurable settings:

Note that these apply only to Python code you type into the code entry box — startup.py is unaffected by these settings.

This page will introduce Input Modes. A separate page will discuss result formatting.

There are two categories of Input Modes: Matrix Mode and Precision Mode.

Matrix Mode

Python packages make it possible to do sophisticated linear algebra. However, the syntax for doing so can be cumbersome. Since ease-of-use is important for a calculator, PyCalc streamlines the experience via Matrix mode.

When Matrix mode is disabled, PyCalc uses standard Python behavior. Specifically, brackets ([]) are used to create Python lists. For example, [1, 2, 3] would result in a Python list with 3 elements.

When Matrix mode is enabled, PyCalc intercepts any bracket expressions you enter and converts them into matrices. For more details on Matrix mode, see this page.

Precision Mode

While standard Python has many nice features for a calculator, it has some subtle deficiencies. This can be seen easily with a normal Python interpreter by typing 2.5 - 1.6. Most people would expect the answer to be 0.9. But Python instead gives 0.8999999999999999. This is because Python uses binary math with limited precision. You can read more about this issue here.

PyCalc uses a couple different techniques for dealing with this issue. One technique is to intercept values that you enter into PyCalc and convert them from Python's standard float type (which is a limited-precision binary value) to other types. Three "Precision Modes" are provided:

For most use cases, we recommend using Decimal mode.

Some examples will help clarify the relative advantages of these modes. (Note that these examples use "Result Format" set to disabled... we discuss result formatting on another page.)

Expression Standard Mode Result Decimal Mode Result Fractional Mode Result
2.5 - 1.6 0.899999...
(16 decimal digits)
0.9 9/10
1e40 + 1 - 1e40 0.0 1.0 1
2/7 + 3/7 0.7142857...
(16 decimal digits)
0.7142857...
(50 decimal digits)
5/7
0.125 + 1/2 0.625 0.625 5/8
type(1.1) float mpmath.mpf sympy.Rational

In Fractional mode, to enter an improper fraction you can either enter it directly (17/3) or enter it as an addition (5+2/3).

Settings

The input modes can be set in two different ways: