division

Assembler 64b division

浪子不回头ぞ 提交于 2019-12-05 02:40:10
问题 I need some easy way to divide 64b unsigned integers in assembler for x86. My number is saved in two 32b registers EDX:EAX and I need to put result back to EDX:EAX. Factor is in 32b integer. Some code, please? 回答1: If I interpret your question correctly (particularly the part Factor is in 32b integer ), you want to divide a 64-bit dividend by a 32-bit divisor and get a 64-bit quotient. If that interpretation is correct, then it's actually easy to do in 32-bit code. The idea is that you divide

Exact difference between div and quot

故事扮演 提交于 2019-12-05 02:22:06
In this question here on SO the differences between the two operators div and quot are mentioned as well as the fact that the quot operator is more efficient than the div operator, whereas div is more natural for us humans to use. My question is what the exact implementations of the two operators are and linked to that what the difference between implementations is. Also I want to know how the speed difference between those two comes to be, as using Hoogle and browsing the sources did not help me in my quest to understanding. I want to clarify that I understand the general difference between

How to divide tiny double precision numbers correctly without precision errors?

隐身守侯 提交于 2019-12-05 00:55:43
I'm trying to diagnose and fix a bug which boils down to X/Y yielding an unstable result when X and Y are small: In this case, both cx and patharea increase smoothly. Their ratio is a smooth asymptote at high numbers, but erratic for "small" numbers. The obvious first thought is that we're reaching the limit of floating point accuracy, but the actual numbers themselves are nowhere near it. ActionScript "Number" types are IEE 754 double-precision floats, so should have 15 decimal digits of precision (if I read it right). Some typical values of the denominator (patharea): 0.0000000002119123 0

Why is math.floor(x/y) != x // y for two evenly divisible floats in Python?

依然范特西╮ 提交于 2019-12-04 23:50:56
I have been reading about division and integer division in Python and the differences between division in Python2 vs Python3. For the most part it all makes sense. Python 2 uses integer division only when both values are integers. Python 3 always performs true division. Python 2.2+ introduced the // operator for integer division. Examples other programmers have offered work out nice and neat, such as: >>> 1.0 // 2.0 # floors result, returns float 0.0 >>> -1 // 2 # negatives are still floored -1 How is // implemented? Why does the following happen: >>> import math >>> x = 0.5 >>> y = 0.1 >>> x

Float divison and casting in Swift

可紊 提交于 2019-12-04 23:46:09
I'm trying to learn Swift and I made a simple average function: func average(numbers: Int...) -> Float { var sum = 0 for number in numbers { sum += number } return Float(sum)/Float(numbers.count) } average(1,2,3,4,5,6) This gives me the correct result: 3.5 However, I am wondering why I have to cast both sum and numbers.count to floats. I tried casting this way: return Float(sum/numbers.count) but it gives me just 3.0 First, you should use Double and not Float. Float gives you very limited precision. Why you would want 6 digits precision with Float when you could have 15 digits with Double is

Newton-Raphson Division With Big Integers

∥☆過路亽.° 提交于 2019-12-04 23:30:05
问题 I'm making a BigInt class as a programming exercise. It uses a vector of 2's complement signed ints in base-65536 (so that 32-bit multiplications don't overflow. I will increase the base once I get it fully working). All of the basic math operations are coded, with one problem: division is painfully slow with the basic algorithm I was able to create. (It kind of works like binary division for each digit of the quotient... I'm not going to post it unless someone wants to see it....) Instead of

How to find the remainder of a division in C?

不羁岁月 提交于 2019-12-04 18:05:17
问题 Which is the best way to find out whether the division of two numbers will return a remainder? Let us take for example, I have an array with values {3,5,7,8,9,17,19}. Now I need to find the perfect divisor of 51 from the above array. Is there any simpler way to solve this? 回答1: You can use the % operator to find the remainder of a division, and compare the result with 0 . Example: if (number % divisor == 0) { //code for perfect divisor } else { //the number doesn't divide perfectly by divisor

Change displayable labels for a JSlider?

做~自己de王妃 提交于 2019-12-04 13:08:16
I have a JSlider with a min of 0 and a max of 10,000. I have the major tick marks set at 1,000. If I were to paint the labels now they would show up as 0, 1000, 2000, 3000, 4000, etc. What I would like to be shown would be 0, 1, 2, 3, 4, 5, etc. What would be a good way to accomplish this task? using JSlider.setLabelTable(Dictionary) EDIT Alternatively you can rely on predefined label UI and just change the label text: Enumeration e = jSlider.getLabelTable().keys(); while (e.hasMoreElements()) { Integer i = (Integer) e.nextElement(); JLabel label = (JLabel) jSlider.getLabelTable().get(i);

Double precision in C - printing 50 significant figures yields inaccurate values

末鹿安然 提交于 2019-12-04 12:32:26
I'm doing an integration program with Riemann sums for my Calculus class. I've decided to use C when computing my integrals, and I noticed a huge error in my program that derives from this problem. #include <stdio.h> #include <stdlib.h> #include <math.h> int main(int argc, char** argv) { double x = 2.0/20.0; printf("%1.50f \n", x); return (EXIT_SUCCESS); } The program gives me : 0.10000000000000000555111512312578270211815834045410. My question: Why does this happen? And how can I fix this? Or at least round off to ~15 decimal places? Thanks for the help. The basics of floating-point: http://en

How does division work in MIX?

纵饮孤独 提交于 2019-12-04 07:38:57
Can someone explain to me how division in MIX (from TAOCP by Knuth) works on a byte-to-byte basis? rA = |-| . . . .0| rX = |+|1235|0|3|1| The memory location 1000 contains |-|0|0|0|2|0| . When you execute the operation DIV 1000 the registers become rA = |+|0|617|?|?| rX = |-|0|0|0|?|1| Now I understand the signs on rA and rX , but in what order are the bytes of rAX filled and which divisions are done? If DIV 1000 leads to every bit divided by 2, then I would expect rAX = |+|617|0|1|0|-|0|1|0|1|1| in which rA contains the division results and rX the remainders (filled from the right side). I'm