Skip to content

float::round doesn't #3281

Closed
Closed

Description

@jesse99

Doesn't work as expected that is. Reasoning by analogy with the int modules I would expect that float::round(5.8) returns 6.0, but instead you get: error: mismatched types: expected core::libc::types::os::arch::c95::c_double but found float.

Looking at the code I expect that more that just round has this problem.

Activity

  1. brson commented on Aug 25, 2012

    @brson
    Contributor

    This is because c_double is a typedef for f64, and f64 and float are not type compatible (they used to be). Most of the float functions are just reexports of bindings to the C math libraries.

    The easiest fix is to write wrapper functions in core::float that cast to the right type (will be a noop).

    Beyond that it might be nice to think about how to get rid of the duplication between float/f32/f64.

  2. catamorphism commented on Jan 30, 2013

    @catamorphism
    Contributor

    3e9c95e fixes the specific problem with round. @brson, I'm not sure if the other issues you pointed out still apply or not.

  3. catamorphism commented on Jan 30, 2013

    @catamorphism
    Contributor

    (sorry, clicked close by mistake)

  4. alexcrichton commented on Jul 1, 2013

    @alexcrichton
    Member

    The specific code in question appears to have been fixed in d9c54f8, although
    it turns out that std::float::round == std::f64::round always, so
    std::float::round(2.3f) is actually a failure. I think this should be a
    separate issue, however (one that probably wants removal of a number of
    top-level functions in the numeric modules.

    I believe the preferred method is now 3.2f.round(). This won't work for
    literals (3.2.round() has multiple methods applicable in scope), but it would
    work for any floating type which is inferred somewhere else (to be expected).

    I'm going to close this saying that it's been fixed, but if others feel
    differently I can definitely reopen.

  5. added a commit that references this issue on Jan 28, 2024
  6. added 2 commits that reference this issue on Aug 21, 2026
    c3702a6
    5e827bd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions