# Procapy

Programmer's Calculator in Python for Sublime Text

## Details

## Installs

- Total 59
- Win 31
- Mac 23
- Linux 5

Aug 5 | Aug 4 | Aug 3 | Aug 2 | Aug 1 | Jul 31 | Jul 30 | Jul 29 | Jul 28 | Jul 27 | Jul 26 | Jul 25 | Jul 24 | Jul 23 | Jul 22 | Jul 21 | Jul 20 | Jul 19 | Jul 18 | Jul 17 | Jul 16 | Jul 15 | Jul 14 | Jul 13 | Jul 12 | Jul 11 | Jul 10 | Jul 9 | Jul 8 | Jul 7 | Jul 6 | Jul 5 | Jul 4 | Jul 3 | Jul 2 | Jul 1 | Jun 30 | Jun 29 | Jun 28 | Jun 27 | Jun 26 | Jun 25 | Jun 24 | Jun 23 | Jun 22 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|

Windows | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |

Mac | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |

Linux | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |

## Readme

- Source
- raw.githubusercontent.com

# SublimeProcapy

Programmer's Calculator in Python for Sublime Text. This is an inline calculator to use inside any document view in Sublime Text. Use inside existing views (e.g. source files) for quick inline calculations or dedicate a blank/unsaved view to use as an embedded standalone calculator.

## Usage

Simply select an expression (or multiple expressions using multiple selections) and execute the calculator by pressing the keyboard shortcut and the selection(s) will be replaced by the result of the calculation. Alternatively, if there are no selections, the line of the cursor will be parsed and the result inserted on the line after it (also works with multiple cursors). This is useful when using it as a normal calculator to incrementally perform a sequence of calculations using the result of the previous calculation as input for the following calculation leaving each step in the series of calculations visible.

Procapy supports any valid Python, and will reduce the result of any expression to a number (or an error string if something did not parse correctly).

The default keyboard shortcuts are:

- ALT-ENTER: Calculate decimal
- CRTL-ALT-ENTER: Calculate hexadecimal
- SHIFT-ALT-ENTER: Calculate binary
- SHIFT-CTRL-ALT-ENTER: Calculate octal

## Built-in functions

In addition to the Python standard functions, math and cmath modules (the latter imported into the cmath namespace), Procapy adds the following functions that are useful in programming:

- u(w,x): truncate x to an unsigned integer of width w.
- u8(x), u16(x), u32(x), u64(x): truncate x to an unsigned integer of the indicated width.
- i(w,x): truncate x to a signed integer of width w.
- i8(x), i16(x), i32(x), i64(x): truncate x to a signed integer of the indicated width.

These are similar to the built-in function int(x) which will truncate to an integer of unlimited width.

In addition, the variable n is assigned a value matching the index of each selection. This can be used in mathematical expressions to form different results for each selection.

## Examples

Difference between two hex numbers:

- “0x0003 - 0x0007”
- Decimal: “-4”

Same but truncated to 32bit unsigned range which reveals the two's complement encoding of the negative number:

- “u32(0x0003 - 0x0007)”
- Hex: “0xfffffffc”

Division and addition:

- “800 / 33 + 500 / 42”
- Decimal: “36.14718614718615”
- Hex: “0x24”
- Binary: “0b100100”

Same but adding truncation to 8bit unsigned of intermediate results:

- c “u8(800 / 33) + u8(500 / 42)”
- Decimal: “35”

Interpretation of a positive hex number as unsigned integer:

- “0xfffffffe”
- Decimal: “4294967294”

Same but showing truncatated to 32bit signed integer, revealing the value when interpreted as a two's complement encoding:

- “i32(0xfffffffe)”
- Decimal: “-2”

Comparisons operators return True/False in decimal mode and 0/1 in hex/binary/octal:

- “0x0003 - 0xffff > 50”
- Decimal: “False”
- Hex: “0x0”
- Binary: “0b0”

Same but with truncation of intermediate result to 32bit unsigned integer:

- “u32(0x0003 - 0xffff) > 50”
- Decimal: “True”

Mixed radix calculations:

- “0b1011 + 0x5 + 5”
- Decimal: “21”
- Hex: “0x15”

Bitwise operators (AND, NOT, OR, XOR):

- “0b1011 | ~0x5 & 5 ^ 0b101”
- Decimal: “15”
- Hex: “0xf”
- Binary: “0b1111”

Shift operators:

- “(1 << 7) >> 3”
- Decimal: “16”
- Hex: “0x10”
- Binary: “0b10000”

Boolean operators and (in)equality:

- “45 > 5 and 6 < 7 or 5 == 3 and 4 != 4”
- Decimal: “True”

Rounding:

- “round(4.51)”
- Decimal: “5”