Skip to content

Commit dfe66cf

Browse files
Rollup merge of #129683 - RalfJung:copysign, r=thomcc
copysign with sign being a NaN can have non-portable results Follow-up to #129559. Cc ```@tgross35``` ```@beetrees``` There's no portable variant we can recommend instead here, is there? Something with a semantics like "if `sign` is a NaN, then return `self` unaltered, otherwise return `self` with the sign changed to that of `sign`"?
2 parents 9ddb45e + 0589dc7 commit dfe66cf

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

library/std/src/f128.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,14 @@ impl f128 {
250250
///
251251
/// Equal to `self` if the sign of `self` and `sign` are the same, otherwise equal to `-self`.
252252
/// If `self` is a NaN, then a NaN with the same payload as `self` and the sign bit of `sign` is
253-
/// returned. Note, however, that conserving the sign bit on NaN across arithmetical operations
254-
/// is not generally guaranteed. See [specification of NaN bit
255-
/// patterns](primitive@f32#nan-bit-patterns) for more info.
253+
/// returned.
254+
///
255+
/// If `sign` is a NaN, then this operation will still carry over its sign into the result. Note
256+
/// that IEEE 754 doesn't assign any meaning to the sign bit in case of a NaN, and as Rust
257+
/// doesn't guarantee that the bit pattern of NaNs are conserved over arithmetic operations, the
258+
/// result of `copysign` with `sign` being a NaN might produce an unexpected or non-portable
259+
/// result. See the [specification of NaN bit patterns](primitive@f32#nan-bit-patterns) for more
260+
/// info.
256261
///
257262
/// # Examples
258263
///

library/std/src/f16.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,14 @@ impl f16 {
249249
///
250250
/// Equal to `self` if the sign of `self` and `sign` are the same, otherwise equal to `-self`.
251251
/// If `self` is a NaN, then a NaN with the same payload as `self` and the sign bit of `sign` is
252-
/// returned. Note, however, that conserving the sign bit on NaN across arithmetical operations
253-
/// is not generally guaranteed. See [specification of NaN bit
254-
/// patterns](primitive@f32#nan-bit-patterns) for more info.
252+
/// returned.
253+
///
254+
/// If `sign` is a NaN, then this operation will still carry over its sign into the result. Note
255+
/// that IEEE 754 doesn't assign any meaning to the sign bit in case of a NaN, and as Rust
256+
/// doesn't guarantee that the bit pattern of NaNs are conserved over arithmetic operations, the
257+
/// result of `copysign` with `sign` being a NaN might produce an unexpected or non-portable
258+
/// result. See the [specification of NaN bit patterns](primitive@f32#nan-bit-patterns) for more
259+
/// info.
255260
///
256261
/// # Examples
257262
///

library/std/src/f32.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,14 @@ impl f32 {
228228
///
229229
/// Equal to `self` if the sign of `self` and `sign` are the same, otherwise equal to `-self`.
230230
/// If `self` is a NaN, then a NaN with the same payload as `self` and the sign bit of `sign` is
231-
/// returned. Note, however, that conserving the sign bit on NaN across arithmetical operations
232-
/// is not generally guaranteed. See [specification of NaN bit
233-
/// patterns](primitive@f32#nan-bit-patterns) for more info.
231+
/// returned.
232+
///
233+
/// If `sign` is a NaN, then this operation will still carry over its sign into the result. Note
234+
/// that IEEE 754 doesn't assign any meaning to the sign bit in case of a NaN, and as Rust
235+
/// doesn't guarantee that the bit pattern of NaNs are conserved over arithmetic operations, the
236+
/// result of `copysign` with `sign` being a NaN might produce an unexpected or non-portable
237+
/// result. See the [specification of NaN bit patterns](primitive@f32#nan-bit-patterns) for more
238+
/// info.
234239
///
235240
/// # Examples
236241
///

library/std/src/f64.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,14 @@ impl f64 {
228228
///
229229
/// Equal to `self` if the sign of `self` and `sign` are the same, otherwise equal to `-self`.
230230
/// If `self` is a NaN, then a NaN with the same payload as `self` and the sign bit of `sign` is
231-
/// returned. Note, however, that conserving the sign bit on NaN across arithmetical operations
232-
/// is not generally guaranteed. See [specification of NaN bit
233-
/// patterns](primitive@f32#nan-bit-patterns) for more info.
231+
/// returned.
232+
///
233+
/// If `sign` is a NaN, then this operation will still carry over its sign into the result. Note
234+
/// that IEEE 754 doesn't assign any meaning to the sign bit in case of a NaN, and as Rust
235+
/// doesn't guarantee that the bit pattern of NaNs are conserved over arithmetic operations, the
236+
/// result of `copysign` with `sign` being a NaN might produce an unexpected or non-portable
237+
/// result. See the [specification of NaN bit patterns](primitive@f32#nan-bit-patterns) for more
238+
/// info.
234239
///
235240
/// # Examples
236241
///

0 commit comments

Comments
 (0)