# Procapy

Programmer's Calculator in Python for Sublime Text

## Details

## Installs

- Total 28
- Win 16
- OS X 10
- Linux 2

Mar 24 | Mar 23 | Mar 22 | Mar 21 | Mar 20 | Mar 19 | Mar 18 | Mar 17 | Mar 16 | Mar 15 | Mar 14 | Mar 13 | Mar 12 | Mar 11 | Mar 10 | Mar 9 | Mar 8 | Mar 7 | Mar 6 | Mar 5 | Mar 4 | Mar 3 | Mar 2 | Mar 1 | Feb 28 | Feb 27 | Feb 26 | Feb 25 | Feb 24 | Feb 23 | Feb 22 | Feb 21 | Feb 20 | Feb 19 | Feb 18 | Feb 17 | Feb 16 | Feb 15 | Feb 14 | Feb 13 | Feb 12 | Feb 11 | Feb 10 | Feb 9 | Feb 8 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|

Windows | 0 | 0 | 0 | 0 | 0 | 2 | 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 | 0 | 0 | 0 | 0 | 0 | 0 |

OS X | 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 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 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”