japaric / fpa

Fixed Point Arithmetic
Apache License 2.0
29 stars 5 forks source link

functions to calculate a vectors magnitude and angle #2

Open 4lbert opened 6 years ago

4lbert commented 6 years ago

Is there any functions for calculating a vectors magnitude and angle in this library?

I tried using polar() but the results are not what I expected. The following code prints 0.7375122532248497, but it should be 1.41... :

extern crate fpa;

use fpa::I3F29;

fn main() {
    let x = I3F29(1_i32).unwrap();
    let y = I3F29(1_i32).unwrap();
    let (a, _) = x.polar(y);
    println!("{}", a);
}

I've also tried different values, but I never get a value that would be the magnitude of the vector.

Thanks for this library!

japaric commented 6 years ago

That may be a convergence bug. 3.polar(4) does return 5.

4lbert commented 6 years ago

Yeah, seems like this happens when both numbers are too close to each other. Thanks, guess I'll just ignore when this causes bugs, shouldn't be too often after all.