1
0
Fork 0
forked from wry/wry

color-management: parametrize bt1886

This commit is contained in:
Julian Orth 2025-09-08 20:37:47 +02:00
parent c37567f1cd
commit ef1727a186
8 changed files with 189 additions and 85 deletions

View file

@ -4,64 +4,71 @@ use std::{
ops::{Add, Div, Mul, Sub},
};
#[derive(Copy, Clone)]
#[repr(transparent)]
pub struct F64(pub f64);
macro_rules! define {
($big:ident, $little:ty) => {
#[derive(Copy, Clone)]
#[repr(transparent)]
pub struct $big(pub $little);
impl Eq for F64 {}
impl Eq for $big {}
impl PartialEq for F64 {
fn eq(&self, other: &Self) -> bool {
self.0.to_bits() == other.0.to_bits()
}
impl PartialEq for $big {
fn eq(&self, other: &Self) -> bool {
self.0.to_bits() == other.0.to_bits()
}
}
impl Hash for $big {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.to_bits().hash(state);
}
}
impl Add<Self> for $big {
type Output = Self;
fn add(self, rhs: $big) -> Self::Output {
Self(self.0 + rhs.0)
}
}
impl Sub<Self> for $big {
type Output = Self;
fn sub(self, rhs: Self) -> Self::Output {
Self(self.0 - rhs.0)
}
}
impl Mul<Self> for $big {
type Output = Self;
fn mul(self, rhs: Self) -> Self::Output {
Self(self.0 * rhs.0)
}
}
impl Div<Self> for $big {
type Output = Self;
fn div(self, rhs: Self) -> Self::Output {
Self(self.0 / rhs.0)
}
}
impl Display for $big {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.0, f)
}
}
impl Debug for $big {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Debug::fmt(&self.0, f)
}
}
};
}
impl Hash for F64 {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.to_bits().hash(state);
}
}
impl Add<F64> for F64 {
type Output = Self;
fn add(self, rhs: F64) -> Self::Output {
Self(self.0 + rhs.0)
}
}
impl Sub<F64> for F64 {
type Output = Self;
fn sub(self, rhs: F64) -> Self::Output {
Self(self.0 - rhs.0)
}
}
impl Mul<F64> for F64 {
type Output = Self;
fn mul(self, rhs: F64) -> Self::Output {
Self(self.0 * rhs.0)
}
}
impl Div<F64> for F64 {
type Output = Self;
fn div(self, rhs: F64) -> Self::Output {
Self(self.0 / rhs.0)
}
}
impl Display for F64 {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.0, f)
}
}
impl Debug for F64 {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Debug::fmt(&self.0, f)
}
}
define!(F64, f64);
define!(F32, f32);