mardi 7 mai 2019

C++: std::remquo not giving expected output

I am trying to find the number of times one double divides into another in C++ and the only function I found to do so was remquo. But when using it it does not give the expected results with the resulting quotients being only between 0 and 3 when they should be from 0 to 20.

smaller sized doubles work does it have problems with more precise floating point numbers?

int quotient;
    double remainder = remquo((coordX+maxX), tileSizeX, &quotient);
    cout << coordX+maxX << " / " << tileSizeX << " = " << quotient << " r " << remainder << endl;
    return quotient;

In this case maxX will be 0.773 and coordX will be a number from -0.773 to 0.773 and lastly tileSizeX will be about 0.073619.

here are some outputs of the cout call:

0.773 / 0.073619 = 2 r 0.0368095 but 0.073619 * 2 + 0.0368095 = 0.1840475, nowhere near 0.773 like I expected.

0.085 / 0.073619 = 0 r 0.011381 <- wrong

0.181 / 0.073619 = 2 r 0.0337619 <- right

0.433 / 0.073619 = 3 r -0.00871429 <- wrong

1.269 / 0.073619 = 0 r 0.0174762 <- wrong

The remainder always seem right but the quotient almost never is. Is there something I am not understanding.

Aucun commentaire:

Enregistrer un commentaire