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
3 answers

Divisor value in for loop is mysteriously (?) changing

So I have been at this for hours, and I'm honestly completely stuck. I've wrote a for loop that counts the amount of numbers in an integer, but I've found that the divisor value changes once i enter a number above 10 digits, and I can't figure out…
Darian Ray
  • 15
  • 5
0
votes
1 answer

Division of integers result in integer not in float? (Raptor Flowchart)

I want to draw a flowchart in Raptor, which will do division of integers and will give result in integers not in floating point numbers like: 2/5=2.5 but I want the result to be 2 which is the quotient part.
0
votes
2 answers

Is Math.floor(x/y) deterministic?

According to this post, floating point numbers in JavaScript are not deterministic. I wonder, is the following code deterministic? z = Math.floor(x/y) If not, how can I do deterministic integer division in JavaScript? Edit: I would like to know if…
Simon Farshid
  • 2,636
  • 1
  • 22
  • 31
0
votes
1 answer

The remainder in integer division is negative in Python

Please explain why: print ((- 1) % (-109)) # prints -1 print (1 % (-109)) # prints -108 Why is the result negative if the terms of the wording of the remainder 0 <= r < b
Eliar
  • 23
  • 2
0
votes
1 answer

Unit tests for 64 bit division

I am tasked with unit testing the 64 bit division function (which we have coded in assembler for PPC, not that that should matter). So far, I have: max value div max value max value div min value max value div minus max value max value div…
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
0
votes
2 answers

ZeroDivisionError: float division by zero even though I have a zero catcher

I'm a little new to Python. I have attached a snippet of code below. constant_a & b are integers. While running this code, I get the following error: Traceback (most recent call last): File "U:\V10_run2\process.py", line 209, in …
rahdirs
  • 13
  • 1
  • 6
0
votes
1 answer

In order to access first Digit of an integer dynamically, is using a String or Division more efficient?

There's two methods I've read about, divide by 10 repeatedly (or slightly more efficiently, divide in a way to minimize division operations) i.e. int getFirstDigit(unsigned int num) { if (num >= 100000000) num /= 100000000; if (num…
Kosba2
  • 15
  • 6
0
votes
1 answer

Why do I have to add a decimal to get this math correct in C++

I was calculating the volume of a sphere and after tons of research I found that I cannot use: float sphereRadius = 2.33; float volSphere = 0; volSphere = (4/3) * (M_PI) * std::pow(sphereRadius, 3); But must add the 3.0 instead to get the right…
Michael Rader
  • 5,839
  • 8
  • 33
  • 43
0
votes
1 answer

how to determine data type of arithmetic expressions involving divisions in c++

Have a look at the following programme. // Example program #include #include int main() { int n=7; std::cout <<"n/2 = "<< n/2 << std::endl; std::cout <<"n/3.3 = "<< n/3.3 << std::endl; } output : n/2 = 3 n/3.3 =…
0
votes
2 answers

Divide integer by 12 and show if remainder is odd or even

Trying to create a program that asks the user to input a number between 20 and 100. After the number has been entered. The program will divide the entered number by 12. The program will then say if the result of the division is even or odd.…
0
votes
7 answers

How to check divisibility of a number in continuous fragments by 11 in c++

Given a number num find out how many continuous fragments of the given number is divisible by 11 for example given 1215598 these continuous fragments could be…
0
votes
0 answers

Remainder without division

I have already googled a lot about this topic and also have read similar questions and their respective answers. What I'm asking about is a specific algorhitm for calculating mod 2**k+c (c can be negative). There are also some limitations about how…
Danetta
  • 1
  • 3
0
votes
2 answers

Determine if a given integer number is element of the Fibonacci sequence in C without using float

I had recently an interview, where I failed and was finally told having not enough experience to work for them. The position was embedded C software developer. Target platform was some kind of very simple 32-bit architecture, those processor does…
user2218825
0
votes
3 answers

Incorrect result of dividing the product of two integers by their gcd

We know that for two numbers 'a' and 'b'; product of a & b is equal to the product of GCD(a,b) and LCM (a,b). So in order to find the LCM of two numbers I wrote this algorithm in Python: def gcd(a,b): if b==0: return a else: a_rem =…
0
votes
3 answers

How to find the value of integer k efficiently for which q divides b ^ k finitely?

We have given two integers b and q, and we want to find the minimum value of an integer 'k' for which q completely divides b^k or k does not exist. Can we find out the value of k efficiently? Not just iterating each value of k (0, 1, 2, 3, ...) and…