Skip to main content

The types

sf.sf4 through sf.sf16 are classes; calling one quantizes your input.
sf.dtypes is the tuple of all thirteen. sf.dtype(spec) resolves a name, a bit count, a class or a value to the class:

What the constructor accepts

Inputs that do not fit

A value at or beyond ±1 overflows; a tiny value underflows to 0; NaN is invalid. Each goes through the error policy:
The overflow threshold is 1 - 2^-N (the point where rounding would reach 1), not 1 itself: 0.99999 already rounds up to the unrepresentable 1.0 in sf16.

From a code or a bit pattern

When you already have the integer the chip holds:
from_code validates the range; a code outside ±M raises SFTypeError.

The largest value

Since 1 is not representable, use sf.info when you need the top of the range: