Questions tagged [integer-division]

Anything related to the integer division operation, i.e. that special form of division which is performed between two integer numbers and which in math results in a quotient and a remainder. This is mostly relevant for languages which have specific integer data-types, for which the division is an integer division, or for languages having a specific operator/function to perform integer division.

Anything related to the integer division operation, i.e. that special form of division which is performed between two integer numbers and which in math results in a quotient and a remainder. This is mostly relevant for languages which have specific integer data-types, for which the division is an integer division, or for languages having a specific operator/function to perform integer division.

619 questions
0
votes
1 answer

Scaling a value using integers only

I'm coding in C - I've got some speed-critical calculations I'm trying to make on a microcontroller, and I want to find the ratio of the numbers without using floating point variables. I have a byte between 0 and 255, and I want to find a percent of…
CarlosTheJackal
  • 220
  • 1
  • 14
0
votes
2 answers

Why "-3 >> 1" does not produce the same result as "-3 / 2"?

Consider the following c++ code: int main() { int a = -3 >> 1; int b = -3 / 2; cout << "a = " << a << ", b = " << b << endl; return 0; } When executed, this code give this result: a = -2, b = -1 I'm a little puzzled, because I…
Jean-Milost Reymond
  • 1,833
  • 1
  • 15
  • 36
0
votes
1 answer

Find/simplify overlapping modulo

I have some code solving today's "Advent of code part 2". https://adventofcode.com/ I have currently many hardcoded modulo conditions, is there any simple way to reduce the number of conditions? Since in general you can skip checking x % 4 == 0 if…
Viktor Mellgren
  • 4,318
  • 3
  • 42
  • 75
0
votes
0 answers

Binary Number Divisible by N using Single Logic Gate

Given a 16-bit register A holding a number in 2’s complement form, use a single gate (e.g., AND, OR, XOR, NAND, NOR, NOT) with an arbitrary number of inputs to implement a circuit that produces an output 1 if the number is divisible by 16, and an…
0
votes
1 answer

Integer division in Common Lisp

I tried to do division in Lisp. When I do (/ 5 2), the result is 5/2, but what I need is 2. How can I do that?
0
votes
2 answers

Division with numerator 2^64

How to to divide the constant 2^64 (i.e. ULLONG_MAX + 1) by uint64 larger than 2, without using unit128? In other words, given x such as 2 <= x <= 2^64-1, how to obtain the quotient 2^64 / x, using just uint64? The problem is that I cannot…
Ecir Hana
  • 10,864
  • 13
  • 67
  • 117
0
votes
1 answer

Division returning quotient and remainder using a loop and subtraction?

I'm doing exam practice, and one of the questions asks you to create a function called divide(a,b) calculates both the quotient and remainder of the two parameters and returns both results. You cannot use the built in division operator or modulo…
Moca
  • 43
  • 2
  • 7
0
votes
4 answers

division with wrong result

I am trying to divide integers but get 0 as result. I just do not understand what i am doing wrong. I am using only int's in this example but get the same result testing with float or double. The code i use is: int wrongAnswers = askedQuestions -…
PeterK
  • 4,243
  • 4
  • 44
  • 74
0
votes
1 answer

can not figure out how to keep my double...a double

if ((double) (points / tries) > hiScore) { hiScore = (double) points / tries; hiPoints = points; hiTries = tries; I cannot understand why hiScore, or even points / tries,…
mr.uaila
  • 3
  • 5
0
votes
2 answers

C++ Integer Division to Float

My C++ program takes in three integer inputs and does some computations including division. At first, the end result was not a decimal. After searching a little on Stack Overflow (Dividing two integers to produce a float result), I found out that…
Superrbo
  • 9
  • 1
  • 1
  • 3
0
votes
1 answer

Till what number is finding the divisors of a given number possible in under 5 seconds

I am given a number n <= 10^85, I want to compute all of the divisors for the given n. Till what number can I compute all of the divisors in under 5 seconds? I am aware that the execution time of whatever algorithm is chosen depends on the hardware…
PlsWork
  • 1,958
  • 1
  • 19
  • 31
0
votes
4 answers

Division in Python 2.x

In Python 2.x ,the integer division-7/3 should output -2,right?.Reason:since both the numerators and denominators are integers,the division is carried out and digits after decimal are truncated.so in this case, -7/3=-2.3333333....so,python should…
explorer
  • 27
  • 1
  • 8
0
votes
1 answer

Error in Eiffel implementation of Burnikel and Ziegler algorithm 2

I need another set of eyes to tell me what is wrong with my Eiffel implementation of Burnikel and Ziegler's division, specifically "Algorithm 2 - 3n/2n". The Eiffel feature is shown below. The type "like Current" is an ARRAYED_LIST [NATURAL_8]. …
jjj
  • 23
  • 8
0
votes
1 answer

Divide by Zero Exception raised despite edge case

I am trying to handle a divide by zero exception manually in python3.5, however, it keeps ignoring my user defined case and giving the default exception. How can I avoid this? Any help is appreciated. NOTE: I'm using a list as a stack, hence the…
J. Doe
  • 17
  • 4
0
votes
1 answer

Python: Loop Parameters

I apologize if I haven't titled this appropriately, but I'm having trouble getting the following code to execute. The for loop parameters seem to be at least part of the problem. If I substitute "limit" for "num" in the for loop to yield "for j in…