Skip to content

Floating-point abs() and friends not part of no_std prelude #34766

Closed
@eefriedman

Description

@eefriedman
#![crate_type="lib"]
#![no_std]
fn f(x: f32) -> f32 { x.abs() }
error: no method named `abs` found for type `f32` in the current scope
 --> <anon>:3:25
  |>
3 |> fn f(x: f32) -> f32 { x.abs() }
  |>                         ^^^
help: items from traits can only be used if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
help: candidate #1: `use core::num::Float`

It is actually possible to write core::num::Float::abs(x), but I'm not sure that's actually supposed to be legal, and at that point, you might as well just write your own abs() function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-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