Questions tagged [modulus]

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

847 questions
3
votes
2 answers

how to get modulo of a value in exponential form

Question is about the modulo operator on very large numbers. For example consider a question where the total number of permutations are to be calculated. Consider a number of 90 digits with each of the 9 numbers (1 to 9) repeating 10 times so…
3
votes
3 answers

Floating point comparison in while loop with modulus

I would like some advise on how to optimise the following while loop: double minor_interval = 0.1; double major_interval = 1.0; double start = 0.0; double finish = 10.0; printf("Start\r\n"); while (start < finish) { …
PCL
  • 421
  • 2
  • 7
  • 15
3
votes
3 answers

Why does the C++ modulo operator return 0 for -1 % str.size()?

I'm confused why the following code produces this output: #include #include using namespace std; int main() { int i = -1; string s = "abc"; int j = s.size(); int x = 1 % 3; int y = i % j; int z = i %…
3
votes
2 answers

Floating point modulus problem

I'm having a problem with modulus on a floating point number in Python. This code: ... print '(' + repr(olddir) + ' + ' + repr(self.colsize) + ') % (math.pi*2) = ' + repr((olddir+self.colsize) ... Prints: (6.281876310240881 + 0.001308996938995747)…
paldepind
  • 4,680
  • 3
  • 31
  • 36
3
votes
1 answer

Different implementations for Extended Euclidean algorithm yield different results?

I'm trying to implement the RSA algorithm. I have been reading about the Extended Euclidean Algorithm, and tried to implement the code on different websites. It didn't give me the correct results for some of my decryptions, so I have been debugging…
Lo Ran
  • 35
  • 2
3
votes
2 answers

Swift Double.remainder(dividingBy:) returning negative value

let num = 32.0 Double(num).remainder(dividingBy: 12.0) I'm getting -4?..instead of 8.0...it's subtracting 12.0 from 8.0 how do i fix this?
caa5042
  • 166
  • 3
  • 16
3
votes
2 answers

What is this zero-invariant modulus function called?

I've got some code that calculates a cyclic offset for a given integer, and I want it to calculate the cyclic-offset such that the function's output will not show any anomalous behavior as the input value transitions from positive to negative and…
Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234
3
votes
2 answers

How to efficiently verify whether pow(a, b) % b == a in C (without overflow)

I'd like to verify whether pow(a, b) % b == a is true in C, with 2 ≤ b ≤ 32768 (215) and 2 ≤ a ≤ b with a and b being integers. However, directly computing pow(a, b) % b with b being a large number, this will quickly cause C to overflow. What…
Isaiah
  • 1,852
  • 4
  • 23
  • 48
3
votes
3 answers

PHP: wrapping each group of 3 elements

I am trying to figure out how to write a loop that will wrap every group of 3 elements. However, for the last iteration, it should wrap whatever is left (be it one, two or three elements) So basically this kind of pattern: div do stuff do stuff do…
user1049944
3
votes
1 answer

How to sum every element in a numpy array divisible by 5 using vectorization?

I am looking for a vectorization method for summing all elements of a numpy array that is evenly divisible by 5. For example, if I have test = np.array([1,5,12,15,20,22]) I want to return 40. I know about the np.sum method, but is there a way to…
SeeDerekEngineer
  • 770
  • 2
  • 6
  • 22
3
votes
1 answer

Can't find the digit check algorithm

I can´t find which algorithm is being used to to calculate the 2 digits check digit of my bank references. Some examples 0404 3295 60983 0707 3328 25810 0900 9907 32991 0900 8912 91695 0707 2268 89938 0808 1153 45010 0808 0964 91963 0900 6632…
Fraga
  • 1,361
  • 2
  • 15
  • 47
3
votes
1 answer

How to find modular multiplicative inverse in c++

#include #define mx 1000005 #define mod 1000003 using namespace std; long long arr[mx]; int fact() { arr[0]=1; for(int i=1; i
Linkon
  • 1,058
  • 1
  • 12
  • 15
3
votes
2 answers

Why does the % operator sometimes output positive and sometimes negative?

I was working on a script in unity when i realized something odd and after I finished the script I tested my realization in a visual studio console project. class Program { static void Main(string[] args) { Console.WriteLine(-3.5 %…
Bilal Shafi
  • 115
  • 2
  • 13
3
votes
0 answers

RSA: convert modulus hexadecimal value to decimal

I have a RSA Public key in base64_encoded form: -----BEGIN PUBLIC…
3
votes
1 answer

Issues deploying meteor app to modulus

Following something similar to this... http://stuart-85933.onmodulus.net/ and that exact one. Tried a bunch of things for an hour and I'm dying. Help please! Thanks. "Unable to connect to any application instances." Here is my logs on modulus…
user1990406
  • 519
  • 4
  • 16