Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

f16

IEEE-754 binary16 floating point with 11 bits of significand precision.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →

These examples describe the Development language contract. They are not a claim that every workflow is supported by the current public preview. Declaration excerpts belong inside a function unless a full module is shown.

Format, precision and finite range

f16 uses IEEE-754 binary16: 16 bits (2 bytes), with 11 significand bits including the implicit leading bit. Its greatest finite magnitude is 65504 (decimal approximation except f16’s exact 65504). The exact maximum is (2 - 2^(1-11)) × 2^15; the finite range is negative maximum through positive maximum. The smallest positive normal is 2^-14 (about 6.103515625e-5); the smallest positive subnormal is 2^-24 (about 5.9604644775390625e-8). Values between representable numbers round; this is not continuous real arithmetic. Every integer from -2^11 through 2^11 is exactly representable; larger integers may skip values.

let Maximum: f16 = 65504_f16;
let SmallestNormal: f16 = 6.103515625e-5_f16;
let SmallestSubnormal: f16 = 5.9604644775390625e-8_f16;

Literals and rounding

Use _f16 or a f16 context. An unconstrained floating literal defaults to f64. Decimal rounding is nearest, ties to even. Explicit literal construction rejects a finite literal outside the destination finite range. The spacing from 1 to its next representable larger value is 2^-10; precision is relative to magnitude. Neither decimal 0.1 nor most other decimal fractions has an exact binary representation.

let Half: f16 = 0.5;
let Explicit = 1.25_f16;
let Decimal: f16 = 0.1;
let WithExponent: f16 = 1.25e2;

Special values and arithmetic

f16 includes positive/negative zero, positive/negative infinity and NaN, in addition to finite normal/subnormal values. Subnormals are preserved by default. Operators are unary +/-, +, -, *, / and IEEE comparisons; % is not provided. Floating division by zero produces IEEE infinity or NaN rather than the integer zero-divisor trap. NaN compares unequal to itself; every ordered comparison with NaN is false. +0 equals -0. Comparison sites receive Sn’s floating-comparison warning. Optimization level alone does not enable reassociation, fast-math, implicit FMA contraction or flushing subnormals. NaN payloads are unspecified.

// Inside a function; IEEE comparisons intentionally illustrate W2101.
let One: f16 = 1.0;
let Zero: f16 = 0.0;
let Infinity = One / Zero;
let NotANumber = Zero / Zero;
let IsNaN = NotANumber != NotANumber; // true

Conversions

Implicit float widening follows f16 → f32 → f64. There is no implicit integer/float conversion. Explicit narrowing and integer-to-float conversion round nearest-even; precision loss is allowed, but a finite source whose rounded magnitude exceeds the finite range fails. Float-to-integer conversion truncates toward zero, rejects NaN/infinity, and checks the integer range. as traps on failure; as? returns none. round<I> instead rounds to the nearest integer with ties to even before checking its range.

let Value: f16 = 42.75;
let Truncated: i32 = Value as i32; // 42
let Rounded: i32 = round<i32>(Value); // 43
let Maybe: i32? = Value as? i32;
let Narrow: f16? = Value as? f16;

See all primitive types and literals and user-defined suffixes.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library