Questions tagged [modulus]

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

847 questions
3
votes
2 answers

C++ modulus requires cast of subtraction between two *un*signed bytes to work, why?

The following Arduino (C++) code void setup() { Serial.begin(115200); byte b1 = 12; byte b2 = 5; const byte RING_BUFFER_SIZE = 64; byte diff = b2 - b1; byte diff2 = (byte)(b2 - b1) % RING_BUFFER_SIZE; //<---NOTE HOW THE (byte) CAST IS…
Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265
3
votes
1 answer

implementing a modulus on fixed point type

so currently I'm helping develop a programming language, and we've reached the point where we have to implement a fixed point type using C++ as our backbone language to write this in. I am able to figure out how to add, subtract, multiply, divide,…
3
votes
3 answers

Excel: calculate modulus of a very large number without getting overflow error

I have a A1 with 2 and a cell A2 with 288. I want to calculate MOD(2^288;2017) but this gives the NUM error. I also tried using this formula: =number-(INT(number/divisor)*divisor) but this gives 0 as a result when the numbers are too big. EDIT: not…
Agnaroc
  • 167
  • 2
  • 10
3
votes
3 answers

C modulus returning negative number

I have data type unsigned __int128 data; so I don't think this is a type issue, but I have no idea why it is occuring #include int main(int argc, char *argv[]) { unsigned __int128 z = 1911602146; unsigned __int128 n =…
Kendall Weihe
  • 2,021
  • 4
  • 27
  • 53
3
votes
1 answer

How to calculate modulus of large numbers with large prime?

I am working with elliptic curve cryptography on software environment. I wish to inquire how to efficiently implement the modulo operation of large numbers with respect to a large prime number. e.g. (192 bit number) mod (192 bit mersenne prime) If…
aviian7
  • 55
  • 6
3
votes
4 answers

need to print 5 column list in alpha order, vertically

Have a webpage that will be viewed by mainly IE users, so CSS3 is out of the question. I want it to list like: A D G B E H C F I Here is the function that currently lists like: A B C D E F G H I function…
Brad
  • 12,054
  • 44
  • 118
  • 187
3
votes
1 answer

Websocket handshake error with MeteorJS App on Modulus

The case is, I have a MeteorJS app deployed on modulus. When using the Modulus URL e.g. "myapp-12312.onmodulus.net" everything is working fine. BUT when using a Custom Domain and access the app via "myapp.mydomain.com" (configured in my DNS) I get…
Matthias Posch
  • 537
  • 6
  • 27
3
votes
3 answers

(n*2-1)%p: avoiding the use of 64 bits when n and p are 32 bits

Consider the following function: inline unsigned int f(unsigned int n, unsigned int p) { return (n*2-1)%p; } Now suppose that n (and p) are greater than std::numeric_limits::max(). For example f(4294967295U, 4294967291U). The mathematical…
Vincent
  • 57,703
  • 61
  • 205
  • 388
3
votes
2 answers

Catching iterations using php modulus in an irregular sequence

How can I write a modulus that will select the following iterations in sequence? 1, 4, 5, 8, 9, 12, 13 etc (+3+1r) I'm working within a loop and counting posts (iterations). So for example, I could catch every third post (1, 4, 7, 10) by:- if ($i %…
zigojacko
  • 1,983
  • 9
  • 45
  • 77
3
votes
1 answer

c++ armadillo modulus function

What is the best way to perform modulus operator over a vector or matrix in c++ Armadillo? The vector and matrix classes overload the % operator to perform element-wise multiplication. Trying to use it yields an invalid operands error. I was…
Brian
  • 3,453
  • 2
  • 27
  • 39
3
votes
2 answers

Modulus Division

I recently enrolled in a Java class and I have a question regarding modulus division. I get an example in my textbook: ( 100 - 25 * 3 % 4 ) = 97 How does this equal 97? I’ve tried every single possiblity and I just can’t seem to figure it out. Can…
DaBruh
  • 41
  • 3
3
votes
3 answers

Detect zero after std::remainder() call on doubles

I have this code: double a = remainder(92.66, 0.01); double b = remainder(92.87, 0.01); And it turns out that a = -5.33948e-15and b = -2.61423e-15 The answer here is clearly zero, and if I multiplied both numbers by 100 and did integer modulus it…
Salgar
  • 7,687
  • 1
  • 25
  • 39
3
votes
2 answers

Accelerating performance of loop performing unsigned long long modulo operation

I need to perform a many operations of finding remainders of the division unsigned long long number by the 16-bit modulus: unsigned long long largeNumber; long residues[100]; unsigned long modules[100]; intiModules(modules); //set different 16-bit…
Konstantin Isupov
  • 199
  • 1
  • 2
  • 12
3
votes
3 answers

regarding behaviour of modulo operation?

I wrote the following program in python for the following codechef question http://www.codechef.com/problems/MOVES/ import sys tokenizedInput = sys.stdin.read().split() mod=1000000007 arr=[1]*5001 for i in range(1,5001): …
Namit Sinha
  • 1,415
  • 3
  • 16
  • 30
3
votes
2 answers

C: The Math Behind Negatives and Remainder

This seems to be the #1 thing that is asked when dealing with Remainder/Mod, and I'm kind of hitting a wall with it. I'm teaching myself to program with a textbook and a chuck of C code. Seeing as I don't really have an instructor to say, "No, no.…