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

Integer Division #304

Closed
juliusbrehme opened this issue Aug 4, 2023 · 1 comment
Closed

Integer Division #304

juliusbrehme opened this issue Aug 4, 2023 · 1 comment
Assignees
Labels

Comments

@juliusbrehme
Copy link

Hello everyone,

I have the following code:

  Expression exp1{10};
  Expression exp2{3};
  Expression result{exp1/exp2};

The expected result of the Expression is 3, because of Integer Division, but I get 3.3333.
If I do the following:

Expression result{10/3};

I get the expected 3.

I don't know if that is intended or not.

Thanks in advance.

@soonhokong
Copy link
Member

soonhokong commented Aug 8, 2023

  Expression exp1{10};
  Expression exp2{3};
  Expression result{exp1/exp2};  // result = 3.3333

This is expected behavior. A constant expression holds a double value and division between expressions is handled not following the integer division rule.

  Expression result{10/3};

Here, 10/3 = 3 is computed before it is passed to the constructor of Expression class. There is nothing much we can do about it. This is how C++ works.

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

No branches or pull requests

2 participants