Results 1 to 8 of 8
  1. #1
    lala is offline Member
    Join Date
    Oct 2010
    Posts
    80
    Rep Power
    0

    Default Not Possible (?)

    Hi.
    here is the problem:
    x=5, y=6, w=3.5.
    (x + y) % w

    My answer:
    (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.

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    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?

  3. #3
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Is it a Java book? Not all languages support the modulus operator on noninteger types.

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    My thoughts too - thanks for mentioning that!

  5. #5
    lala is offline Member
    Join Date
    Oct 2010
    Posts
    80
    Rep Power
    0

    Default 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.

  6. #6
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

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

    Good luck!

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,560
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by quad64bit View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    lala is offline Member
    Join Date
    Oct 2010
    Posts
    80
    Rep Power
    0

    Default (Solved) Not Possible (?)

    That's what I got, .5.

    Thanks again quad64bit and all.
    lala

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •