sf.sfN(value=0)
Thirteen classes, sf.sf4 through sf.sf16. Calling one quantizes value to the nearest code of that width, ties to even, through the error policy.
int | float | Fraction | Decimal | str | numpy scalar | SF value
default:"0"
The number to quantize. Only the integer
0 fits; a string is parsed as an exact decimal; an SF value of a narrower width is widened exactly, a wider one raises SFTypeError (use sf.cast).|value| rounds to 1 or beyond (including ±inf and any nonzero int); underflow when a nonzero value rounds to 0; invalid for NaN.
Attributes
int
The signed integer code, in
[-M, M].int
The sign-magnitude pattern the device stores.
int
0 or 1.
int
The magnitude,
abs(code).Fraction
The exact value,
code / 2^(N-1).type
The class itself.
Operators
A host number next to an SF value is quantized to that value’s type for arithmetic and compared exactly for comparisons. Mixed widths promote to the wider.
sf.dtypes
The tuple (sf.sf4, sf.sf5, ..., sf.sf16).
sf.dtype(spec)
str | int | type | SF value
"sf16", 16, sf.sf16 or an sf16 value.SFTypeError for anything else.
sf.info(dt)
dtype spec
Any of the forms
sf.dtype accepts.SFInfo with the format’s constants:
int
Width.
float
(2^(N-1) - 1) / 2^(N-1), the largest value.float
-max.float
2^-(N-1), the step between neighbouring values.int
2^(N-1) - 1.int
The number of distinct values,
2^N - 1.Fraction
The same, exactly.
sf.from_code(code, dt) and sf.from_bits(bits, dt)
Build a value (or an array, when given an array) from its signed code or from its sign-magnitude pattern. The code is validated against the width; an out-of-range code raises SFTypeError. No events: these never quantize.
sf.FORMATS, sf.SFFormat, sf.MIN_BITS, sf.MAX_BITS
The per-width constant records the library uses internally (FORMATS[16].scale, .max_code, …), and the width range (4, 16). Prefer sf.info in user code.