Skip to main content

f16

Struct f16 

Source
#[repr(transparent)]
pub struct f16(pub u16);
Expand description

A half-precision (16-bit) floating point number.

This type represents IEEE 754 half-precision binary floating-point format. It provides conversion methods to and from f32, and the underlying u16 representation is publicly accessible for direct bit manipulation.

§Examples

use simsimd::f16;

// Create from f32
let half = f16::from_f32(3.14);

// Convert back to f32
let float = half.to_f32();

// Direct access to bits
let bits = half.0;

Tuple Fields§

§0: u16

Implementations§

Source§

impl f16

Source

pub const ZERO: Self

Positive zero.

Source

pub const ONE: Self

Positive one.

Source

pub const NEG_ONE: Self

Negative one.

Source

pub fn from_f32(value: f32) -> Self

Converts an f32 to f16 representation.

§Examples
use simsimd::f16;
let half = f16::from_f32(3.14159);
Source

pub fn to_f32(self) -> f32

Converts the f16 to an f32.

§Examples
use simsimd::f16;
let half = f16::from_f32(3.14159);
let float = half.to_f32();
Source

pub fn is_nan(self) -> bool

Returns true if this value is NaN.

Source

pub fn is_infinite(self) -> bool

Returns true if this value is positive or negative infinity.

Source

pub fn is_finite(self) -> bool

Returns true if this number is neither infinite nor NaN.

Source

pub fn abs(self) -> Self

Returns the absolute value of self.

Trait Implementations§

Source§

impl Add for f16

Source§

type Output = f16

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for f16

Source§

fn clone(&self) -> f16

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ComplexProducts for f16

Source§

fn dot(a: &[Self], b: &[Self]) -> Option<ComplexProduct>

Computes the dot product between two complex number vectors.
Source§

fn vdot(a: &[Self], b: &[Self]) -> Option<ComplexProduct>

Computes the Hermitian dot product (conjugate dot product) between two complex number vectors.
Source§

impl Debug for f16

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div for f16

Source§

type Output = f16

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl Mul for f16

Source§

type Output = f16

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl Neg for f16

Source§

type Output = f16

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for f16

Source§

fn eq(&self, other: &f16) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for f16

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl ProbabilitySimilarity for f16

Source§

fn jensenshannon(a: &[Self], b: &[Self]) -> Option<Distance>

Computes the Jensen-Shannon divergence between two probability distributions. The Jensen-Shannon divergence is a method of measuring the similarity between two probability distributions. It is based on the Kullback-Leibler divergence, but is symmetric and always has a finite value.
Source§

fn kullbackleibler(a: &[Self], b: &[Self]) -> Option<Distance>

Computes the Kullback-Leibler divergence between two probability distributions. The Kullback-Leibler divergence is a measure of how one probability distribution diverges from a second, expected probability distribution.
Source§

impl SpatialSimilarity for f16

Source§

fn cos(a: &[Self], b: &[Self]) -> Option<Distance>

Computes the cosine distance between two slices. The cosine distance is 1 minus the cosine similarity between two non-zero vectors of an dot product space that measures the cosine of the angle between them.
Source§

fn dot(a: &[Self], b: &[Self]) -> Option<Distance>

Computes the inner product (also known as dot product) between two slices. The dot product is the sum of the products of the corresponding entries of the two sequences of numbers.
Source§

fn l2sq(a: &[Self], b: &[Self]) -> Option<Distance>

Computes the squared Euclidean distance between two slices. The squared Euclidean distance is the sum of the squared differences between corresponding elements of the two slices.
Source§

fn l2(a: &[Self], b: &[Self]) -> Option<Distance>

Computes the Euclidean distance between two slices. The Euclidean distance is the square root of elements of the two slices.
Source§

fn sqeuclidean(a: &[Self], b: &[Self]) -> Option<Distance>

Computes the squared Euclidean distance between two slices. The squared Euclidean distance is the sum of the squared differences between corresponding elements of the two slices.
Source§

fn euclidean(a: &[Self], b: &[Self]) -> Option<Distance>

Computes the Euclidean distance between two slices. The Euclidean distance is the square root of the sum of the squared differences between corresponding elements of the two slices.
Source§

fn inner(a: &[Self], b: &[Self]) -> Option<Distance>

Computes the squared Euclidean distance between two slices. The squared Euclidean distance is the sum of the squared differences between corresponding elements of the two slices.
Source§

fn cosine(a: &[Self], b: &[Self]) -> Option<Distance>

Computes the cosine distance between two slices. The cosine distance is 1 minus the cosine similarity between two non-zero vectors of an dot product space that measures the cosine of the angle between them.
Source§

impl Sub for f16

Source§

type Output = f16

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl Copy for f16

Source§

impl Eq for f16

Source§

impl StructuralPartialEq for f16

Auto Trait Implementations§

§

impl Freeze for f16

§

impl RefUnwindSafe for f16

§

impl Send for f16

§

impl Sync for f16

§

impl Unpin for f16

§

impl UnsafeUnpin for f16

§

impl UnwindSafe for f16

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.