division

How to let GCC compiler turn variable-division into mul(if faster)

瘦欲@ 提交于 2019-12-02 11:22:42
问题 int a, b; scanf("%d %d", &a, &b); printf("%d\n", (unsigned int)a/(unsigned char)b); When compiling, I got ... ::00401C1E:: C70424 24304000 MOV DWORD PTR [ESP],403024 %d %d ::00401C25:: E8 36FFFFFF CALL 00401B60 scanf ::00401C2A:: 0FB64C24 1C MOVZX ECX,BYTE PTR [ESP+1C] ::00401C2F:: 8B4424 18 MOV EAX,[ESP+18] ::00401C33:: 31D2 XOR EDX,EDX ::00401C35:: F7F1 DIV ECX ::00401C37:: 894424 04 MOV [ESP+4],EAX ::00401C3B:: C70424 2A304000 MOV DWORD PTR [ESP],40302A %d\x0A ::00401C42:: E8 21FFFFFF CALL

An unexpected result about divide in C [duplicate]

别等时光非礼了梦想. 提交于 2019-12-02 10:43:16
问题 This question already has answers here : What is the behavior of integer division? (5 answers) Closed 4 years ago . My goal is to output the average of the input number and its reversal. When I input 974, the result is 726.0 instead of 726.5. I have think about this problem for long time but I still cannot get the answer. Hope someone can help me. Thank you very much! #include <stdio.h> int main(void) { int N, D1, D2, D3; double aver; scanf("%d", &N); D1 = N % 10; D2 = ((N - D1) / 10) % 10;

Division with really big numbers

£可爱£侵袭症+ 提交于 2019-12-02 10:05:02
问题 I was just wondering what different strategies there are for division when dealing with big numbers. By big numbers, I mean ~50 digit numbers . e.g. 9237639100273856744937827364095876289200667937278 / 8263744826271827396629934467882946252671 When both numbers are big, long division seems to lose its usefulness... I thought one possibility is to count through multiplications of the divisor until you go over the dividend, but if it was the dividend in the example above divided by a small number

JavaScript simple calculation

时光毁灭记忆、已成空白 提交于 2019-12-02 09:56:25
I'm pretty sure I'm being stupid but why isn't this working!? form.find( '.per_time' ).on( 'change', function() { var price = parseInt( form.find( '.section-price' ).attr('data-price'), 10 ) ; var multiplier = parseInt( $( this ).val(), 10 ); var newprice = (price / 7) * multiplier; form.find( '.section-price .price' ).html( newprice ) }) It's this line I'm concerned about: var newprice = (price / 7) * multiplier; The calculation is not dividing by 7, it only calculates price * multiplier ? This code also seems to be dictating what happens but I'm pretty sure it's jsut a shorter version of the

Division on the fly [duplicate]

最后都变了- 提交于 2019-12-02 08:54:31
问题 This question already has answers here : Trouble with calling method [duplicate] (2 answers) Closed 5 years ago . I'm trying to make a small program in Java which converts Fahrenheit to Celsius. It involves deducting 32 and multiplying by 5/9. So I did this. double Fahrenheit = 100; double celsius = (Fahrenheit - 32) * (5/9); System.out.println(celsius); But for some reason that 5/9 returns zero which ruins it all, even double s = 5/9; returns zero and I don't know why. The only way I found I

How to do division in ARM?

自作多情 提交于 2019-12-02 07:56:45
I m trying to find how to make a division in ARM since there is no DIV command. If that can be done by multiplication of a float number [/9 = *0.09] , by subtraction or by the use of a library. Any way would do. Currently I am doing division using subtraction using a loop like this but I loose the decimals: MOV R0,#70 ;Fahrenheit Temperature SUB R1,R0,#32 ; Subtracting 32 MOV R4,#0 ;Counter LOOP ADD R4,R4,#1; Counter+1 ->Is the answer of the division without decimals SUB R1,#9 CMP R1,#0 BPL LOOP MOV R1,R4 So basically what I am doing is that I have temperature 70, I subtract 32 and I get 38.

How to divide each row of a calculated column by the total of another calculated column?

醉酒当歌 提交于 2019-12-02 07:55:58
问题 I can't get a division correct with this sample data: Calculated column Another calc. column 48 207 257 370 518 138 489 354 837 478 1,005 648 1,021 2,060 1,463 2,164 2,630 1,818 2,993 2,358 3,354 3,633 4,332 5,234 4,885 6,108 4,514 6,008 4,356 6,888 4,824 7,382 7,082 5,988 7,498 6,059 4,865 4,192 3,816 2,851 2,768 2,093 2,207 770 397 149 178 336 167 124 18 What I'm trying to do is to create a new calculated column. For each row I want to get the value of Calculated column and divide it by the

An unexpected result about divide in C [duplicate]

人走茶凉 提交于 2019-12-02 07:41:57
This question already has an answer here: What is the behavior of integer division? 5 answers My goal is to output the average of the input number and its reversal. When I input 974, the result is 726.0 instead of 726.5. I have think about this problem for long time but I still cannot get the answer. Hope someone can help me. Thank you very much! #include <stdio.h> int main(void) { int N, D1, D2, D3; double aver; scanf("%d", &N); D1 = N % 10; D2 = ((N - D1) / 10) % 10; D3 = (N - D1 - D2) / 100; aver = (D1*100 + D2*10 + D3 + N) / 2; printf("%lf", aver); return 0; } In your code, N , D1 , D2 ,

Divide columns in a DataFrame by a Series (result is only NaNs?)

夙愿已清 提交于 2019-12-02 07:03:35
I'm trying to do a similar thing to what is posted in this question: Python Pandas - n X m DataFrame multiplied by 1 X m Dataframe I have an n x m DataFrame, with all non-zero float values, and a 1 x m column, with all non-zero float values, and I'm trying to divide each column in the n x m dataframe by the values in the column. So I've got: a b c 1 2 3 4 5 6 7 8 9 and x 11 12 13 and I'm looking to return: a b c 1/11 2/11 3/11 4/12 5/12 6/12 7/13 8/13 9/13 I've tried a multiplication operation first, to see if I can make it work, so I tried applying the two solutions given in the answer to the

Binary divisibility by 10

一笑奈何 提交于 2019-12-02 06:48:44
问题 How to check if a binary number can be divided by 10 (decimal), without converting it to other system. For example, we have a number: 1010 1011 0100 0001 0000 0100 How we can check that this number is divisible by 10? 回答1: First split the number into odd and even bits (I'm calling "even" the bits corresponding to even powers of 2): 100100110010110000000101101110 0 1 0 1 0 0 1 0 0 0 1 1 0 1 0 even 1 0 0 1 0 1 1 0 0 0 0 0 1 1 1 odd Now in each of these, add and subtract the digits alternately,