Skip to content

Units and precision

Every deck chooses units="nm", "um", or "mm". Lengths use that unit, areas its square, angles degrees, and density fractions. Counts are integers. These rules also apply in imported helpers.

Numeric inputs

Physical values accept finite int, float, or Decimal values. Booleans, complex numbers, numeric strings, NaN, and infinity are rejected. Counts reject floats, even integral ones. Each operation defines whether zero or negatives are allowed.

Integers and Decimals stay exact. Floats use Decimal(str(value)), including results of Python arithmetic. Use Decimal for exact decimal calculations.

Input grids

Each layout has a database unit (DBU). For grid spacing g in deck units, length x is x / g steps. Equivalent lengths such as 0.2 um, 200 nm, and 0.0002 mm must convert identically. Areas use squared units; a grid triangle can have area 0.5 g², so length rounding is not an area-rounding policy.

Compilation has no layout grid. It checks types, dimensions, and policy names; the backend checks grid representability during execution. Reference layouts can have different DBUs and need explicit transforms into a shared coordinate context.

Length rounding

Deck(..., grid_rounding="error") rejects off-grid lengths by default. When the input DBU is known, quantize_length() performs local conversion:

Python
from fabcheck import quantize_length

value = quantize_length(0.2005, units="um", dbu_um=0.001, rounding="nearest")
assert value.steps == 201
Policy Integer steps for q = x / g What it does and why
error Reject non-integer q (default) Requires the length to be an exact whole number of grid steps. Use it when moving an off-grid value would change the intended rule.
nearest Nearest integer; ties away from zero Rounds to the closest step, sending exact half-step ties away from zero. Use it when that tie rule is required by the input conversion.
nearest_even Nearest integer; ties to even Rounds to the closest step, sending exact half-step ties to an even integer. Use it when matching nearest-even grid conversion.
floor Greatest integer at or below q Rounds down, including toward a more negative value for negative inputs. Use it when the converted value must not be larger than the authored value.
ceil Least integer at or above q Rounds up, including toward zero for negative fractional inputs. Use it when the converted value must not be smaller than the authored value.

On a 1 nm grid, 0.2005 um fails under error, becomes 0.201 um under nearest / ceil, and 0.200 um under nearest_even / floor. Negative ties: nearest(-1.5)=-2, nearest_even(-2.5)=-2, floor(-1.5)=-2, ceil(-1.5)=-1 steps.

The returned GridValue contains the authored Decimal, integer steps, exact Fraction effective value, units, and policy. DBU must be positive. This helper does not open layouts or check operation-specific limits.

Round once at the operation/input boundary, then check limits: a positive window stride must not round to zero. Do not round angles, density ratios, or continuous measurements just because coordinates use an integer grid.

Comparisons and tolerances

Minimum checks report values below the threshold; maximum checks report values above it. Equality passes. Range selectors default to minimum <= value < maximum; set endpoint options to change this. Zero-distance touching rules are separate.

Use explicit tolerances rather than an undocumented epsilon. Continuous distance and perimeter calculations do not promise exact arithmetic. See the DRC reference for operation-specific behavior.