Skip to content

use libm for acosh and asinh for f16, f32, and f64#154051

Open
malezjaa wants to merge 1 commit intorust-lang:mainfrom
malezjaa:approximations-acosh-and-asinh
Open

use libm for acosh and asinh for f16, f32, and f64#154051
malezjaa wants to merge 1 commit intorust-lang:mainfrom
malezjaa:approximations-acosh-and-asinh

Conversation

@malezjaa
Copy link
Copy Markdown
Contributor

@malezjaa malezjaa commented Mar 18, 2026

Fixes #153878

Uses libm for acosh and asinh for f16, f32, and f64.
I didn't change impl for f128 as i couldn't find existing function for these in libm

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 18, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 18, 2026

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, joboet

@reddevilmidzy
Copy link
Copy Markdown
Member

Hello @malezjaa,
Next time you contribute, please check if someone has been assigned to the issue before contributing.

@malezjaa
Copy link
Copy Markdown
Contributor Author

I'm really sorry about that. I should've checked If anyone was already assigned to this issue. I'll do that from now on.

@rust-bors

This comment has been minimized.

@malezjaa malezjaa force-pushed the approximations-acosh-and-asinh branch from 4a67c1e to 90a7256 Compare March 21, 2026 09:01
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 21, 2026

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.

@tgross35
Copy link
Copy Markdown
Contributor

Happy to review this or alternatives, unless you have a preference @joboet

r? tgross35

@rustbot rustbot assigned tgross35 and unassigned joboet Mar 26, 2026
@tgross35
Copy link
Copy Markdown
Contributor

this fixes acosh and asinh for large float values using the approximation from libm

Can we just call libm via the cmath moule instead, rather than having the same logic here? Like we do for acos and similar.

Can you also clarify what approximations you are referencing? This isn't what is in https://github.com/rust-lang/compiler-builtins/blob/644346f0541f74fc425070f8e0712f2dac898e11/libm/src/math/acosh.rs.

@malezjaa malezjaa changed the title return approximations for large float values in acosh and asinh use libm for acosh and asinh for f16, f32, and f64 Mar 28, 2026
@malezjaa malezjaa marked this pull request as draft March 28, 2026 16:41
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 28, 2026
@malezjaa malezjaa force-pushed the approximations-acosh-and-asinh branch from 3a210bb to 538e681 Compare March 28, 2026 17:02
@malezjaa
Copy link
Copy Markdown
Contributor Author

Oh yeah that makes sense. I'll update the PR title and description to show that we're now using libm for these functions.
For f128 I kept the existing approximation since I couldn't find the f128 version in libm

@malezjaa malezjaa marked this pull request as ready for review March 28, 2026 17:05
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 28, 2026
@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-miri failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
tests/pass/shims/x86/rounding-error.rs ... ok
tests/pass/shims/x86/intrinsics-x86-gfni.rs ... ok

FAILED TEST: tests/pass/float.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-KeuWOb" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/miri" "--error-format=json" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/pass" "tests/pass/float.rs" "--edition" "2021"

error: test got exit status: 1, but expected 0
 = note: compilation failed, but was expected to succeed

error: no output was expected
Execute `./miri test --bless` to update `tests/pass/float.stderr` to the actual output
+++ <stderr output>
error: unsupported operation: can't call foreign function `asinhf` on OS `linux`
##[error]  --> /checkout/library/std/src/num/f16.rs:835:9
   |
LL |         cmath::asinhf(self as f32) as f16
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^ unsupported operation occurred here
   |
   = help: this means the program tried to do something Miri does not support; it does not indicate a bug in the program
   = note: stack backtrace:
           0: std::f16::<impl f16>::asinh
               at /checkout/library/std/src/num/f16.rs:835:9: 835:35
           1: libm
               at tests/pass/float.rs:1212:23: 1212:37
           2: main
               at tests/pass/float.rs:73:5: 73:11
---



full stderr:
error: unsupported operation: can't call foreign function `asinhf` on OS `linux`
##[error]  --> /checkout/library/std/src/num/f16.rs:835:9
   |
LL |         cmath::asinhf(self as f32) as f16
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^ unsupported operation occurred here
   |
   = help: this means the program tried to do something Miri does not support; it does not indicate a bug in the program
   = note: stack backtrace:
           0: std::f16::<impl f16>::asinh
               at /checkout/library/std/src/num/f16.rs:835:9: 835:35
           1: libm
               at tests/pass/float.rs:1212:23: 1212:37
           2: main
               at tests/pass/float.rs:73:5: 73:11
---
Location:
   /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ui_test-0.30.3/src/lib.rs:365

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   1: <color_eyre[fa244e63cbefe556]::config::EyreHook>::into_eyre_hook::{closure#0}<unknown>
      at <unknown source file>:<unknown line>
   2: <eyre[f23cdec6a3caa159]::Report>::from_adhoc::<&str><unknown>
      at <unknown source file>:<unknown line>
   3: ui_test[8296c1797d7c4a74]::run_tests_generic::<ui_test[8296c1797d7c4a74]::default_file_filter, ui[cebf951dc1980741]::run_tests::{closure#1}, alloc[ea442e7f9db0b120]::boxed::Box<dyn ui_test[8296c1797d7c4a74]::status_emitter::StatusEmitter>><unknown>
      at <unknown source file>:<unknown line>
   4: ui[cebf951dc1980741]::ui<unknown>
      at <unknown source file>:<unknown line>
   5: ui[cebf951dc1980741]::main<unknown>
      at <unknown source file>:<unknown line>
   6: std[5e094cc60be0206c]::sys::backtrace::__rust_begin_short_backtrace::<fn() -> core[c27f5559c9d72157]::result::Result<(), eyre[f23cdec6a3caa159]::Report>, core[c27f5559c9d72157]::result::Result<(), eyre[f23cdec6a3caa159]::Report>><unknown>
      at <unknown source file>:<unknown line>
   7: std[5e094cc60be0206c]::rt::lang_start::<core[c27f5559c9d72157]::result::Result<(), eyre[f23cdec6a3caa159]::Report>>::{closure#0}<unknown>
      at <unknown source file>:<unknown line>
   8: std[5e094cc60be0206c]::rt::lang_start_internal<unknown>
      at <unknown source file>:<unknown line>
   9: main<unknown>
      at <unknown source file>:<unknown line>
  10: __libc_start_main<unknown>
      at <unknown source file>:<unknown line>
  11: _start<unknown>
      at <unknown source file>:<unknown line>

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.
error: test failed, to rerun pass `--test ui`

Caused by:
  process didn't exit successfully: `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/ui-626f07652299b838` (exit status: 1)
Bootstrap failed while executing `test --stage 2 src/tools/miri src/tools/miri/cargo-miri`
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo test -Zwarnings --target x86_64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout --locked --color=always --profile=release --manifest-path /checkout/src/tools/miri/Cargo.toml -- [workdir=/checkout]` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:191:21
Executed at: src/bootstrap/src/core/build_steps/test.rs:739:19

--- BACKTRACE vvv
   0: <bootstrap::utils::exec::DeferredCommand>::finish_process
             at /checkout/src/bootstrap/src/utils/exec.rs:939:17
   1: <bootstrap::utils::exec::DeferredCommand>::wait_for_output::<&bootstrap::utils::exec::ExecutionContext>
             at /checkout/src/bootstrap/src/utils/exec.rs:831:21
   2: <bootstrap::utils::exec::ExecutionContext>::run
             at /checkout/src/bootstrap/src/utils/exec.rs:741:45
   3: <bootstrap::utils::exec::BootstrapCommand>::run::<&bootstrap::core::builder::Builder>
             at /checkout/src/bootstrap/src/utils/exec.rs:339:27
   4: <bootstrap::core::build_steps::test::Miri as bootstrap::core::builder::Step>::run
             at /checkout/src/bootstrap/src/core/build_steps/test.rs:739:19
   5: <bootstrap::core::builder::Builder>::ensure::<bootstrap::core::build_steps::test::Miri>
             at /checkout/src/bootstrap/src/core/builder/mod.rs:1579:36
   6: <bootstrap::core::build_steps::test::Miri as bootstrap::core::builder::Step>::make_run
             at /checkout/src/bootstrap/src/core/build_steps/test.rs:665:21
   7: <bootstrap::core::builder::StepDescription>::maybe_run
             at /checkout/src/bootstrap/src/core/builder/mod.rs:476:13
   8: bootstrap::core::builder::cli_paths::match_paths_to_steps_and_run
             at /checkout/src/bootstrap/src/core/builder/cli_paths.rs:232:18
   9: <bootstrap::core::builder::Builder>::run_step_descriptions
             at /checkout/src/bootstrap/src/core/builder/mod.rs:1122:9
  10: <bootstrap::core::builder::Builder>::execute_cli
             at /checkout/src/bootstrap/src/core/builder/mod.rs:1101:14
  11: <bootstrap::Build>::build
             at /checkout/src/bootstrap/src/lib.rs:799:25
  12: bootstrap::main
             at /checkout/src/bootstrap/src/bin/main.rs:130:11
  13: <fn() as core::ops::function::FnOnce<()>>::call_once
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/core/src/ops/function.rs:250:5
  14: std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/sys/backtrace.rs:166:18
  15: std::rt::lang_start::<()>::{closure#0}
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/rt.rs:206:18
  16: <&dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync as core::ops::function::FnOnce<()>>::call_once
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/core/src/ops/function.rs:287:21
  17: std::panicking::catch_unwind::do_call::<&dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync, i32>
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/panicking.rs:581:40
  18: std::panicking::catch_unwind::<i32, &dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync>
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/panicking.rs:544:19
  19: std::panic::catch_unwind::<&dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync, i32>
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/panic.rs:359:14
  20: std::rt::lang_start_internal::{closure#0}
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/rt.rs:175:24
  21: std::panicking::catch_unwind::do_call::<std::rt::lang_start_internal::{closure#0}, isize>
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/panicking.rs:581:40
---
  28: __libc_start_main
  29: _start


Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:37:57
  local time: Sat Mar 28 17:44:21 UTC 2026
  network time: Sat, 28 Mar 2026 17:44:21 GMT
##[error]Process completed with exit code 1.
##[group]Run echo "disk usage:"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

asinh and acosh return inf for very large input values

6 participants