1 Cordial SPICE
jess edited this page 2026-04-15 09:38:07 -07:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Cordial: SPICE Notation

Enable

use spice

SI prefixes

Prefix Multiplier Name
m / M ×10⁻³ milli
u / U / µ / μ ×10⁻⁶ micro
n / N ×10⁻⁹ nano
p / P ×10⁻¹² pico

Units

Unit Quantity
F Farads
H Henries
Hz Hertz
V Volts
A Amperes
W Watts
R / Ohm Ohms
S Siemens
J Joules

Case-insensitive; uppercased on display.

Literals

use spice

100nF                       // 1e-7 F
80Hz                        // 80 Hz
10µF                        // 1e-5 F
22n                         // 2.2e-8 with no unit

Internally: [scalar, "UNIT"].

Unit annotations

let cap:  F  = 22n          // [2.2e-8, "F"]
let freq: Hz = 60           // [60, "HZ"]
let h     = 10
let inductance: H = h       // [10, "H"]

Unit algebra

Op Rule
* same → squared; different → A·B; one-sided → carry
/ same → drop unit; one-sided → A/X or 1/X
+, -, % same or one-sided → carry; different → drop
^ , , √F, F^N
2F * 3H                     // [6, "F·H"]
6F / 3F                     // 2
6F / 2H                     // [3, "F/H"]
1F + 2F                     // [3, "F"]
1F + 2H                     // 3 — labels dropped
(2F)^2                      // [4, "F²"]

Function annotations

use spice

fn charge(c: F, v: V) -> J {
    return 0.5 * c * v^2
}

/= charge(100uF, 12V)
    → 7.2MJ

Display formatting

3 significant figures. Closest SI prefix so mantissa ∈ [1, 1000). Unit uppercased.

1.5e-7 F   →  150NF
2.2e-5 F   →  22UF
[707e-3, "F/H"]   →  707M F/H
[5.0, "F²"]       →  5 F²

Strip operator

let c = 22nF                // [2.2e-8, "F"]
let raw = ~c                // 2.2e-8

See also