MikeLankamp / fpm

C++ header-only fixed-point math library
https://mikelankamp.github.io/fpm
MIT License
672 stars 85 forks source link

Is Division of two fixed point numbers implemented? #63

Closed Kuratius closed 8 months ago

Kuratius commented 8 months ago

I couldnt get a working result when I tried this

    float mydivide (float x0, float y0){
    fpm::fixed_16_16 x {x0};

    fpm::fixed_16_16 y {x0};
    fpm::fixed_16_16 z = x/y;
    return static_cast<float> (z) ;
    }

    printf("0.65/0.4 = %f \n", mydivide(0.65, 0.4));

this returns

0.65/0.4 = 1.000000

MikeLankamp commented 8 months ago

It is implemented. The reason you're getting 1.0 is because you have a typo in your example: you're constructing y from x0, so x/y is really just x0/x0.

I hope this helps. If the problem persists after fixing the typo, please re-open this issue.

Kuratius commented 8 months ago

Ah, thank you.

Kuratius commented 8 months ago

It may still be a good idea to add examples for common operations even if they seem obvious.