core: implement float conversion methods - #159954
Conversation
This comment has been minimized.
This comment has been minimized.
|
The Codegen Cranelift failure was a pre-existing cg_clif bug in f128 as {i8,i16,u8,u16}, unrelated to this PR. |
1706b22 to
95876c9
Compare
This comment has been minimized.
This comment has been minimized.
|
Seems still failed, is it synced yet or any other issues happen? |
Not synced yet. The fix is rust-lang/rustc_codegen_cranelift@29b9205 and the last subtree sync was #159712. |
|
Alright, cc @bjorn3 for awareness |
95876c9 to
3c55beb
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot ready |
…ohnTitor core: implement float conversion methods Implements the accepted ACP rust-lang/libs-team#810, adding float conversion methods on `f16`, `f32`, `f64`, and `f128`: - `cast` converts to the target float type (`self as Flt`, IEEE rounding). - `to_int_saturating` converts to an integer with `as` semantics: saturating, and `NaN` to 0. - `to_int_checked` truncates toward zero and returns `None` on `NaN`, infinity, or out of range. - `to_int_strict` is `to_int_checked().unwrap()`. Per the libs-api meetings on the ACP, `to_float` is named `cast` and `to_int_saturating` maps `NaN` to 0 rather than panicking (which the team noted makes rust-lang/libs-team#831 redundant). The integer-to-float `cast` from the ACP is left out: it shares the `cast` method name on integer types with the integer-to-integer `cast` in rust-lang/libs-team#811 (being unified with the other integer cast methods in rust-lang/libs-team#833), so it needs a decision on how those fit together. Happy to follow up once that settles. Tracking issue: rust-lang#159913 r? libs
…ohnTitor core: implement float conversion methods Implements the accepted ACP rust-lang/libs-team#810, adding float conversion methods on `f16`, `f32`, `f64`, and `f128`: - `cast` converts to the target float type (`self as Flt`, IEEE rounding). - `to_int_saturating` converts to an integer with `as` semantics: saturating, and `NaN` to 0. - `to_int_checked` truncates toward zero and returns `None` on `NaN`, infinity, or out of range. - `to_int_strict` is `to_int_checked().unwrap()`. Per the libs-api meetings on the ACP, `to_float` is named `cast` and `to_int_saturating` maps `NaN` to 0 rather than panicking (which the team noted makes rust-lang/libs-team#831 redundant). The integer-to-float `cast` from the ACP is left out: it shares the `cast` method name on integer types with the integer-to-integer `cast` in rust-lang/libs-team#811 (being unified with the other integer cast methods in rust-lang/libs-team#833), so it needs a decision on how those fit together. Happy to follow up once that settles. Tracking issue: rust-lang#159913 r? libs
…uwer Rollup of 18 pull requests Successful merges: - #151061 (Build rustc and codegen backends with -Zembed-metadata=no) - #157949 (Allow self in const generics) - #158588 (trait_selection: fix assumptions-on-binders diagnostics) - #159954 (core: implement float conversion methods) - #160136 (Add `Default` implementation for `std::sync::Once`) - #160835 (resolver diagnostics: don't swallow labels and point out similar items as a note, not a label) - #161048 (Improve the ABI between the panic runtime and libstd) - #161292 (Add safety comments in alloc::Wtf8) - #161444 (Add some `rustc_type_ir` comments) - #161465 (Remove leftover immediate creation) - #152433 (Use `symlink_dir` to create junctions on Windows instead of trying to use symbolic links in `copy_link_internal`) - #159098 (Add Arc/Rc::strong_count_from_raw) - #159282 (Update documentation for `-Zdump-dep-graph`) - #161401 (Remove fields from TypeKind: Bool, Char, Float and Int) - #161431 (bootstrap: (offload) be stricter about selected compiler and paths) - #161451 (Avoid arming the Windows TLS destructor guard in fibers) - #161463 (Add myself to mailmap) - #161476 (Use bitset for locals_with_use_data) Failed merges: - #161443 (add internal DSL for testing binders)
…ohnTitor core: implement float conversion methods Implements the accepted ACP rust-lang/libs-team#810, adding float conversion methods on `f16`, `f32`, `f64`, and `f128`: - `cast` converts to the target float type (`self as Flt`, IEEE rounding). - `to_int_saturating` converts to an integer with `as` semantics: saturating, and `NaN` to 0. - `to_int_checked` truncates toward zero and returns `None` on `NaN`, infinity, or out of range. - `to_int_strict` is `to_int_checked().unwrap()`. Per the libs-api meetings on the ACP, `to_float` is named `cast` and `to_int_saturating` maps `NaN` to 0 rather than panicking (which the team noted makes rust-lang/libs-team#831 redundant). The integer-to-float `cast` from the ACP is left out: it shares the `cast` method name on integer types with the integer-to-integer `cast` in rust-lang/libs-team#811 (being unified with the other integer cast methods in rust-lang/libs-team#833), so it needs a decision on how those fit together. Happy to follow up once that settles. Tracking issue: rust-lang#159913 r? libs
…ohnTitor core: implement float conversion methods Implements the accepted ACP rust-lang/libs-team#810, adding float conversion methods on `f16`, `f32`, `f64`, and `f128`: - `cast` converts to the target float type (`self as Flt`, IEEE rounding). - `to_int_saturating` converts to an integer with `as` semantics: saturating, and `NaN` to 0. - `to_int_checked` truncates toward zero and returns `None` on `NaN`, infinity, or out of range. - `to_int_strict` is `to_int_checked().unwrap()`. Per the libs-api meetings on the ACP, `to_float` is named `cast` and `to_int_saturating` maps `NaN` to 0 rather than panicking (which the team noted makes rust-lang/libs-team#831 redundant). The integer-to-float `cast` from the ACP is left out: it shares the `cast` method name on integer types with the integer-to-integer `cast` in rust-lang/libs-team#811 (being unified with the other integer cast methods in rust-lang/libs-team#833), so it needs a decision on how those fit together. Happy to follow up once that settles. Tracking issue: rust-lang#159913 r? libs
…ohnTitor core: implement float conversion methods Implements the accepted ACP rust-lang/libs-team#810, adding float conversion methods on `f16`, `f32`, `f64`, and `f128`: - `cast` converts to the target float type (`self as Flt`, IEEE rounding). - `to_int_saturating` converts to an integer with `as` semantics: saturating, and `NaN` to 0. - `to_int_checked` truncates toward zero and returns `None` on `NaN`, infinity, or out of range. - `to_int_strict` is `to_int_checked().unwrap()`. Per the libs-api meetings on the ACP, `to_float` is named `cast` and `to_int_saturating` maps `NaN` to 0 rather than panicking (which the team noted makes rust-lang/libs-team#831 redundant). The integer-to-float `cast` from the ACP is left out: it shares the `cast` method name on integer types with the integer-to-integer `cast` in rust-lang/libs-team#811 (being unified with the other integer cast methods in rust-lang/libs-team#833), so it needs a decision on how those fit together. Happy to follow up once that settles. Tracking issue: rust-lang#159913 r? libs
…uwer Rollup of 19 pull requests Successful merges: - #151061 (Build rustc and codegen backends with -Zembed-metadata=no) - #154992 (Error on projection of dyn noncompat type in old trait solver) - #157949 (Allow self in const generics) - #158588 (trait_selection: fix assumptions-on-binders diagnostics) - #159954 (core: implement float conversion methods) - #160136 (Add `Default` implementation for `std::sync::Once`) - #160835 (resolver diagnostics: don't swallow labels and point out similar items as a note, not a label) - #161048 (Improve the ABI between the panic runtime and libstd) - #161292 (Add safety comments in alloc::Wtf8) - #161444 (Add some `rustc_type_ir` comments) - #161465 (Remove leftover immediate creation) - #159098 (Add Arc/Rc::strong_count_from_raw) - #159282 (Update documentation for `-Zdump-dep-graph`) - #161401 (Remove fields from TypeKind: Bool, Char, Float and Int) - #161431 (bootstrap: (offload) be stricter about selected compiler and paths) - #161451 (Avoid arming the Windows TLS destructor guard in fibers) - #161463 (Add myself to mailmap) - #161476 (Use bitset for locals_with_use_data) - #161483 (Warn about running ui-fulldeps tests in stage 1) Failed merges: - #161443 (add internal DSL for testing binders)
Rollup merge of #159954 - valentynkit:float-conversions, r=JohnTitor core: implement float conversion methods Implements the accepted ACP rust-lang/libs-team#810, adding float conversion methods on `f16`, `f32`, `f64`, and `f128`: - `cast` converts to the target float type (`self as Flt`, IEEE rounding). - `to_int_saturating` converts to an integer with `as` semantics: saturating, and `NaN` to 0. - `to_int_checked` truncates toward zero and returns `None` on `NaN`, infinity, or out of range. - `to_int_strict` is `to_int_checked().unwrap()`. Per the libs-api meetings on the ACP, `to_float` is named `cast` and `to_int_saturating` maps `NaN` to 0 rather than panicking (which the team noted makes rust-lang/libs-team#831 redundant). The integer-to-float `cast` from the ACP is left out: it shares the `cast` method name on integer types with the integer-to-integer `cast` in rust-lang/libs-team#811 (being unified with the other integer cast methods in rust-lang/libs-team#833), so it needs a decision on how those fit together. Happy to follow up once that settles. Tracking issue: #159913 r? libs
Implements the accepted ACP rust-lang/libs-team#810, adding float conversion methods on
f16,f32,f64, andf128:castconverts to the target float type (self as Flt, IEEE rounding).to_int_saturatingconverts to an integer withassemantics: saturating, andNaNto 0.to_int_checkedtruncates toward zero and returnsNoneonNaN, infinity, or out of range.to_int_strictisto_int_checked().unwrap().Per the libs-api meetings on the ACP,
to_floatis namedcastandto_int_saturatingmapsNaNto 0 rather than panicking (which the team noted makes rust-lang/libs-team#831 redundant).The integer-to-float
castfrom the ACP is left out: it shares thecastmethod name on integer types with the integer-to-integercastin rust-lang/libs-team#811 (being unified with the other integer cast methods in rust-lang/libs-team#833), so it needs a decision on how those fit together. Happy to follow up once that settles.Tracking issue: #159913
r? libs