Skip to content

Commit c412751

Browse files
authored
Rollup merge of #124609 - RalfJung:float-precision, r=cuviper
variable-precision float operations can differ depending on optimization levels Follow-up to #121793 and #118217 that accounts for optimizations changing the precision of these functions. Fixes #109118 Fixes #71355
2 parents ad0be15 + ff2ff97 commit c412751

File tree

2 files changed

+174
-116
lines changed

2 files changed

+174
-116
lines changed

library/std/src/f32.rs

+87-58
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,10 @@ impl f32 {
371371
/// It might have a different sequence of rounding operations than `powf`,
372372
/// so the results are not guaranteed to agree.
373373
///
374-
/// # Platform-specific precision
374+
/// # Unspecified precision
375375
///
376-
/// The precision of this function varies by platform and Rust version.
376+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
377+
/// can even differ within the same execution from one invocation to the next.
377378
///
378379
/// # Examples
379380
///
@@ -393,9 +394,10 @@ impl f32 {
393394

394395
/// Raises a number to a floating point power.
395396
///
396-
/// # Platform-specific precision
397+
/// # Unspecified precision
397398
///
398-
/// The precision of this function varies by platform and Rust version.
399+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
400+
/// can even differ within the same execution from one invocation to the next.
399401
///
400402
/// # Examples
401403
///
@@ -444,9 +446,10 @@ impl f32 {
444446

445447
/// Returns `e^(self)`, (the exponential function).
446448
///
447-
/// # Platform-specific precision
449+
/// # Unspecified precision
448450
///
449-
/// The precision of this function varies by platform and Rust version.
451+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
452+
/// can even differ within the same execution from one invocation to the next.
450453
///
451454
/// # Examples
452455
///
@@ -470,9 +473,10 @@ impl f32 {
470473

471474
/// Returns `2^(self)`.
472475
///
473-
/// # Platform-specific precision
476+
/// # Unspecified precision
474477
///
475-
/// The precision of this function varies by platform and Rust version.
478+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
479+
/// can even differ within the same execution from one invocation to the next.
476480
///
477481
/// # Examples
478482
///
@@ -494,9 +498,10 @@ impl f32 {
494498

495499
/// Returns the natural logarithm of the number.
496500
///
497-
/// # Platform-specific precision
501+
/// # Unspecified precision
498502
///
499-
/// The precision of this function varies by platform and Rust version.
503+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
504+
/// can even differ within the same execution from one invocation to the next.
500505
///
501506
/// # Examples
502507
///
@@ -524,9 +529,10 @@ impl f32 {
524529
/// `self.log2()` can produce more accurate results for base 2, and
525530
/// `self.log10()` can produce more accurate results for base 10.
526531
///
527-
/// # Platform-specific precision
532+
/// # Unspecified precision
528533
///
529-
/// The precision of this function varies by platform and Rust version.
534+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
535+
/// can even differ within the same execution from one invocation to the next.
530536
///
531537
/// # Examples
532538
///
@@ -548,9 +554,10 @@ impl f32 {
548554

549555
/// Returns the base 2 logarithm of the number.
550556
///
551-
/// # Platform-specific precision
557+
/// # Unspecified precision
552558
///
553-
/// The precision of this function varies by platform and Rust version.
559+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
560+
/// can even differ within the same execution from one invocation to the next.
554561
///
555562
/// # Examples
556563
///
@@ -572,9 +579,10 @@ impl f32 {
572579

573580
/// Returns the base 10 logarithm of the number.
574581
///
575-
/// # Platform-specific precision
582+
/// # Unspecified precision
576583
///
577-
/// The precision of this function varies by platform and Rust version.
584+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
585+
/// can even differ within the same execution from one invocation to the next.
578586
///
579587
/// # Examples
580588
///
@@ -599,9 +607,10 @@ impl f32 {
599607
/// * If `self <= other`: `0.0`
600608
/// * Else: `self - other`
601609
///
602-
/// # Platform-specific precision
610+
/// # Unspecified precision
603611
///
604-
/// The precision of this function varies by platform and Rust version.
612+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
613+
/// can even differ within the same execution from one invocation to the next.
605614
/// This function currently corresponds to the `fdimf` from libc on Unix
606615
/// and Windows. Note that this might change in the future.
607616
///
@@ -637,9 +646,10 @@ impl f32 {
637646

638647
/// Returns the cube root of a number.
639648
///
640-
/// # Platform-specific precision
649+
/// # Unspecified precision
641650
///
642-
/// The precision of this function varies by platform and Rust version.
651+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
652+
/// can even differ within the same execution from one invocation to the next.
643653
/// This function currently corresponds to the `cbrtf` from libc on Unix
644654
/// and Windows. Note that this might change in the future.
645655
///
@@ -666,9 +676,10 @@ impl f32 {
666676
/// right-angle triangle with other sides having length `x.abs()` and
667677
/// `y.abs()`.
668678
///
669-
/// # Platform-specific precision
679+
/// # Unspecified precision
670680
///
671-
/// The precision of this function varies by platform and Rust version.
681+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
682+
/// can even differ within the same execution from one invocation to the next.
672683
/// This function currently corresponds to the `hypotf` from libc on Unix
673684
/// and Windows. Note that this might change in the future.
674685
///
@@ -693,9 +704,10 @@ impl f32 {
693704

694705
/// Computes the sine of a number (in radians).
695706
///
696-
/// # Platform-specific precision
707+
/// # Unspecified precision
697708
///
698-
/// The precision of this function varies by platform and Rust version.
709+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
710+
/// can even differ within the same execution from one invocation to the next.
699711
///
700712
/// # Examples
701713
///
@@ -716,9 +728,10 @@ impl f32 {
716728

717729
/// Computes the cosine of a number (in radians).
718730
///
719-
/// # Platform-specific precision
731+
/// # Unspecified precision
720732
///
721-
/// The precision of this function varies by platform and Rust version.
733+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
734+
/// can even differ within the same execution from one invocation to the next.
722735
///
723736
/// # Examples
724737
///
@@ -739,9 +752,10 @@ impl f32 {
739752

740753
/// Computes the tangent of a number (in radians).
741754
///
742-
/// # Platform-specific precision
755+
/// # Unspecified precision
743756
///
744-
/// The precision of this function varies by platform and Rust version.
757+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
758+
/// can even differ within the same execution from one invocation to the next.
745759
/// This function currently corresponds to the `tanf` from libc on Unix and
746760
/// Windows. Note that this might change in the future.
747761
///
@@ -765,9 +779,10 @@ impl f32 {
765779
/// the range [-pi/2, pi/2] or NaN if the number is outside the range
766780
/// [-1, 1].
767781
///
768-
/// # Platform-specific precision
782+
/// # Unspecified precision
769783
///
770-
/// The precision of this function varies by platform and Rust version.
784+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
785+
/// can even differ within the same execution from one invocation to the next.
771786
/// This function currently corresponds to the `asinf` from libc on Unix
772787
/// and Windows. Note that this might change in the future.
773788
///
@@ -794,9 +809,10 @@ impl f32 {
794809
/// the range [0, pi] or NaN if the number is outside the range
795810
/// [-1, 1].
796811
///
797-
/// # Platform-specific precision
812+
/// # Unspecified precision
798813
///
799-
/// The precision of this function varies by platform and Rust version.
814+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
815+
/// can even differ within the same execution from one invocation to the next.
800816
/// This function currently corresponds to the `acosf` from libc on Unix
801817
/// and Windows. Note that this might change in the future.
802818
///
@@ -822,9 +838,10 @@ impl f32 {
822838
/// Computes the arctangent of a number. Return value is in radians in the
823839
/// range [-pi/2, pi/2];
824840
///
825-
/// # Platform-specific precision
841+
/// # Unspecified precision
826842
///
827-
/// The precision of this function varies by platform and Rust version.
843+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
844+
/// can even differ within the same execution from one invocation to the next.
828845
/// This function currently corresponds to the `atanf` from libc on Unix
829846
/// and Windows. Note that this might change in the future.
830847
///
@@ -854,9 +871,10 @@ impl f32 {
854871
/// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]`
855872
/// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
856873
///
857-
/// # Platform-specific precision
874+
/// # Unspecified precision
858875
///
859-
/// The precision of this function varies by platform and Rust version.
876+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
877+
/// can even differ within the same execution from one invocation to the next.
860878
/// This function currently corresponds to the `atan2f` from libc on Unix
861879
/// and Windows. Note that this might change in the future.
862880
///
@@ -890,9 +908,10 @@ impl f32 {
890908
/// Simultaneously computes the sine and cosine of the number, `x`. Returns
891909
/// `(sin(x), cos(x))`.
892910
///
893-
/// # Platform-specific precision
911+
/// # Unspecified precision
894912
///
895-
/// The precision of this function varies by platform and Rust version.
913+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
914+
/// can even differ within the same execution from one invocation to the next.
896915
/// This function currently corresponds to the `(f32::sin(x),
897916
/// f32::cos(x))`. Note that this might change in the future.
898917
///
@@ -919,9 +938,10 @@ impl f32 {
919938
/// Returns `e^(self) - 1` in a way that is accurate even if the
920939
/// number is close to zero.
921940
///
922-
/// # Platform-specific precision
941+
/// # Unspecified precision
923942
///
924-
/// The precision of this function varies by platform and Rust version.
943+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
944+
/// can even differ within the same execution from one invocation to the next.
925945
/// This function currently corresponds to the `expm1f` from libc on Unix
926946
/// and Windows. Note that this might change in the future.
927947
///
@@ -947,9 +967,10 @@ impl f32 {
947967
/// Returns `ln(1+n)` (natural logarithm) more accurately than if
948968
/// the operations were performed separately.
949969
///
950-
/// # Platform-specific precision
970+
/// # Unspecified precision
951971
///
952-
/// The precision of this function varies by platform and Rust version.
972+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
973+
/// can even differ within the same execution from one invocation to the next.
953974
/// This function currently corresponds to the `log1pf` from libc on Unix
954975
/// and Windows. Note that this might change in the future.
955976
///
@@ -975,9 +996,10 @@ impl f32 {
975996

976997
/// Hyperbolic sine function.
977998
///
978-
/// # Platform-specific precision
999+
/// # Unspecified precision
9791000
///
980-
/// The precision of this function varies by platform and Rust version.
1001+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
1002+
/// can even differ within the same execution from one invocation to the next.
9811003
/// This function currently corresponds to the `sinhf` from libc on Unix
9821004
/// and Windows. Note that this might change in the future.
9831005
///
@@ -1004,9 +1026,10 @@ impl f32 {
10041026

10051027
/// Hyperbolic cosine function.
10061028
///
1007-
/// # Platform-specific precision
1029+
/// # Unspecified precision
10081030
///
1009-
/// The precision of this function varies by platform and Rust version.
1031+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
1032+
/// can even differ within the same execution from one invocation to the next.
10101033
/// This function currently corresponds to the `coshf` from libc on Unix
10111034
/// and Windows. Note that this might change in the future.
10121035
///
@@ -1033,9 +1056,10 @@ impl f32 {
10331056

10341057
/// Hyperbolic tangent function.
10351058
///
1036-
/// # Platform-specific precision
1059+
/// # Unspecified precision
10371060
///
1038-
/// The precision of this function varies by platform and Rust version.
1061+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
1062+
/// can even differ within the same execution from one invocation to the next.
10391063
/// This function currently corresponds to the `tanhf` from libc on Unix
10401064
/// and Windows. Note that this might change in the future.
10411065
///
@@ -1062,9 +1086,10 @@ impl f32 {
10621086

10631087
/// Inverse hyperbolic sine function.
10641088
///
1065-
/// # Platform-specific precision
1089+
/// # Unspecified precision
10661090
///
1067-
/// The precision of this function varies by platform and Rust version.
1091+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
1092+
/// can even differ within the same execution from one invocation to the next.
10681093
///
10691094
/// # Examples
10701095
///
@@ -1089,9 +1114,10 @@ impl f32 {
10891114

10901115
/// Inverse hyperbolic cosine function.
10911116
///
1092-
/// # Platform-specific precision
1117+
/// # Unspecified precision
10931118
///
1094-
/// The precision of this function varies by platform and Rust version.
1119+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
1120+
/// can even differ within the same execution from one invocation to the next.
10951121
///
10961122
/// # Examples
10971123
///
@@ -1118,9 +1144,10 @@ impl f32 {
11181144

11191145
/// Inverse hyperbolic tangent function.
11201146
///
1121-
/// # Platform-specific precision
1147+
/// # Unspecified precision
11221148
///
1123-
/// The precision of this function varies by platform and Rust version.
1149+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
1150+
/// can even differ within the same execution from one invocation to the next.
11241151
///
11251152
/// # Examples
11261153
///
@@ -1143,9 +1170,10 @@ impl f32 {
11431170

11441171
/// Gamma function.
11451172
///
1146-
/// # Platform-specific precision
1173+
/// # Unspecified precision
11471174
///
1148-
/// The precision of this function varies by platform and Rust version.
1175+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
1176+
/// can even differ within the same execution from one invocation to the next.
11491177
/// This function currently corresponds to the `tgammaf` from libc on Unix
11501178
/// and Windows. Note that this might change in the future.
11511179
///
@@ -1171,9 +1199,10 @@ impl f32 {
11711199
///
11721200
/// The integer part of the tuple indicates the sign of the gamma function.
11731201
///
1174-
/// # Platform-specific precision
1202+
/// # Unspecified precision
11751203
///
1176-
/// The precision of this function varies by platform and Rust version.
1204+
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and
1205+
/// can even differ within the same execution from one invocation to the next.
11771206
/// This function currently corresponds to the `lgamma_r` from libc on Unix
11781207
/// and Windows. Note that this might change in the future.
11791208
///

0 commit comments

Comments
 (0)