Skip to content

no_std does not impl sqrt for f32 and f64 #39473

Closed
@CasualX

Description

@CasualX

I tried the following code (compiled as a library):

#![no_std]
pub trait Float {
    fn sqrt(self) -> Self;
}
impl Float for f32 {
    fn sqrt(self) -> Self { self.sqrt() }
}
impl Float for f64 {
    fn sqrt(self) -> Self { self.sqrt() }
}

I expected to see this happen: The above code working and calling the correct sqrt function.

The core docs for the f32 primitive type 404s and unlike the integer types does not contain a link to f32's primitive type info page.

Instead this happened:

warning: function cannot return without recurring, #[warn(unconditional_recursion)] on by default
  --> src\unit.rs:58:2
   |
58 |    fn sqrt(self) -> f32 { self.sqrt() }
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: recursive call site
  --> src\unit.rs:58:25
   |
58 |    fn sqrt(self) -> f32 { self.sqrt() }
   |                           ^^^^^^^^^^^
   = help: a `loop` may express intention better if this is on purpose

warning: function cannot return without recurring, #[warn(unconditional_recursion)] on by default
  --> src\unit.rs:61:2
   |
61 |    fn sqrt(self) -> f64 { self.sqrt() }
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: recursive call site
  --> src\unit.rs:61:25
   |
61 |    fn sqrt(self) -> f64 { self.sqrt() }
   |                           ^^^^^^^^^^^
   = help: a `loop` may express intention better if this is on purpose

Is this intended?

Meta

rustc --version --verbose:

rustc 1.14.0 (e8a012324 2016-12-16)
binary: rustc
commit-hash: e8a0123241f0d397d39cd18fcc4e5e7edde22730
commit-date: 2016-12-16
host: x86_64-pc-windows-msvc
release: 1.14.0
LLVM version: 3.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions