Questions tagged [modulo]
The modulo (sometimes called modulus) operation finds the remainder of division of one number by another. It's typically represented by the percent ('%') character in programming languages.
modulo
1,986
questions
0
votes
0
answers
18
views
C++ - Questions about bit shift operators (<< and >>)
Consider the below code:
std::string g_CharTable = "stjkloptrew23456mncv891TZUIOPAS";
std::uint32_t value = 123456789
std::string hash;
for (std::size_t i = 0; i < 5; ++i)
{
...
-3
votes
0
answers
52
views
Issue with modulus operator in dynamic SQL [closed]
I am trying to execute the following example query through dynamic SQL (let's not get into why it's dynamic), but I cannot get it to consistently execute correctly.
If I substitute % with %% I get ...
0
votes
0
answers
11
views
How to pin modulus of the certificate public key on Android?
So I am using Android TrustKit to pin certificate's Subject Public Key Info. One of the security guys suggested I pin modulus of the public key, however, I cannot find any sort of examples on how to ...
0
votes
2
answers
35
views
How to convert a time string measured in 24 hours cycle to 12 hours cycle?
I have a stored value of an hour in a 24-hour format in a variable named hour. My task is to convert this value to a 12-hour format and print the result.
I tried while-loops, if-elif-statements. I ...
0
votes
1
answer
36
views
Math power function with modulo arithmetic in Python
I am learning group homomorphism (a Math concept) with modulo arithmetic. Basically, I want to show that g^(2x+8y) mod n equals to (g^(2x) . g^(8y)) mod n.
I have the following python code:
g = 57
n = ...
3
votes
2
answers
106
views
Why is `array % 1` running 150% slower for smaller numbers than larger ones?
I would understand if numpy was smart enough to see that array % 1 gives a constant result (for that dtype), and that its runtime was independent of the input. I would also understand if runtime was ...
-1
votes
0
answers
38
views
if statement is executed while condition is false. with modulo [duplicate]
i am working an a set of data that roughly repeats itself every 34 data points. however i wish to modify every N-th value. but in every repetion of the data set. the amount of data sets can vary.
i ...
0
votes
0
answers
75
views
C# modulo operation with decimal yields inconclusive result
I have a very quick question, based on the following C# code:
decimal _sampleCounter = 2100m;
decimal wrong = _sampleCounter % (30m / 2.3m);
decimal correct = 2100m % (30m / 2.3m);
Console.WriteLine(...
0
votes
2
answers
55
views
How to include a modulus operation in CasADi function
I can't find a modulus function in CasADi. I want to build a function with something like this:
from casadi import MX
angle = MX.sym('angle')
wrapped_angle = ((angle + 180) % 360) - 180
TypeError: ...
1
vote
2
answers
105
views
Modulus `%%` giving unexpected result for `3.1 %% 0.1`. Is this expected?
I'm using the base modulus (%%) operator, and just struggling to understand the following behaviour. My understanding is that %% returns the remainder after dividing 2 numbers. So eg:
5 %% 2
# [1] 1
...
1
vote
1
answer
90
views
Counting the number of distinct digits that divide a number- Unable to pass all test cases
I was practicing from Leetcode earlier and I came across this question:
Given an integer num, return the number of distinct digits in num that divide num.
An integer val divides nums if nums % val == ...
0
votes
0
answers
12
views
Raymarcher glitches when performing local transforms using modulus "coordinate-space" repeat trick
I am building a ray marcher in GLSL to further understand the language. I am attempting to repeat the coordinate space using modulus when calculating the SDF so that "infinite" spheres ...
0
votes
0
answers
25
views
why does the value of n increases by one in in first iteration while the result of (n+1)%26 is 0.26
in line 10, n = (n + 1) % 26; the value of n should be 0.26 in first iteration as it has not been rounded up or rounded down so why has the value of n increased by one ?? I don't understand this part ...
0
votes
1
answer
54
views
modulus maths question - competitive programming
I was attempting past competition questions and was stuck on this question. The solution was made public, but I still can't seem to get how did they derive the solution logic.
question:
Meow is ...
2
votes
3
answers
61
views
Homework Help - Using Modulo to Count out Bills and Coins
NOTE: I do NOT want the answer! I am hoping to get guidance on next steps
I am new to python and have a question about a problem I'm working:
Define a function consolidate_change that takes as ...