File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

minus modulo minus equals plus?

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

output is -4 . but it should be 4 . am i missing something?
 
John Jai
Rancher
Posts: 1776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"fall down seven times, get up eight times"-Bodhidharman
+1
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How on earth would you get 4 out of 9 remainder 5? If you want a positive remainder, it would be 1.
You should read about the conventions behind the % operator. It is defined as a “Euclidean” operator, which means that multiplying back and adding the remainder gives the original dividend. If you try -9 % -5 and get a remainder of 1, then that is not “Euclidean”; if you multiply back, you will get -4.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic