-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement f{16,32,64,128}::{erf,erfc}
(#![feature(float_erf)]
)
#136324
Conversation
f{16,32,64,128}::{erf,erfc}
(float_erf
)f{16,32,64,128}::{erf,erfc}
(#![feature(float_erf)]
)
r? tgross35 |
Could you gate behind
Afaik there aren't any "convenient" values, it's probably fine to pick some random numbers. For reference: > erf.(big.([-1.0, -0.5, 0.0, 0.5, 1.0]))
5-element Vector{BigFloat}:
-0.8427007929497148693412206350826092592960669979663029084599378978347172540960087
-0.5204998778130465376827466538919645287364515757579637000588057256471935217168533
0.0
0.5204998778130465376827466538919645287364515757579637000588057256471935217168533
0.8427007929497148693412206350826092592960669979663029084599378978347172540960087
If you don't mind waiting a week or so (updating builtins is temporarily stuck), I think it would be easiest to expose them from libm before this merges. Otherwise the doctests will need to be gated to
They mention these functions in their docs https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/erf-erff-erfl-erfc-erfcf-erfcl?view=msvc-170 but the docs also mention In any case we can run a try job for these two targets. |
In 32-bit x86 MSVC, some UCRT functions are header-only but the DLL does indeed export |
Done.
Added those as well. I think it's fine to not do it in a separate PR, since it's just a comment, not to mention
Is one number enough or should I add more? Also, out of curiosity, what language was that example in?
I will file a PR in the compiler-builtins repo. UPD: Done. rust-lang/compiler-builtins#753 BTW, under what conditions will the doctests fail if the functions are not exposed in compiler-builtins? I'm not entirely familiar with how these things work. |
Also add ```rust // #[unstable(feature = "float_gamma", issue = "99842")] ``` to `gamma`-function-related methods on `f16` & `f128`, as per rust-lang#136324 (comment)
Thanks!
🤷 up to you, it's more of a demonstration than a test. I guess if you are looking for ideas you could use something based on the emperical rule: /// The error function relates what percent of a normal distribution lies
/// within `x` standard deviations (scaled by `1/sqrt(2)`).
fn within_standard_deviations(x: f32) -> f32 {
(x as f32 * std::f32::consts::FRAC_1_SQRT_2).erf() * 100.0
}
// 68% of a normal distribution is within one standard deviation
assert!((within_standard_deviations(1.0) - 68.269).abs() < 0.01);
// 95% of a normal distribution is within two standard deviations
assert!((within_standard_deviations(2.0) - 95.450).abs() < 0.01);
// 99.7% of a normal distribution is within three standard deviations
assert!((within_standard_deviations(3.0) - 99.730).abs() < 0.01);
Julia, with
Left a comment there but that change LGTM, But as noted there, @rustbot blocked
Most everything uses the system's C |
library/std/src/f16.rs
Outdated
/// # Unspecified precision | ||
/// | ||
/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and | ||
/// can even differ within the same execution from one invocation to the next. | ||
/// This function currently corresponds to the `erff` from libc on Unix | ||
/// and Windows. Note that this might change in the future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're updating the docs, mind copying this section from the f128
or f16
files? The f32
/f64
ones just have really random wrapping.
Also add ```rust // #[unstable(feature = "float_gamma", issue = "99842")] ``` to `gamma`-function-related methods on `f16` & `f128`, as per rust-lang#136324 (comment)
Also add ```rust // #[unstable(feature = "float_gamma", issue = "99842")] ``` to `gamma`-function-related methods on `f16` & `f128`, as per rust-lang#136324 (comment)
@rustbot ready |
@@ -742,6 +742,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> { | |||
| "log1pf" | |||
| "expm1f" | |||
| "tgammaf" | |||
| "erff" | |||
| "erfcf" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add calls to this function in src/tools/miri/tests/pass/float.rs
.
Miri changes LGTM. :) But let's ensure they pass CI. |
@bors try |
Implement `f{16,32,64,128}::{erf,erfc}` (`#![feature(float_erf)]`) Tracking issue: rust-lang#136321 try-job: x86_64-gnu-aux
☀️ Try build successful - checks-actions |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (f77247a): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (secondary -2.1%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (secondary 9.2%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 790.529s -> 788.977s (-0.20%) |
… r=tgross35 tests: Also gate `f16::erfc()` doctest with `reliable_f16_math` cfg In rust-lang#136324 the doctest for `f16::erf()` was gated with `reliable_f16_math`. Add the same gate on `f16::erfc()` to avoid: rust_out.71e2e529d20ea47d-cgu.0:\ (.text._ZN8rust_out4main43_doctest_main_library_std_src_f16_rs_1321_017h485f3ffe6bf2a981E+0x38): \ undefined reference to `__gnu_h2f_ieee' on MIPS (and maybe other architectures). r? tgross35
… r=tgross35 tests: Also gate `f16::erfc()` doctest with `reliable_f16_math` cfg In rust-lang#136324 the doctest for `f16::erf()` was gated with `reliable_f16_math`. Add the same gate on `f16::erfc()` to avoid: rust_out.71e2e529d20ea47d-cgu.0:\ (.text._ZN8rust_out4main43_doctest_main_library_std_src_f16_rs_1321_017h485f3ffe6bf2a981E+0x38): \ undefined reference to `__gnu_h2f_ieee' on MIPS (and maybe other architectures). r? tgross35
… r=tgross35 tests: Also gate `f16::erfc()` doctest with `reliable_f16_math` cfg In rust-lang#136324 the doctest for `f16::erf()` was gated with `reliable_f16_math`. Add the same gate on `f16::erfc()` to avoid: rust_out.71e2e529d20ea47d-cgu.0:\ (.text._ZN8rust_out4main43_doctest_main_library_std_src_f16_rs_1321_017h485f3ffe6bf2a981E+0x38): \ undefined reference to `__gnu_h2f_ieee' on MIPS (and maybe other architectures). r? tgross35
… r=tgross35 tests: Also gate `f16::erfc()` doctest with `reliable_f16_math` cfg In rust-lang#136324 the doctest for `f16::erf()` was gated with `reliable_f16_math`. Add the same gate on `f16::erfc()` to avoid: rust_out.71e2e529d20ea47d-cgu.0:\ (.text._ZN8rust_out4main43_doctest_main_library_std_src_f16_rs_1321_017h485f3ffe6bf2a981E+0x38): \ undefined reference to `__gnu_h2f_ieee' on MIPS (and maybe other architectures). r? tgross35
Rollup merge of rust-lang#137167 - martn3:reliable_f16_math-f16-erfc, r=tgross35 tests: Also gate `f16::erfc()` doctest with `reliable_f16_math` cfg In rust-lang#136324 the doctest for `f16::erf()` was gated with `reliable_f16_math`. Add the same gate on `f16::erfc()` to avoid: rust_out.71e2e529d20ea47d-cgu.0:\ (.text._ZN8rust_out4main43_doctest_main_library_std_src_f16_rs_1321_017h485f3ffe6bf2a981E+0x38): \ undefined reference to `__gnu_h2f_ieee' on MIPS (and maybe other architectures). r? tgross35
Also add ```rust // #[unstable(feature = "float_gamma", issue = "99842")] ``` to `gamma`-function-related methods on `f16` & `f128`, as per rust-lang#136324 (comment)
Also add ```rust // #[unstable(feature = "float_gamma", issue = "99842")] ``` to `gamma`-function-related methods on `f16` & `f128`, as per rust-lang#136324 (comment)
Also add ```rust // #[unstable(feature = "float_gamma", issue = "99842")] ``` to `gamma`-function-related methods on `f16` & `f128`, as per rust-lang#136324 (comment)
Also add ```rust // #[unstable(feature = "float_gamma", issue = "99842")] ``` to `gamma`-function-related methods on `f16` & `f128`, as per rust-lang#136324 (comment)
Tracking issue: #136321
try-job: x86_64-gnu-aux