Skip to main content

Module precise

Module precise 

Source
Expand description

Exact powf()-based conversions with C0-continuous constants.

Uses C0-continuous constants (from the moxcms reference implementation) that eliminate the IEC 61966-2-1 piecewise discontinuity. ~6 ULP max error vs f64 reference. See the module docs for the constant comparison table.

Also provides f64, extended-range (unclamped), and custom gamma functions. For faster alternatives, use default. Exact conversion functions using powf().

These functions use the mathematical sRGB transfer function with powf(), providing maximum accuracy at the cost of speed (~6 ULP max vs f64 reference). For faster alternatives, use crate::default which provides rational polynomial approximations (~14 ULP max, ~0.5 ULP avg, perfectly monotonic).

§Constants: C0-continuous (moxcms)

Both this module and crate::default use C0-continuous constants (from the moxcms reference implementation) that eliminate the ~2.3×10⁻⁹ discontinuity present in the IEC 61966-2-1 textbook constants:

ConstantIEC textbookThis crate
Gamma threshold0.040450.039293…
Linear threshold0.00313080.003041…
Offset (a)0.0550.055011…

The adjusted constants solve 12.92 × threshold = (1+a) × threshold^(1/2.4) − a exactly, making the piecewise function mathematically continuous. The difference is unmeasurable at u8 precision and within 1 LSB at u16.

§Extended-range variants

The _extended functions do not clamp to [0, 1], making them suitable for HDR, ICC, and cross-gamut pipelines. See the crate-level docs on clamping for details.

Functions§

gamma_to_linear_f64
Convert gamma-encoded value to linear using a custom gamma exponent (f64).
linear_to_gamma_f64
Convert linear value to gamma-encoded using a custom gamma exponent (f64).
linear_to_srgb
Convert linear light value to sRGB gamma-encoded (f32).
linear_to_srgb_extended
Convert linear light value to sRGB gamma-encoded without clamping (f32).
linear_to_srgb_f64
Convert linear light value to sRGB gamma-encoded (f64).
srgb_to_linear
Convert sRGB gamma-encoded value to linear light (f32).
srgb_to_linear_extended
Convert sRGB gamma-encoded value to linear light without clamping (f32).
srgb_to_linear_f64
Convert sRGB gamma-encoded value to linear light (f64).