![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2005
Posts: 3
Rep Power: 0
![]() |
Modulus
Hello,
I'm trying to use the % for modulus but this works purely as a remainder operator. This does not work properly when you have non whole numbers, i.e. it won't calculate 25/4 % 7 correctly. Is there another operator which deals with this properly? Thanks! Hammamur. |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Have you tried it with numbers larger than the modulo? I believe even something like 24/4 % 7 will return 0, because 6 is less than 7.
|
|
|
|
|
|
#3 |
|
Programmer
|
Actually, 25/4 % 7 should return 6. Because all the numbers you used here are int's, the dividing and the mod will automatically round down. So, 25/4 = 6 and 6%7 = 6. (6/7 = 0R6). If you're looking for a decimal answer, you need to change all your numbers to doubles, like so: 25.0/4.0 % 7.0 which will return 6.25. If you were looking for something else entirely, then you might have your formula set up wrong (or mod isn't what you need ). What result were you looking for exactly?
__________________
I can pick my friends. And I can pick my nose. So, why can't I pick my friend's nose? |
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Damnit... what was I thinking about...
|
|
|
|
|
|
#5 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
I believe when using modulus you must have a whole number.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#6 | |
|
Programmer
|
Quote:
__________________
I can pick my friends. And I can pick my nose. So, why can't I pick my friend's nose? |
|
|
|
|
|
|
#7 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Heh. That's pretty cool. I had no idea you could do that with decimals.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#8 |
|
Programmer
|
Yeah, me neither, I'd was just guessing it would work 'till I tried it. :p
But anyway, the question remains, what values were you originally expecting, HRahman?
__________________
I can pick my friends. And I can pick my nose. So, why can't I pick my friend's nose? |
|
|
|
|
|
#9 |
|
Newbie
Join Date: Jan 2005
Posts: 3
Rep Power: 0
![]() |
Hello,
Yes, should'nt be able to use non-whole number with mod (it doesn't make sense to). BUT yet Java allows you which is mathematically incorrect. What needs to happen is for the example for 25/4: Convert this to 25 * 1/4 Now the inverse of 1/4 is 2, so therefore: 25 * 2 = 50 = 1 (mod 7) Now, what I was hoping that Java provided a more surfisticated modulus operator to do all the above. So, anyone no of one. Thanks alot for all the replies!!!! Hammamur. |
|
|
|
|
|
#10 |
|
Programmer
|
Oh, I see, you want the real, mathematical modulus. Well, I think you're outta luck then. I don't know of any other operators that work with modulus.
Also, to be honest, I still can't really tell what you're trying to evaluate. Are you trying to show that 25 = 4 (mod 7) (and get a boolean result)? Or are you trying to find that the modulus is 7? Or are you tring to find the remainder that makes them congruent (4)? Outside of programming, mod isn't an operator at all, it's simply a label. Oh, and isn't 4 the inverse of 1/4 not 2?
__________________
I can pick my friends. And I can pick my nose. So, why can't I pick my friend's nose? |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|