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

divdi3 division used for long long by gcc on x86

When gcc sees multiplication or division of integer types that isn't supported in hardware, it generates call to special library function. http://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html#Integer-library-routines According link…
user2718551
  • 33
  • 1
  • 5
3
votes
2 answers

Faster way for any number(16bit) divide by 3 in assembly without DIV opcode

I want to divide a unsigned integer by 3, in 8086 assembly or similar , any way to do it faster which I dont want to use DIV opcode.
Kent Liau
  • 915
  • 15
  • 26
3
votes
3 answers

Efficiently converting 16-bits short to 8-bits char

I'm working on a Cortex M0 cpu, which doesn't have hardware division, so every time I divide something, the GCC libary function is used. Now one of the division I do the most is dividing by 256, to convert shorts into bytes. Is there some way I can…
Maestro
  • 9,046
  • 15
  • 83
  • 116
3
votes
4 answers

Avoiding floating point arithmetic

I wrote a small software synth for the iPhone. To further tune performance I measured my application with Shark and found that I am losing a lot of time in float/SInt16 conversions. So I rewrote some parts to get around the conversions by…
3
votes
2 answers

JSP EL div operator - strange behavior

I have this strange behavior in my JSP page: I have two Integer variables count and size. When I print the values of these variables to the page I'm getting 266 100 but when I use ${count div size} or ${count / size} I'm getting 2.66. I checked…
Betlista
  • 10,327
  • 13
  • 69
  • 110
2
votes
3 answers

Unsigned and signed division in C

In my program two variables are declared as signed long (let say X and Y on 32 bit machine) and these divided one by other(X/Y). The final value is assigned to a unsigned long variable(Let say Z). I am not sure whether this is right or wrong…
rakeeee
  • 973
  • 4
  • 19
  • 44
2
votes
2 answers

Can someone clarify why the value of a variable in my loop is not updating until the loop is closed?

This is my function def rating(array) sum_count = array.values.inject(0) { |sum_count,value| sum_count + value } run_count = 0 array.each do |tag,count| run_count += count cum_distn = run_count/sum_count logger.debug "cum_distn is…
socratic_singh
  • 183
  • 1
  • 13
2
votes
2 answers

How to calculate division remainder in SPARC Assembly?

Here is the pseudo code which computes division of two positive integers. HR register saves remainder, and LR saves dividend. (and eventually saves root) However I think this algorithm has some problem. Because this algorithm sometimes don't…
manutd
  • 564
  • 9
  • 22
2
votes
1 answer

Do you convert signed integers to hex before doing an `idiv` in 64-bit Intel CPUs?

Suppose you want to divide -198077031546722079779 by 23 using gas. As this dividend is larger than %rax, how do you put it in %rdx:%rax? All the books I read on assembly avoid illustrating idiv with examples, so I am lost.
ntos
  • 189
  • 10
2
votes
1 answer

Can the x87 perform exact division on UNsigned QUADword integers?

The 8086/8087/8088 MACRO ASSEMBLY LANGUAGE REFERENCE MANUAL (c) 1980 Intel Corporation mentions (Emphasis mine): ... the 8087 provides a very good approximation of the real number system. It is important to remember, however, that it is not an…
Sep Roland
  • 33,889
  • 7
  • 43
  • 76
2
votes
0 answers

How do constants for signed division differ from unsigned division when using reciprocal multiplication in assembly?

While using Godbolt Compiler, I was playing around with various functions when I checked what signed division looks like using the following code: int div10(int num) { return num / 10; } Where the num/10 section generated the following assembly…
2
votes
1 answer

Get a integer if there are no significant digits after decimal or get a float if there are significant digits after decimal in python

I was recently doing a question on geeks for geeks website where they required median of two sorted arrays, but they are asking answer to be a int if there are no digits after decimals or a float if there are digits after decimals. For example when…
2
votes
2 answers

How to set a number of loop 'for' as a parameter of a function in python to find all the possibility to cut a period in n parts?

Here is a ugly code to find all the possibilities to cut a period in 5 parts. Is there a possibility to create a function which makes it look better, with the number of cut as a parameter ? I am only abble to write each for loop : part_list =…
Shanki
  • 21
  • 4
2
votes
2 answers

How do these two while loops to separate an integer into digits work?

The code is about to separate an integer into digits, the code works, but I am having trouble with how the two "while" work together. #include int main() { int num, temp, factor = 1; printf("Enter a 5 digit number: "); …
2
votes
2 answers

Why is there a loop in this division as multiplication code?

I got the js code below from an archive of hackers delight (view the source) The code takes in a value (such as 7) and spits out a magic number to multiply with. Then you bitshift to get the results. I don't remember assembly or any math so I'm sure…
Cal
  • 121
  • 8