sarah-ek / faer-rs

Linear algebra foundation for the Rust programming language
https://faer-rs.github.io
MIT License
1.75k stars 56 forks source link

impl faer_mul_add and faer_abs2_add #128

Closed n3vu0r closed 2 months ago

n3vu0r commented 2 months ago

Adds faer_mul_add and faer_abs2_add to ComplexField.

sarah-ek commented 2 months ago

im not sure i get why we need these?

n3vu0r commented 2 months ago

I'm attempting to reduce rounding errors for functions accepting E: RealField:

fn dummy_example<E: RealField>(x: E) -> E {
    x.faer_mul_add(x, x)
}

Is this already possible somehow?

sarah-ek commented 2 months ago

if you mean outside of faer, you can already do that by using your own trait that has faer::ComplexField as a super-trait

n3vu0r commented 2 months ago

Ok, at the moment I'm using E: RealField + MulAdd<Output = E> where MulAdd is my own trait and it works fine. But I thought this functionality is in general useful and if I understand the traits correctly it's currently not supported out of the box. It would complement the SIMD variants faer_simd_mul_adde for non-SIMD types.

Feel free to close this PR if you don't think it's useful.

sarah-ek commented 2 months ago

yeah, i don't think i want to add these. mul_add needs to go through an indirect function call on x86, which makes it really slow.