[BUG] f128 comparison fails with newest cargo versions (>1.81.0)
The tests fail when compiling with a cargo version higher than 1.81.0
This seems to be independent on the GCC version. I've also tried to use the libf128.a generated from the f128.c file and behave as expected.
The problem is with the binging to rust with x86 intel CPUs, I tried to compile on a new mac and it worked also for the latest 1.83.0 cargo version
use f128::f128; use std::mem;
// Define a struct to hold 128-bit float bits with endianness awareness #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq, Eq)] struct F128Bits { lo: u64, // least significant bits hi: u64, // most significant bits }
// Extract bits from __float128 (assuming __float128 is a C type)
fn float128_to_bits(f: f128) -> F128Bits { unsafe { mem::transmute_copy(&f) } }
fn float128_to_ordered(bits: &mut F128Bits) { let sign = bits.hi >> 63; if sign != 0 { bits.hi = !bits.hi; bits.lo = !bits.lo; } else { bits.hi |= 0x8000000000000000; } }
fn f128_eq(a: f128, b: f128) -> bool { let ba = float128_to_bits(a); let bb = float128_to_bits(b); ba == bb }
fn f128_lt(a: f128, b: f128) -> bool { let mut ba = float128_to_bits(a); let mut bb = float128_to_bits(b); float128_to_ordered(&mut ba); float128_to_ordered(&mut bb); (ba.hi < bb.hi) || (ba.hi == bb.hi && ba.lo < bb.lo) }
fn f128_cmp(a: f128, b: f128) -> i32 { if f128_lt(a, b) { -1 } else if f128_eq(a, b) { 0 } else { 1 } }
this code should address the problem of comparison, I tested it rendering Mandelbrot fratcal and seem correct. After using this code on intel x86 I found out it works