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
9
votes
1 answer

With c++ integers, does 1 divided by 2 reliably equal 0, and 3/2 = 1, 5/2 = 2 etc.?

There are two vectors of differing, yet related sizes. The larger is (2 * RESOLUTION) + INDEX_OFFSET (e.g. 2050) and the smaller is simply RESOLUTION (e.g. 1024). I believe it safe enough to assume that uint16_t can be used to contain the vector…
mosi
  • 247
  • 1
  • 2
  • 10
8
votes
3 answers

Does \ perform integer division in VB?

In VB.NET even if both the operands are integer, the / operator will cause the value to be floating point (if the result is non integer). So I tried with the \ operator which yields integer value irrespective of the operands. So I thought \ is…
techBeginner
  • 3,792
  • 11
  • 43
  • 59
8
votes
1 answer

Fast hardware integer division

Hardware instruction for integer division has been historically very slow. For example, DIVQ on Skylake has latency of 42-95 cycles [1] (and reciprocal throughput of 24-90), for 64-bits inputs. There are newer processor however, which perform much…
Ecir Hana
  • 10,864
  • 13
  • 67
  • 117
8
votes
2 answers

Python multiplication equivalent to integer division

In python using // for division forces the result to be an integer. Is there an equivalent for multiplication? For example, assume I have an integer W which I scale by a float f. It could be nice to have an operator such as .*, so…
Amir Rosenfeld
  • 331
  • 2
  • 12
8
votes
1 answer

What is signed division(idiv) instruction?

In intel instruction, idiv(integer divsion) means signed division. I got the result of idiv, but I don't quite understand the result. - Example 0xffff0000 idiv 0xffff1100 - My wrong prediction As long as I know, quotient should be 0, and…
Jiwon
  • 1,074
  • 1
  • 11
  • 27
8
votes
2 answers

How can I avoid a warning about division-by-zero in this template code?

I have a class for fixed-point arithmetic, of which this is the salient portion: template struct fixed { I value; fixed(I i) : value(i * S) {} template fixed(const fixed &fx) { if…
user79758
8
votes
1 answer

Division between integers in Java

I need to perform division between integers in Java, and the result should be a float. Could I just use / symbol for it? As in: int integer1 = 1; int integer2 = 2; float quotient = integer1 / integer2; // Could I do this?
aneuryzm
  • 63,052
  • 100
  • 273
  • 488
8
votes
4 answers

What is the behavior of C89 with respect to integer division of two negative numbers: round up, round down or not defined?

For Example, If I write int var; var=-8/-5; As per operator precedence, -8/-5 would be equivalent to ((-8)/(-5)). But will it be possible for C89 to give two values like for the case of -8/5 it can give -1 or -2. or It will treat it as the division…
8
votes
2 answers

Why should EDX be 0 before using the DIV instruction?

I noticed when EDX contains some random default value like 00401000, and I then use a DIV instruction like this: mov eax,10 mov ebx,5 div ebx it causes an INTEGER OVERFLOW ERROR. However, if I set edx to 0 and do the same thing it works. I believed…
Kanna Kim
  • 383
  • 1
  • 3
  • 15
8
votes
2 answers

Bug in glibc `div()` code?

As quoted in "Integer division rounding with negatives in C++", in C before C99 (i.e. in C89) and in C++ before C++11 (i.e. in C++98 and C++03), for an integer division computation where either operand is negative the sign of the remainder (or…
gx_
  • 4,690
  • 24
  • 31
8
votes
1 answer

Nasm Error: invalid combination of opcode and operands

In my quest to learn NASM, I am trying to create a really simple program that does a division and outputs the result. By the books, everything should run fine. I'm dividing 15 by 3, and it should automatically be stored in the AX register which I…
CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
7
votes
3 answers

Is it possible to get both the modulus and quotient of division in a single operation in C++?

I hear that when the processor does / or %, it will perform the same operation but one way it returns the quotient, the other way the remainder. Is it possible to get both in a single operation? Maybe if I throw in a snippet of assembly code (which…
mczarnek
  • 1,305
  • 2
  • 11
  • 24
7
votes
6 answers

Locating numerical errors due to Integer division

Is there a g++ warning or other tool that can identify integer division (truncation toward zero)? I have thousands of lines of code with calculations that inevitably will have numerical errors typically due to "float = int/int" that need to be…
user763322
  • 71
  • 2
7
votes
2 answers

Any way to do integer division in sympy?

I have a very long expression that I think can be simplified, and I thought sympy would be the perfect way to do it. Unfortunately the formula relies on a couple of integer divides, and I can't find any way to represent those in sympy. >>>…
Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
7
votes
5 answers

Dividing with/without using floats in C

Below is the main function I wrote in C (for PIC18F8722 microprocessor) attempting to drive 2 multiplexing 7 segments displays at a specific frequency set by the unsigned int function get_ADC_value(). The displays also display the current…
Psi
  • 268
  • 4
  • 13