Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double Conversion #26

Closed
peteut opened this issue Mar 16, 2015 · 1 comment
Closed

Double Conversion #26

peteut opened this issue Mar 16, 2015 · 1 comment
Assignees

Comments

@peteut
Copy link

peteut commented Mar 16, 2015

There is a problem w/ the double conversion if TOTAL_WIDTH and FRACTION_WIDTH is equal and Fi::SIGNED. Considering

#include "fi/Fixed.hpp"
#include "fi/overflow/Wrap.hpp"

//#include <boost/shared_ptr.hpp>

int main(int argc, char* argv[]) {

    const double val(0.1);

    Fi::Fixed<16, 16, Fi::SIGNED> a(val);
    Fi::Fixed<16, 15, Fi::SIGNED> b(val);
    Fi::Fixed<16, 16, Fi::SIGNED> c("0.1");

    std::cout << "Fi::Fixed<16, 16, Fi::SIGNED> a(0.1) does not work: "
        << a << std::endl;
    std::cout << "Fi::Fixed<16, 15, Fi::SIGNED> b(0.1) works: "
        << b << std::endl;
    std::cout << "Fi::Fixed<16, 16, Fi::SIGNED> c(\"0.1\") works: "
        << c << std::endl;

    return 0;
}

yields

Fi::Fixed<16, 16, Fi::SIGNED> a(0.1) does not work: -0.100006103515625
Fi::Fixed<16, 15, Fi::SIGNED> b(0.1) works: 0.0999755859375
Fi::Fixed<16, 16, Fi::SIGNED> c("0.1") works: 0.0999908447265625

I'm using GCC 4.7.2 and Boost 1.57.0.

@gsarkis gsarkis self-assigned this Mar 17, 2015
@gsarkis
Copy link
Owner

gsarkis commented Apr 16, 2015

Thanks for finding this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants