Calculator

I often use a mix of hexadecimal and decimal in my calculations, and needed a calculator that could do this conveniently. I designed this calculator with the following goals:

This is the documentation page. The calculator is here.

Features

Implementation

Help

Keyboard input

The top two rows of buttons map to F1 to F12 of the keyboard, with Shift for the top row, and without Shift for the second row.

When a button has a red label above, or blue label below the main label, the red function is accessed by holding Shift, while the blue function is accessed by holding Ctrl.

Scientific notation

Unlike most calculators, the decimal point and exponent functions share one key. When entering a number, press ∙/EXP once to enter the fractional part, and press ∙/EXP again to enter the exponent. Some examples:

Backspace key

The backspace key is used for three similar operations:

Decimal, Hexadecimal, and Binary

Converting between bases is done by changing the display mode using the Bin, Dec, and Hex buttons. Changing the mode changes the base for all numbers in the display.

Entering numbers: The base can be changed while entering a number, to allow mixed-base expressions. When entering a number, pressing Bin/Dec/Hex once changes the base only for the number being entered without changing the display mode. Pressing a second time changes the display mode. The base of a number being entered can also be changed with the Shift and Ctrl keys. Typing digits while holding Shift changes the base to decimal, while holding Ctrl changes the base to Hexadecimal.

For example, to calculate C00 (hexadecimal) + 128 (decimal), type Ctrl+(C00)+Shift+(128)=, holding Ctrl while typing C00 and holding Shift while typing 128. The result will be c00+80=c80 in hexadecimal mode or 3072+128=3200 in decimal mode. Individual numbers being entered can be in a different base than the current display mode. The same calculation in RPN mode would be Ctrl+(C00)EnterShift+(128)+, with a result of c80 (hexadecimal), 3200 (decimal), or 110010000000 (binary).

Typing a digit that exceeds the maximum allowed by the current mode also automatically changes the base. For example, typing 5 while in binary mode automatically changes the number to decimal, while typing A changes the number to hexadecimal, regardless of whether Shift or Ctrl are held.

What's the current base?

The current display mode is shown by the yellow highlight on the Bin, Dec, and Hex buttons. This indicates the base that is used to display numbers, and is also the default base used when entering a new number.

When entering a number, the base of the current number is shown in the display and on the Bin/Dec/Hex buttons. The right side of the bottom row of the display shows BIN, DEC, or HEX, and one of the Bin/Dec/Hex button labels has an underline. These are only shown when entering a number. If the yellow highlight is on a different Bin/Dec/Hex button than the underline, it indicates that the number is being entered in a different base than the base used to display numbers.

Interesting Calculations

This is the hypot (hypotenuse) function. It computes sqrt(x2 + y2). For example, 34 = 5.

This function computes 1/(1/x + 1/y). This is sometimes called the "parallel" operator, because it can be used to calculate the resistance of two parallel resistors.

fracint

These two functions take the fractional part and integer part of a number, respectively. For example, for the number 123.45, the fractional part is 0.45 and the integer part is 123.

mod

This button is located at Shift-÷. It computes the remainder from dividing the first operand by the second operand. The quotient of the division is rounded towards zero. This function is implemented using mpfr_fmod.

→fp32→fp64←fp32←fp64

These buttons convert raw IEEE 754 floating-point numbers (as 32-bit or 64-bit integers) to and from floating-point values. For example, 1 →fp32 becomes 0x3f800000 (or 1065353216), and ←fp32 performs the reverse operation to convert 0x3f800000 back to 1.0.

Options

Input notation

There are two input notations supported:

The button layout is slightly different between the two modes. RPN mode uses an Enter key to enter multiple numbers without an operator in between, while infix mode requires (, ), and = keys.

Button layout

The Numpad layout matches the numeric keypad and navigation keys of a typical full-size keyboard. Hexadecimal numbers can be entered using the numeric keypad while holding down Ctrl. This places the A to F keys near the numeric keys, to allow entering hexadecimal numbers without jumping all over the keyboard.

The Hexadecimal layout is intended for mouse or touchscreen devices where there is no need for buttons to be arranged to match a keyboard. With more buttons, all sixteen hexadecimal digits are arranged in numerical order and available without using Ctrl.

The Touch 42 layout arranges the sixteen hexademical digits into four groups of four. Each digit is entered by dragging from one of the four start squares to one of four end squares, which provides 16 different combinations. For example, dragging from the lower-left square to the upper-right square results in the digit 2. The numbers 0, 4, 8, and C only require a single tap/click because they have the same start and end square. Because there are only four buttons instead of sixteen, less precise clicking/tapping is required. In exchange, most digits are line segments instead of just a point.

Display notation

Display options

Integer truncate

If set to something other than None, the result of every operation is truncated to an integer of the selected number of bits. This is useful when you want to use fixed-length two's complement integers including its overflow behaviour.

Angles

Select degrees or radians as the unit for angles for trigonometric functions.