Float128

#[derive(Clone, Copy)]
#[allow(non_camel_case_types)]
struct f128(std::arch::x86_64::__m128);

macro_rules! impl_float {
    (from $t:ty: $from:ident $to:ident) => {
        impl From<$t> for f128 {
            fn from(v: $t) -> Self {
                unsafe { $from(v) }
            }
        }
        impl From<f128> for $t {
            fn from(v: f128) -> Self {
                unsafe { $to(v) }
            }
        }
    };
    (op $trait:ident $method:ident $func:ident) => {
        impl std::ops::$trait<Self> for f128 {
            type Output = Self;
            fn $method(self, o: Self) -> Self {
                unsafe { $func(self, o) }
            }
        }
    };
}
impl_float!(from f64: __extenddftf2 __trunctfdf2);
impl_float!(from i64: __floatditf __fixtfdi);
impl_float!(from u64: __floatunditf __fixunstfdi);
impl_float!(from i32: __floatsitf __fixtfsi);
impl_float!(from u32: __floatunsitf __fixunstfsi);
impl_float!(op Add add __addtf3);
impl_float!(op Sub sub __subtf3);
impl_float!(op Mul mul __multf3);
impl_float!(op Div div __divtf3);
impl std::ops::Neg for f128 {
    type Output = Self;
    fn neg(self) -> Self::Output {
        unsafe { __negtf3(self) }
    }
}

#[link(name = "stdc++")]
#[allow(improper_ctypes)]
extern "C" {
    fn __extenddftf2(a: f64) -> f128;
    fn __trunctfdf2(a: f128) -> f64;
    fn __addtf3(a: f128, b: f128) -> f128;
    fn __subtf3(a: f128, b: f128) -> f128;
    fn __multf3(a: f128, b: f128) -> f128;
    fn __divtf3(a: f128, b: f128) -> f128;
    fn __negtf3(a: f128) -> f128;
    fn __fixtfsi(a: f128) -> i32;
    fn __fixunstfsi(a: f128) -> u32;
    fn __fixtfdi(a: f128) -> i64;
    fn __fixunstfdi(a: f128) -> u64;
    fn __floatsitf(a: i32) -> f128;
    fn __floatunsitf(a: u32) -> f128;
    fn __floatditf(a: i64) -> f128;
    fn __floatunditf(a: u64) -> f128;
}