DitherFloatConversion

Trait DitherFloatConversion 

Source
pub trait DitherFloatConversion<Dest>: Sized {
    // Required methods
    fn compute_target_ulp(self) -> Self;
    fn cast_to_dest(self) -> Dest;
}
Expand description

Trait for dithered float-to-float precision conversions.

This trait enables dithering when converting between floating-point types of different precisions to reduce quantization artifacts like banding in smooth gradients.

§Example

use dithereens::dither_float;

let value: f32 = 1.234567;
let dithered: f16 = dither_float(value, 0, 42);

Required Methods§

Source

fn compute_target_ulp(self) -> Self

Compute the ULP (Unit in the Last Place) for the destination type at this value’s magnitude.

The ULP represents the quantization step size – the spacing between representable values at the current magnitude.

Source

fn cast_to_dest(self) -> Dest

Cast to the destination type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl DitherFloatConversion<f32> for f64

Implementation for f64 to f32 conversion.

f32 has 23 mantissa bits vs f64’s 52 bits, losing 29 bits of precision.

Implementors§