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
10
votes
2 answers

Division by zero not causing runtime exception on Nvidia Jetson

I'm not very familiar with the internal details of ARM processors, but I do not understand the following behaviour on my Nvidia Jetson Nano dev board. C code sample ... //main.c #include int main() { int fred = 123; int i; …
user5069935
10
votes
7 answers

Causing a divide overflow error (x86)

I have a few questions about divide overflow errors on x86 or x86_64 architecture. Lately I've been reading about integer overflows. Usually, when an arithmetic operation results in an integer overflow, the carry bit or overflow bit in the FLAGS…
Channel72
  • 24,139
  • 32
  • 108
  • 180
10
votes
1 answer

Javascript: Is This Truly Signed Integer Division

Given the following code, where both a and b are Numbers representing values within the range of signed 32-bit signed integers: var quotient = ((a|0) / (b|0))|0; and assuming that the runtime is in full compliance with the ECMAScript 6…
lcmylin
  • 2,552
  • 2
  • 19
  • 31
10
votes
1 answer

Integer division compared to floored quotient: why this surprising result?

The // "integer division" operator of Python surprised me, today: >>> math.floor(11/1.1) 10.0 >>> 11//1.1 9.0 The documentation reads "(floored) quotient of x and y". So, why is math.floor(11/1.1) equal to 10, but 11//1.1 equal to 9?
Eric O. Lebigot
  • 91,433
  • 48
  • 218
  • 260
10
votes
3 answers

Python remainder operator

Is there any remainder operator in Python? I do not ask for modulo operator, but remainder. For example: -5 mod 2 = 1 but -5 rem 2 = -1 # where "rem" is a remainder operator. Do I have to implement it by myself ;)?
Dejwi
  • 4,393
  • 12
  • 45
  • 74
10
votes
4 answers

Integer division & modulo operation with negative operands in Python

Questions arise when I type in these expressions to Python 3.3.0 -10 // 3 # -4 -10 % 3 # 2 10 // -3 # -4 10 % -3 # -2 -10 // -3 # 3 It appears as though it takes the approximate floating point (-3.33)? and rounds down either way in integer…
tlands_
  • 176
  • 1
  • 10
9
votes
2 answers

What's the point of Raku's 'mod' operator?

I previously incorrectly thought that the % operator returned the remainder and the mod operator returned the modulus (the remainder and modulus are the same when the operands are both positive or both negative but differ when one operand is…
codesections
  • 8,900
  • 16
  • 50
9
votes
0 answers

What is integer division heavily used for?

An analysis on https://ridiculousfish.com/blog/posts/benchmarking-libdivide-m1-avx512.html finds that the new Apple CPU has spent a lot of resources making integer division massively faster. This is a surprising thing to do. In my experience,…
rwallace
  • 31,405
  • 40
  • 123
  • 242
9
votes
1 answer

Can integer division ever over/underflow, assuming the denominator <>0?

Can (true) integer division ever over/underflow (with the assumption that the denominator is not 0)? Since the value is always either staying the same or getting smaller (since, in integer division, the smallest absolute non-zero denominator is 1,…
Qix - MONICA WAS MISTREATED
  • 14,451
  • 16
  • 82
  • 145
9
votes
5 answers

Fast floor of a signed integer division in C / C++

In C a floor division can be done, eg: int floor_div(int a, int b) { int d = a / b; if (a < 0 != b < 0) { /* negative output (check inputs since 'd' isn't floored) */ if (d * a != b) { /* avoid modulo, use multiply instead */ …
ideasman42
  • 42,413
  • 44
  • 197
  • 320
9
votes
2 answers

ColdFusion too big to be an integer

I am trying to convert a large number going in to Megabytes. I don't want decimals numeric function formatMB(required numeric num) output="false" { return arguments.num \ 1024 \ 1024; } It then throws an error How do I get around this?
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
9
votes
2 answers

Obtaining remainder using single aarch64 instruction?

I am writing some assembly code for ARM8 (aarch64). I want to do a division and use the remainder obtained for further calculations. In x86 when I use 'div', and I know my remainder is kept in RDX. My question is - is there an equivalent to that in…
c_mnon
  • 366
  • 4
  • 14
9
votes
6 answers

Is "long x = 1/2" equal to 1 or 0, and why?

if I have something like: long x = 1/2; shouldn't this be rounded up to 1? When I print it on the screen it say 0.
user69514
  • 26,935
  • 59
  • 154
  • 188
9
votes
2 answers

Why does -103/100 == -2 but 103/100 == 1 in Python?

Why does -103/100 == -2 but 103/100 == 1 in Python? I can't seem to understand why.
frazras
  • 5,928
  • 4
  • 30
  • 40
9
votes
5 answers

What determines the sign of m % n for integers?

The modulo in Python is confusing. In Python, % operator is calculating the remainder: >>> 9 % 5 4 However: >>> -9 % 5 1 Why is the result 1? and not -4?
user1864828
  • 349
  • 1
  • 3
  • 10