Skip to content

Float::abs_sub isn't working properly #22105

Closed
@mdinger

Description

@mdinger

I'm not sure what Float::abs_sub() is supposed to do but it's not working correctly.

#![feature(std_misc)]

fn main() {
    use std::num::Float;

    // Rules:    
    // - If `self < other`: `0`
    // - Otherwise `self - other`

    assert_eq!(3.0f64.abs_sub(5.0), 0.0); // okay
    assert_eq!(3.0f64.abs_sub(-5.0), 8.0);// okay

    assert_eq!(3.0f64.abs_sub(2.0), 1.0); // okay
    assert_eq!(3.0f64.abs_sub(-2.0), 5.0);// okay

    assert_eq!(-3.0f64.abs_sub(2.0), -1.0); // Wrong. What should this do?
    assert_eq!(-3.0f64.abs_sub(-2.0), -5.0);// Wrong. What should this do?

    assert_eq!(-1.0f64.abs_sub(2.0), 0.0);  // okay
    assert_eq!(-1.0f64.abs_sub(-2.0), -3.0);// Wrong. What should this do?

    assert_eq!(0.0f64.abs_sub(1.0), 0.0);   // okay
    assert_eq!(0.0f64.abs_sub(-1.0), 1.0);  // okay
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions