]> git.lizzy.rs Git - rust.git/commit
Auto merge of #45205 - rkruppe:saturating-casts, r=eddyb
authorbors <bors@rust-lang.org>
Wed, 8 Nov 2017 17:27:56 +0000 (17:27 +0000)
committerbors <bors@rust-lang.org>
Wed, 8 Nov 2017 17:27:56 +0000 (17:27 +0000)
commit7ca430df713ad1697a9d27eb4ae0f49c8563eed4
tree1c6453c32fe136f095038e6cfc1a3396a778ec3c
parent6e2977499bc9075fcc50f03e155303db53583f90
parentef0b99930e52ee90f9452542dd14f148bbbe13af
Auto merge of #45205 - rkruppe:saturating-casts, r=eddyb

Saturating casts between integers and floats

Introduces a new flag, `-Z saturating-float-casts`, which makes code generation for int->float and float->int casts safe (`undef`-free), implementing [the saturating semantics laid out by](https://github.com/rust-lang/rust/issues/10184#issuecomment-299229143) @jorendorff for float->int casts and overflowing to infinity for `u128::MAX` -> `f32`.
Constant evaluation in trans was changed to behave like HIR const eval already did, i.e., saturate for u128->f32 and report an error for problematic float->int casts.

Many thanks to @eddyb, whose APFloat port simplified many parts of this patch, and made HIR constant evaluation recognize dangerous float casts as mentioned above.
Also thanks to @ActuallyaDeviloper whose branchless implementation served as inspiration for this implementation.

cc #10184 #41799
fixes #45134
src/librustc/session/config.rs