Questions tagged [modulus]

The remainder of the quotient of two numbers (usually integers).

847 questions
2
votes
1 answer

How do I fix modulus in Linear Congruential Generator?

I have one problem in my Linear Congruential Generator. I have two Modulus. If I replace or remove any one of them, I don't get any output, except for the counter which initiates at the end but it's pretty useless if there's no output to process…
2
votes
1 answer

MySQL MOD() is broken: Is this the best alternative?

At least in MySQL v5.1.73 (CentOS 6.6), MOD() function returns a bogus result... unless someone can explain how this is actually correct. mysql> select MOD(-385.4784399 ,1440); +-------------------------+ | MOD(-385.4784399 ,1440)…
tlum
  • 913
  • 3
  • 13
  • 30
2
votes
2 answers

Modulus to display input number vertically

Basically I need to write a program in java that will ask the user for an integer, and then display that number vertically (using only math), so the number 2849 will display: 2 8 4 9 I know that I can use modulus by 10, getting 9, 4, 8, 2 but what I…
Devin
  • 21
  • 1
2
votes
1 answer

How to go about doing something every fourth loop as well as every other loop?

int doEveryTwoTimes= 1; // Counter to do something every two loops int doEveryFourTimes= 2; // Counter to do something every four loops // add a nested infinite loop to increment counter while(true){ if(doEveryTwoTimes%2 == 0){ // DO…
Hooplator15
  • 1,540
  • 7
  • 31
  • 58
2
votes
1 answer

Modulus not returning the correct value for a non-negative input

I am working on a scaled down RSA encryption and decryption methods and everything seems to be working well, until I try to take the modulus of a number. The modulus operator isn't returning the expected result. for(int k = 0; k < sA.length;…
jm2rv
  • 29
  • 3
2
votes
3 answers

Every nth image with remainder offset for next loop

I have two values that indicate how many results to parse from some data and which nth item I want to target. In this case, it's making every nth item a large image where as the rest are normal size. Here's what I need the loop to do: First image…
Rob Graham
  • 73
  • 1
  • 7
2
votes
1 answer

finding sum of digits after decimal in a float till arbitary precision

I am trying to find the sum of 2000 decimal digits of a number created by a fraction, a/b. I am getting a lot of the digits until i hit NaN (not a number). I hit NaN when the loop runs around 310 times. How do I get the rest of the digits? Here is…
spørreren
  • 75
  • 3
2
votes
2 answers

How to use fmod and avoid precision issues

I'm going to boil this problem down to the simplest form: Let's iterate from [0 .. 5.0] with a step of 0.05 and print out 'X' for every 0.25 multiplier. for(double d=0.0; d<=5.0; d+=0.05) { if(fmod(d,0.25) is equal 0) print 'X'; } This…
c0dehunter
  • 6,412
  • 16
  • 77
  • 139
2
votes
3 answers

modulus optimization in c

I'm trying to do optimization of modulus operation on set of integers I know ahead The dividers are 400-3500, And the dividends are positive integers up to 2^16 I heard about magic numbers on hacker's delight but I couldn't find a way to get magic…
MrBlueSky
  • 305
  • 3
  • 10
2
votes
3 answers

Python - Modulus format variable

When I type the following into Notepad++ as Python code: days = "Mon" print "Here are the days: %s ". % days I get this output in Windows Powershell: File "ex9exp.py", line 4 print "Here are the days: %s ". % days I am at a loss as to why…
Raz
  • 93
  • 1
  • 6
2
votes
0 answers

Unexpected output in R with modulus operator

((10*(7655.7-7652.3))%/%(2)) [1] 16 ((10*(655.7-652.3))%/%(2)) [1] 17 ((10*(7655.7-7652.3))%/%(2)) [1] 16 ((10*(8655.7-8652.3))%/%(2)) [1] 17 ((10*(9655.7-9652.3))%/%(2)) [1] 17 ((10*(7655.7-7652.3))%/%(2)) [1] 16 %/% operator gives the…
2
votes
4 answers

C++ Remove First and Last digits of a number

I am trying to write a program to get rid of the first and last digit of a number. For the last digit, diving an int by 10 solves that issue. I need to find a way to use % to remove the first digit, but it seems like my logic is off somewhere, my…
Xerrad Anon
  • 57
  • 1
  • 2
  • 9
2
votes
2 answers

Having trouble converting integer color for cyan to RGB

There is a simple algorithm to convert integer values to RGB value of three numbers between 0-255 at integer to rgb. I got the integer number from Android Colors. I even ran: System.out.println(Color.decode("-16711681")); and the answer was…
smuggledPancakes
  • 9,881
  • 20
  • 74
  • 113
2
votes
1 answer

Boost cpp_dec_float supports modulus operation

As the title says, does Boost's cpp_dec_float support modulus operations? I'm dealing with money and would like to do some modulus operations to get the number of bills and coins that I need to return. cpp_dec_float seems to be the only arbitrary…
No_name
  • 2,732
  • 3
  • 32
  • 48
2
votes
1 answer

Why does this gives a runtime floating point error?

I am doing an assignment for school which introduced hashmaps, and so I am creating a templated class for a hashmap that uses the std::hash function. The problem that I am having comes in my insert function, which is shown below: template
shermanzach
  • 591
  • 1
  • 6
  • 14