# Not Possible (?)

• 01-13-2011, 08:32 PM
lala
Not Possible (?)
Hi.
here is the problem:
x=5, y=6, w=3.5.
(x + y) % w

(x + y) % w
(5 + 6) % 3.5
11 % 3.5 (because this is a mixed expression 11 is 11.0). My answer: 0.5

Book answer: Not possible

I don't get it. (?) Any ideas. Thank you.
• 01-13-2011, 09:17 PM
Well, assuming all numbers are floats, then I too get .5. I have a feeling there they are mixed types? Could we get some more context here?
• 01-13-2011, 09:51 PM
Is it a Java book? Not all languages support the modulus operator on noninteger types.
• 01-13-2011, 10:13 PM
My thoughts too - thanks for mentioning that!
• 01-15-2011, 02:38 PM
lala
Not Possible (?)
Hi. Yes, toadaly this is a java book.
This is how the problem is stated:

"If x=5, y=6, z=4, & w=3.5, evaluate each of the following expressions, if possible. If it is not possible, state the reason. "

I think the book is wrong, & my answer is correct. I am presuming all values are "int" except w.

Thanks again Everyone.
• 01-15-2011, 03:23 PM
Well the ultimate test is to type it into a java app and execute it. Thats what I did and got .5.

Good luck!
• 01-15-2011, 03:30 PM
JosAH
Quote:

Originally Posted by quad64bit
Well the ultimate test is to type it into a java app and execute it. Thats what I did and got .5.

I did so too and typed it in, using my own little language and it came up with the wrong answer. I already found the bug (it was a simple copy/paste error). That darn code exists for more than four years already and I never found that bug, despite all the unit tests I ran! Aaarrghhh! ;-) That shows that I never use a floating pont modulo operator ...

kind regards,

Jos
• 01-15-2011, 03:42 PM
lala
(Solved) Not Possible (?)
That's what I got, .5.

Thanks again quad64bit and all.
lala