SimonHub Calc

Help & Reference

A small, secure calculator language with Python-like syntax.

Contents & prefixes

Related functions start with the listed prefix. Previous names remain available as compatible aliases.

Included functions Prefix Spoken / meaning
Mathematics · General mathematical functions without a prefix. no prefix
Formatting · Engineering and SI output formats. fmt_ Format
Programmer · Number bases, bit operations and pretty print. prog_ Programmer
Electronics · Basic circuits and electrical quantities. ee_ Electrical Engineering
Embedded · Timing, PWM, timers and ADCs. emb_ Embedded
Alternating current · RMS, peak and peak-to-peak values. ac_ Alternating Current
Three-phase systems · Star, delta and three-phase power. ac3_ Three-phase Alternating Current
HV battery · Pack, energy, C-rate, DCIR and losses. bat_ Battery
Electric machine · Speed, torque, power and frequency. em_ Electric Machine
Power electronics · DC/DC, PWM, modulation and semiconductor losses. pe_ Power Electronics
Visualization · Safe function plots over the variable x. no prefix
TILF · Timestamps relative to the UTC epoch of 2000. tilf_ TILF time format
Help · Direct link to this reference. no prefix

Quick start

[I1]: 1 + 2
[O1]: 3
[I2]: o1 * 10
[O2]: 30
[I3]: 230 * sqrt2
[O3]: 325.269119346
[I4]: fmt_si(ac3_p(400, 250, 0.92), "W")
[O4]: 159.349 kW
[I5]: plot(exp(x), -3, 3)
[O5]: Plot: exp(x)
[I6]: plot(log(x), 0.01, 10)
[O6]: Plot: log(x)

Allowed syntax includes + - * / // % **, parentheses, & | ^ ~ << >>, hex/binary/octal literals, documented names, and iN/oN. History references are case-insensitive.

Up opens the full catalog when the input is empty. With text in the input, Up/Down browse history. When suggestions are open, arrow keys select, Tab or Enter accepts, and Esc closes it.

Engineering literals work without whitespace: 1k, 4.7k, 2.2M, 100m, 47u, 100n, and 10p. The decimal separator is always a dot.

Function plots use plot(expression, x_min, x_max, points=300). Allowed inputs are x, mathematical constants, history references, and pure functions such as sin, cos, tan, exp, log, log10, log2, and sqrt. Undefined values create gaps.

Constants

pi e tau sqrt2 sqrt3 G M k m u_micro n pico

Constants for explicit multiplication: G M k m u_micro n pico. Unambiguous names avoid collisions with functions.

Mathematics

General mathematical functions without a prefix.

abs(x)

Absolute value.

acos(x)

Arc cosine in radians.

asin(x)

Arc sine in radians.

atan(x)

Arc tangent in radians.

atan2(y, x)

Quadrant-aware angle in radians.

ceil(x)

Round up to an integer.

cos(x)

Cosine; x in radians.

degrees(rad)

Convert radians to degrees.

exp(x)

Exponential function with base e.

factorial(n)

Factorial up to n=500.

floor(x)

Round down to an integer.

hypot(*values)

Euclidean length.

log(x, base=e)

Logarithm with an optional base.

log10(x)

Base-10 logarithm.

log2(x)

Base-2 logarithm.

max(a, b, ...)

Largest value.

min(a, b, ...)

Smallest value.

radians(deg)

Convert degrees to radians.

round(x, digits=0)

Round a value to the requested digits.

sin(x)

Sine; x in radians.

sqrt(x)

Square root.

tan(x)

Tangent; x in radians.

trunc(x)

Discard the fractional part.

Formatting

Engineering and SI output formats.

fmt_
fmt_eng(value, digits=6)

Format a value in engineering notation.

Compatible alias: eng() Example: fmt_eng(0.0000047)
fmt_si(value, unit, digits=6)

Format a value with an SI prefix and unit.

Compatible alias: si() Example: fmt_si(188495, "W")

Programmer

Number bases, bit operations and pretty print.

prog_
prog_bin(value)

Binary representation; keeps the numeric result.

Compatible alias: bin()
prog_bits(value)

Compact bit overview; returns the numeric value.

Compatible alias: bits()
prog_byteswap(value, bits=32)

Reverse byte order.

Compatible alias: byteswap()
prog_chr(codepoint)

Unicode character for a code point.

Compatible alias: chr()
prog_clear_bit(value, bit)

Clear one bit.

Compatible alias: clear_bit()
prog_hex(value)

Hexadecimal representation; keeps the numeric result.

Compatible alias: hex()
prog_int(value, base=10)

Convert to an integer, optionally using a base.

Compatible alias: int()
prog_oct(value)

Octal representation; keeps the numeric result.

Compatible alias: oct()
prog_ord(character)

Unicode code point for one character.

Compatible alias: ord()
prog_popcount(value)

Count set bits.

Compatible alias: popcount()
prog_pp(value)

Pretty-print as DEC/HEX/BIN; returns the numeric value.

Compatible alias: pp() Example: prog_pp(0x1234abcd)
prog_rol(value, shift, bits=32)

Rotate left within the selected width.

Compatible alias: rol()
prog_ror(value, shift, bits=32)

Rotate right within the selected width.

Compatible alias: ror()
prog_s16(value)

Signed 16-bit value.

Compatible alias: s16()
prog_s32(value)

Signed 32-bit value.

Compatible alias: s32()
prog_s64(value)

Signed 64-bit value.

Compatible alias: s64()
prog_s8(value)

Signed 8-bit value.

Compatible alias: s8()
prog_set_bit(value, bit)

Set one bit.

Compatible alias: set_bit()
prog_test_bit(value, bit)

Read one bit as 0 or 1.

Compatible alias: test_bit()
prog_toggle_bit(value, bit)

Toggle one bit.

Compatible alias: toggle_bit()
prog_twos(value, bits)

Interpret a two's-complement value.

Compatible alias: twos() Example: prog_twos(0xff, 8)
prog_u16(value)

Unsigned 16-bit value.

Compatible alias: u16()
prog_u32(value)

Unsigned 32-bit value.

Compatible alias: u32()
prog_u64(value)

Unsigned 64-bit value.

Compatible alias: u64()
prog_u8(value)

Unsigned 8-bit value.

Compatible alias: u8()

Electronics

Basic circuits and electrical quantities.

ee_
ee_db(ratio)

Amplitude ratio in dB.

Compatible alias: db()
ee_db_power(ratio)

Power ratio in dB.

Compatible alias: db_power()
ee_dbm(power_w)

Convert watts to dBm.

Compatible alias: dbm()
ee_divider(vin, r_top, r_bottom)

Unloaded voltage divider.

Compatible alias: divider()
ee_fc_rc(resistance, capacitance)

RC cutoff frequency.

Compatible alias: fc_rc()
ee_i(voltage, resistance)

Ohm's law I=U/R.

Compatible alias: i()
ee_p(voltage, current)

Electrical power U·I.

Compatible alias: p()
ee_parallel(*resistances)

Equivalent resistance of parallel resistors.

Compatible alias: parallel() Example: ee_parallel(1000, 2200)
ee_r(voltage, current)

Ohm's law R=U/I.

Compatible alias: r()
ee_ratio_db(db_value)

Convert dB to an amplitude ratio.

Compatible alias: ratio_db()
ee_rc(resistance, capacitance)

RC time constant.

Compatible alias: rc()
ee_rl(inductance, resistance)

RL time constant.

Compatible alias: rl()
ee_series(*values)

Add components connected in series.

Compatible alias: series()
ee_u(current, resistance)

Ohm's law U=I·R.

Compatible alias: u()
ee_watts_dbm(dbm_value)

Convert dBm to watts.

Compatible alias: watts_dbm()
ee_xc(frequency, capacitance)

Capacitive reactance.

Compatible alias: xc()
ee_xl(frequency, inductance)

Inductive reactance.

Compatible alias: xl()

Embedded

Timing, PWM, timers and ADCs.

emb_
emb_adc_code(voltage, vref, bits)

Convert voltage to an ideal ADC code.

Compatible alias: adc_code()
emb_adc_voltage(code, vref, bits)

Convert an ADC code to voltage.

Compatible alias: adc_voltage()
emb_bit_time(baudrate)

Bit duration from baud rate.

Compatible alias: bit_time()
emb_frequency(period)

Convert period to frequency.

Compatible alias: frequency()
emb_period(frequency)

Convert frequency to period.

Compatible alias: period()
emb_pwm_duty(on_time, period)

PWM duty cycle from 0 to 1.

Compatible alias: pwm_duty()
emb_timer_frequency(clock, prescaler, period)

Timer frequency; period counts from zero.

Compatible alias: timer_frequency()

Alternating current

RMS, peak and peak-to-peak values.

ac_
ac_peak(rms_value)

Convert a sinusoidal RMS value to peak.

Compatible alias: peak()
ac_peak_from_pp(vpp_value)

Convert peak-to-peak to peak.

Compatible alias: peak_from_pp()
ac_rms(peak_value)

Convert a sinusoidal peak value to RMS.

Compatible alias: rms()
ac_vpp(peak_value)

Convert a peak value to peak-to-peak.

Compatible alias: vpp()

Three-phase systems

Star, delta and three-phase power.

ac3_
ac3_delta_line_current(i_phase)

Delta: I_line=I_phase·√3.

Compatible alias: delta_line_current()
ac3_delta_phase_current(i_line)

Delta: I_phase=I_line/√3.

Compatible alias: delta_phase_current()
ac3_p(v_line, i_line, cosphi=1)

Three-phase active power from line quantities.

Compatible alias: p3() Example: ac3_p(400, 250, 0.92)
ac3_q(v_line, i_line, cosphi)

Three-phase reactive power from line quantities.

Compatible alias: q3()
ac3_s(v_line, i_line)

Three-phase apparent power from line quantities.

Compatible alias: s3()
ac3_star_line_current(i_phase)

Star: I_line=I_phase.

Compatible alias: star_line_current()
ac3_star_line_voltage(v_phase)

Star: U_LL=U_phase·√3.

Compatible alias: star_line_voltage()
ac3_star_phase_voltage(v_line)

Star: U_phase=U_LL/√3.

Compatible alias: star_phase_voltage()

HV battery

Pack, energy, C-rate, DCIR and losses.

bat_
bat_c_rate(current, capacity_ah)

Calculate battery C-rate.

Compatible alias: c_rate()
bat_cell_v(pack_v, ns)

Cell voltage from pack voltage.

Compatible alias: cell_v()
bat_current_c(c_rate, capacity_ah)

Current from C-rate and capacity.

Compatible alias: current_c()
bat_dcir(delta_v, delta_i)

DC internal resistance from voltage and current delta.

Compatible alias: dcir()
bat_eff(pin, pout)

Efficiency Pout/Pin from 0 to 1.

Compatible alias: eff()
bat_energy_kwh(voltage, capacity_ah)

Nominal energy in kWh.

Compatible alias: energy_kwh()
bat_energy_wh(voltage, capacity_ah)

Nominal energy in Wh.

Compatible alias: energy_wh()
bat_loss(pin, pout)

Power loss Pin−Pout.

Compatible alias: loss()
bat_pack_ah(cell_ah, np)

Battery pack capacity.

Compatible alias: pack_ah()
bat_pack_kwh(cell_v, cell_ah, ns, np)

Pack energy from cell voltage, capacity and topology.

Compatible alias: pack_kwh() Example: bat_pack_kwh(3.7, 5, 216, 24)
bat_pack_v(cell_v, ns)

Battery pack voltage.

Compatible alias: pack_v()
bat_pdc(voltage, current)

DC power U·I.

Compatible alias: pdc()
bat_ploss(current, resistance)

Resistive power loss I²R.

Compatible alias: ploss()
bat_soc_energy(capacity_kwh, soc)

Available energy; state of charge from 0 to 1.

Compatible alias: soc_energy()
bat_vdrop(current, resistance)

Voltage drop I·R.

Compatible alias: vdrop()

Electric machine

Speed, torque, power and frequency.

em_
em_electrical_frequency(rpm, pole_pairs)

Electrical fundamental frequency.

Compatible alias: electrical_frequency()
em_mech_power(torque, rpm)

Mechanical power from torque and speed.

Compatible alias: mech_power()
em_omega(rpm)

Convert speed to radians per second.

Compatible alias: omega()
em_rpm(power, torque)

Speed from mechanical power and torque.

Compatible alias: rpm()
em_rpm_from_omega(omega)

Convert radians per second to rpm.

Compatible alias: rpm_from_omega()
em_rpm_sync(frequency, pole_pairs)

Synchronous speed.

Compatible alias: rpm_sync()
em_torque(power, rpm)

Torque from mechanical power and speed.

Compatible alias: torque()

Power electronics

DC/DC, PWM, modulation and semiconductor losses.

pe_
pe_boost_duty(vout, vin)

Ideal boost duty cycle 1−Vin/Vout.

Compatible alias: boost_duty()
pe_boost_v(vin, duty)

Ideal CCM boost: Vout=Vin/(1−D).

Compatible alias: boost_v()
pe_buck_v(vin, duty)

Ideal buck: Vout=Vin·D; D from 0 to 1.

Compatible alias: buck_v()
pe_cond_loss(i_rms, r_on, duty=1, devices=1)

Conduction loss from RMS current and on-resistance.

Compatible alias: cond_loss()
pe_duty(vout, vin)

Ideal buck duty cycle Vout/Vin.

Compatible alias: duty()
pe_spwm_mod_index(vll_rms, vdc)

SPWM modulation index.

Compatible alias: spwm_mod_index()
pe_spwm_vll_rms(vdc, m=1)

Two-level SPWM: U_LL,rms=m·Vdc·√3/(2√2).

Compatible alias: spwm_vll_rms()
pe_svpwm_mod_index(vll_rms, vdc)

Normalized SVPWM modulation index.

Compatible alias: svpwm_mod_index()
pe_svpwm_vll_rms(vdc, m=1)

Linear normalized SVPWM: U_LL,rms=m·Vdc/√2.

Compatible alias: svpwm_vll_rms()
pe_switch_loss(eon, eoff, fsw, devices=1)

Switching loss from energy, frequency and devices.

Compatible alias: switch_loss()

Visualization

Safe function plots over the variable x.

plot(expression, x_min, x_max, points=300)

Plot a whitelisted mathematical expression over x.

Example: plot(sin(x), -2*pi, 2*pi)

TILF

Timestamps relative to the UTC epoch of 2000.

tilf_
tilf_convert(timestamp)

Show UTC and seconds since the year 2000 epoch.

Compatible alias: tilf() Example: tilf_convert("2020-07-16 08:07:00")
tilf_diff(timestamp1, timestamp2)

Difference between two TILF times in seconds.

Compatible alias: dtilf()
tilf_now()

Current UTC time as TILF seconds.

Compatible alias: tnowilf()

Help

Direct link to this reference.

help()

Open the web help reference.

Security limits

Calc never executes unrestricted Python code. Attributes, imports, builtins, dunder names, assignments, lambdas, comprehensions, container literals, and arbitrary calls are rejected. Limits also apply to input length, AST size and depth, arguments, strings, integers, exponents, shifts, results, and HTTP request size. Engineering suffixes are only translated for directly adjacent decimal numbers from a fixed whitelist. Plots use a separate mathematics whitelist and at most 500 samples.