]> git.lizzy.rs Git - rust.git/commit
Add a `copysign` function to f32 and f64
authorRaph Levien <raph.levien@gmail.com>
Thu, 18 Oct 2018 01:15:00 +0000 (18:15 -0700)
committerRaph Levien <raph.levien@gmail.com>
Thu, 18 Oct 2018 01:15:00 +0000 (18:15 -0700)
commit0e6c3f29be98176c91aa77eb71c04cca18c51115
tree50d22acd767b9d2974c31c48f0e3aa1377b1e0db
parent5ea8eb55cd9f4547b332f43c9f723de30187c223
Add a `copysign` function to f32 and f64

This patch adds a `copysign` function to the float primitive types.
It is an exceptionally useful function for writing efficient numeric
code, as it often avoids branches, is auto-vectorizable, and there
are efficient intrinsics for most platforms.

I think this might work as-is, as the relevant `copysign` intrinsic
is already used internally for the implementation of `signum`. It's
possible that an implementation might be needed in japaric/libm for
portability across all platforms, in which case I'll do that also.

Part of the work towards #55107
src/libstd/f32.rs
src/libstd/f64.rs