Skip to content

Casting negative float to float results in 0 #13

Description

@MaxenceLg9

Hello,

I encountered a bug today and I find it great to report it as it can causes some trouble to users.

Description

Given a negative float value, if we try to cast it with the method .as_, so as_f64() for example, it returns 0 instead of the float value on 64 bits.

I tested it with as_f64(), as_f32() it works.

Example

let test : f64 = -10.0;
println!("Value : {}, casted value {}", test, test.as_f32());

It gives the output :

Value : -10, casted value 0

My guess is because there is a middle operation that casts the float to an unsigned integer, but I'm not sure.

Have a great day, and I hope this issue will be useful!!

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