Skip to content
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

Add constants for f16 and f128 #123850

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tspiteri
Copy link
Contributor

  • Commit 1 adds associated constants for f16, excluding NaN and infinities as these are implemented using arithmetic for f32 and f64.
  • Commit 2 adds associated constants for f128, excluding NaN and infinities.
  • Commit 3 adds constants in std::f16::consts.
  • Commit 4 adds constants in std::f128::consts.

@rustbot
Copy link
Collaborator

rustbot commented Apr 12, 2024

r? @Amanieu

rustbot has assigned @Amanieu.
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

@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 Apr 12, 2024
@tspiteri tspiteri changed the title Add constants for f16 and f32 Add constants for f16 and f128 Apr 12, 2024
@fmease
Copy link
Member

fmease commented Apr 12, 2024

cc @tgross35

@rust-log-analyzer

This comment has been minimized.

@tspiteri tspiteri force-pushed the f16_f128_consts branch 3 times, most recently from 9810c6e to e972a7f Compare April 12, 2024 13:30
@rust-log-analyzer

This comment has been minimized.

@tspiteri
Copy link
Contributor Author

Note that for constants gated under more_float_constants for f32 and f64, I used #103883 rather than #116909 as a tracking issue.

@tspiteri
Copy link
Contributor Author

The test failure seems to be a panic in beta clippy.

  thread 'rustc' panicked at src/tools/clippy/clippy_lints/src/float_literal.rs:145:26:
  not implemented: f16_f128

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thank you for the help here!

I was holding off on these until we had the ability to actually run code that involves these types, which unfortunately we won't until I get compiler_builtins updated (well, code will run on x86 but nothing else so we can't actually merge anything). I was trying to add as little as possible until we get tests, but don't have any big problem with adding these.

One change needed - the literals we have aren't high enough precision for f128. I have a Julia script to generate longer ones using arbitrary precision math, https://github.com/tgross35/apfloat-consts. You can just copy the consts from output.rs.

@tgross35
Copy link
Contributor

The test failure seems to be a panic in beta clippy.

  thread 'rustc' panicked at src/tools/clippy/clippy_lints/src/float_literal.rs:145:26:
  not implemented: f16_f128

This is the other reason I haven't added too much more, clippy and CTFE both have some unimplemented! scattered around that can't be fixed until math is working (compiler_builtins...). You might be able to #[allow(clippy::all)] on this module.

@rustbot label +F-f16_and_f128

@tspiteri
Copy link
Contributor Author

Oops, I used 36 significant digits for f128 constants. I stumbled because 36 decimal digits is enough for numbers which are representable (such as EPSILON, MIN_POSITIVE, MAX, etc.), but not for numbers that are not, where you may need many more digits especially if the exact decimal number is close to mid-way between two consecutive floating-point numbers.

I changed f128 constants like PI to use 60 decimal significant digits, which is enough for all these constants. (I generated them with MPFR through the Rug crate, with rounding to the nearest just like the constants in the standard library for f32 and f64.) For f16 I just used the same literals that are used for f32 and f64.

@tspiteri
Copy link
Contributor Author

For the clippy warning, I think clippy is already fine in nightly, so instead of adding extra clippy allows, I think I might just wait for the next beta to be cut.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

NaN and infinity are not included as they require arithmetic.
NaN and infinity are not included as they require arithmetic.
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
                               at /rustc/efd9d2df12b5e17fac0b4d0fb89f612ecd79f259/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fd04d78f3eb - std::panicking::default_hook::{{closure}}::h743c1c016c642bf0
  10:     0x7fd04d78f143 - std::panicking::default_hook::h304853134c903f50
                               at /rustc/efd9d2df12b5e17fac0b4d0fb89f612ecd79f259/library/std/src/panicking.rs:292:9
  11:     0x7fd05062c05d - std[999bdecce25602ed]::panicking::update_hook::<alloc[5d2a9fe8278cb303]::boxed::Box<rustc_driver_impl[e6c4295f52574c92]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fd04d78fb50 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h8e05c89c9dfd827c
  13:     0x7fd04d78fb50 - std::panicking::rust_panic_with_hook::h6987b578e7dec23c
                               at /rustc/efd9d2df12b5e17fac0b4d0fb89f612ecd79f259/library/std/src/panicking.rs:783:13
  14:     0x7fd04d78f859 - std::panicking::begin_panic_handler::{{closure}}::h5e61050e5431c199
                               at /rustc/efd9d2df12b5e17fac0b4d0fb89f612ecd79f259/library/std/src/panicking.rs:649:13
---
  22:     0x7fd05097c8f6 - <rustc_lint[6313896b7e65eed2]::late::LateContextAndPass<rustc_lint[6313896b7e65eed2]::late::RuntimeCombinedLateLintPass> as rustc_hir[121f359932e59ede]::intravisit::Visitor>::visit_nested_item
  23:     0x7fd05097b6dd - <rustc_lint[6313896b7e65eed2]::late::LateContextAndPass<rustc_lint[6313896b7e65eed2]::late::RuntimeCombinedLateLintPass> as rustc_hir[121f359932e59ede]::intravisit::Visitor>::visit_nested_item
  24:     0x7fd05097b6dd - <rustc_lint[6313896b7e65eed2]::late::LateContextAndPass<rustc_lint[6313896b7e65eed2]::late::RuntimeCombinedLateLintPass> as rustc_hir[121f359932e59ede]::intravisit::Visitor>::visit_nested_item
  25:     0x7fd05204ff8a - rustc_lint[6313896b7e65eed2]::late::check_crate
  26:     0x7fd052055e49 - rustc_interface[2cd87b402a7bbb07]::passes::analysis
  27:     0x7fd052054f65 - rustc_query_impl[e29825a6f88888a7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e29825a6f88888a7]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f6bb74e4dd5a8f75]::query::erase::Erased<[u8; 1usize]>>
  28:     0x7fd052501ba2 - rustc_query_system[3350c2d9ca0121e2]::query::plumbing::try_execute_query::<rustc_query_impl[e29825a6f88888a7]::DynamicConfig<rustc_query_system[3350c2d9ca0121e2]::query::caches::SingleCache<rustc_middle[f6bb74e4dd5a8f75]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[e29825a6f88888a7]::plumbing::QueryCtxt, false>
  30:     0x7fd0523a5894 - rustc_interface[2cd87b402a7bbb07]::interface::run_compiler::<core[75bed1c93f3984e1]::result::Result<(), rustc_span[ebf54beea9088bcf]::ErrorGuaranteed>, rustc_driver_impl[e6c4295f52574c92]::run_compiler::{closure#0}>::{closure#0}
  30:     0x7fd0523a5894 - rustc_interface[2cd87b402a7bbb07]::interface::run_compiler::<core[75bed1c93f3984e1]::result::Result<(), rustc_span[ebf54beea9088bcf]::ErrorGuaranteed>, rustc_driver_impl[e6c4295f52574c92]::run_compiler::{closure#0}>::{closure#0}
  31:     0x7fd0526b1b2e - std[999bdecce25602ed]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[2cd87b402a7bbb07]::util::run_in_thread_with_globals<rustc_interface[2cd87b402a7bbb07]::interface::run_compiler<core[75bed1c93f3984e1]::result::Result<(), rustc_span[ebf54beea9088bcf]::ErrorGuaranteed>, rustc_driver_impl[e6c4295f52574c92]::run_compiler::{closure#0}>::{closure#0}, core[75bed1c93f3984e1]::result::Result<(), rustc_span[ebf54beea9088bcf]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[75bed1c93f3984e1]::result::Result<(), rustc_span[ebf54beea9088bcf]::ErrorGuaranteed>>
  32:     0x7fd0526b198a - <<std[999bdecce25602ed]::thread::Builder>::spawn_unchecked_<rustc_interface[2cd87b402a7bbb07]::util::run_in_thread_with_globals<rustc_interface[2cd87b402a7bbb07]::interface::run_compiler<core[75bed1c93f3984e1]::result::Result<(), rustc_span[ebf54beea9088bcf]::ErrorGuaranteed>, rustc_driver_impl[e6c4295f52574c92]::run_compiler::{closure#0}>::{closure#0}, core[75bed1c93f3984e1]::result::Result<(), rustc_span[ebf54beea9088bcf]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[75bed1c93f3984e1]::result::Result<(), rustc_span[ebf54beea9088bcf]::ErrorGuaranteed>>::{closure#1} as core[75bed1c93f3984e1]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:     0x7fd04d7991e5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3b366b3d6b556d67
                               at /rustc/efd9d2df12b5e17fac0b4d0fb89f612ecd79f259/library/alloc/src/boxed.rs:2020:9
  34:     0x7fd04d7991e5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h49756348eb63eea1
  35:     0x7fd04d7991e5 - std::sys::pal::unix::thread::Thread::new::thread_start::hdf802a7c2e3fdf20
                               at /rustc/efd9d2df12b5e17fac0b4d0fb89f612ecd79f259/library/std/src/sys/pal/unix/thread.rs:108:17
  36:     0x7fd04d45cac3 - <unknown>
  37:     0x7fd04d4ee850 - <unknown>
  37:     0x7fd04d4ee850 - <unknown>
  38:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new?template=ice.yml

warning: the ICE couldn't be written to `/checkout/rustc-ice-2024-04-29T08_39_20-17044.txt`: Read-only file system (os error 30)
note: rustc 1.78.0-beta.1 (efd9d2df1 2024-03-18) running on x86_64-unknown-linux-gnu


note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -C debug-assertions=on -Z unstable-options -C symbol-mangling-version=legacy -Z unstable-options -Z unstable-options -Z force-unstable-if-unmarked -Z macro-backtrace -C split-debuginfo=off -C prefer-dynamic -Z validate-mir -Z mir-opt-level=3 -Z inline-mir -C link-args=-Wl,-z,origin -C link-args=-Wl,-rpath,$ORIGIN/../lib -C force-frame-pointers=yes -Z crate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/") -Z binary-dep-depinfo -Z force-unstable-if-unmarked
note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [analysis] running analysis passes on this crate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-f16_and_f128 `#![feature(f16_and_f128)]` 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.

None yet

6 participants