multiplying

Where can I find soft-multiply and divide algorithms?

不想你离开。 提交于 2019-12-03 23:51:46
I'm working on a micro-controller without hardware multiply and divide. I need to cook up software algorithms for these basic operations that are a nice balance of compact size and efficiency. My C compiler port will employ these algos, not the the C developers themselves. My google-fu is so far turning up mostly noise on this topic. Can anyone point me to something informative? I can use add/sub and shift instructions. Table lookup based algos might also work for me, but I'm a bit worried about cramming so much into the compiler's back-end...um, so to speak. Here's a simple multiplication

Find sum of subset with multiplication

佐手、 提交于 2019-12-03 20:07:29
Let's say we have got a set {a_1, a_2, a_3, ..., a_n} The goal is to find a sum that we create in the following way: We find all subsets whose length is 3, then multiply each subset's elements (for the subset {b_1, b_2, b_3} the result will be b_1*b_2*b_3 ). At the end we sum up all these products. I am looking for a shortest time-execution algorithm. Example SET: {3, 2, 1, 2} Let S be our sum. S = 3*2*1 + 3*2*2 + 2*1*2 + 3*1*2 = 28 It is easier to calculate sum of multiplied triplets when repetitions are allowed (like a_1*a_1*a_1). This sum is just (sum^3) . Since repetitions are not allowed,

How to multiply in Javascript? problems with decimals

旧城冷巷雨未停 提交于 2019-12-03 18:57:17
问题 i've the following code in Javascript: var m1 = 2232.00; var percent = (10/100); var total = percent*m1; alert(total); The problem is that the variable "total" gives me "223.20000000000002" and it should be "223.2", what should i do to get the correct value? 回答1: .toFixed() is best solution.It will keep only two digits after dot. Exp 1: var value = 3.666; value.toFixed(2); //Output : 3.67 Exp 2: var value = 3.0000; value.toFixed(2); //Output : 3.00 回答2: You can't get the exact value. This is

imul assembly instruction - one operand?

一个人想着一个人 提交于 2019-12-03 11:16:05
I am using a run-time debugger. EAX: 0000 0023 EDX: 5555 5556 imul edx EAX: aaaa aac2 EDX: 0000 000b I am utterly confused, and can't figure out how this multiply is working. What's happening here? I notice in a similar question here that imul ebx ; result in EDX:EAX I don't understand the EDX:EAX notation though :/ Chris Taylor When the one-operand form of imul is passed a 32 bit argument (as in your case with EDX ) it effectively means EAX * EDX where both EAX and EDX are 32 bit registers. The product of two 32 bit values doesn't necessarily fit in 32 bits: the full multiply result can take

How to Multiply / Sum with Javascript [closed]

有些话、适合烂在心里 提交于 2019-12-02 14:35:58
https://jsbin.com/wujusajowa/1/edit?html,js,output I can sum the numbers of options. Like (5+5+5=15) But I don't know a way to multiply the input with the sum of selects. For example, What should I do to do 6 x (5+5+5) and get 90 ? Use <input type="number"> , define a global variable to store value of <input> ; attach change event to <input> element to update global variable; use variable at change event of <select> element if variable is defined, else use 1 as multiplier var input = 0; $('select').change(function(){ var sum = 0; $('select :selected').each(function() { sum += Number($(this)

Squaring number in c++, Kaprekar numbers [duplicate]

早过忘川 提交于 2019-12-02 07:20:30
问题 This question already has answers here : Multiplication of two integers in C++ (3 answers) Closed 3 years ago . Found this issue in C++ while detecting Kaprekar numbers in a range. For number 77778 - unsigned long long sq = pow(n, 2); returns 6,049,417,284 while unsigned long long sq = n * n; returns 1,754,449,988 Any ideas why? Is this some sort of overflow which pow avoids but normal n*n does not. 回答1: Assuming your n to be typical int or unsigned int , the reason for this is because this

How do I multiply lists together using a function?

只愿长相守 提交于 2019-12-02 02:12:58
how do I multiply lists together in python using a function? This is what I have: list = [1, 2, 3, 4] def list_multiplication(list, value): mylist = [] for item in list: for place in value: mylist.append(item*value) return mylist So I want to use this to multiply list*list (1*1, 2*2, 3*3, 4*4) So the output would be 1, 4, 9, and 16. How would I do this in python where the 2nd list could be anything? Thanks My favorite way is mapping the mul operator over the two lists: from operator import mul mul(2, 5) #>>> 10 mul(3, 6) #>>> 18 map(mul, [1, 2, 3, 4, 5], [6, 7, 8, 9, 10]) #>>> <map object at

Multiply a data frame row-by-row

和自甴很熟 提交于 2019-12-01 22:48:01
问题 Input file: df1 <- data.frame(row.names=c("w","x","y","z"), A=c(0,0,0,0), B=c(0,1,0,0), C=c(1,0,1,0), D=c(1,1,1,1)) A B C D w 0 0 1 1 x 0 1 0 1 y 0 0 1 1 z 0 0 0 1 I want to apply an equation i.e. multiply row w to row x to get the pairwise value for w-x pair, as follows: A B C D w 0 0 1 1 X x 0 1 0 1 -------------- wx 0 0 0 1 to get row-wise analysis for w-x, w-y, w-y, w-z, x-y, x-z, y-z. and generate a new dataframe with 6 columns (two row names followed by the multiplied values). That's w

Multiply a data frame row-by-row

╄→尐↘猪︶ㄣ 提交于 2019-12-01 21:34:17
Input file: df1 <- data.frame(row.names=c("w","x","y","z"), A=c(0,0,0,0), B=c(0,1,0,0), C=c(1,0,1,0), D=c(1,1,1,1)) A B C D w 0 0 1 1 x 0 1 0 1 y 0 0 1 1 z 0 0 0 1 I want to apply an equation i.e. multiply row w to row x to get the pairwise value for w-x pair, as follows: A B C D w 0 0 1 1 X x 0 1 0 1 -------------- wx 0 0 0 1 to get row-wise analysis for w-x, w-y, w-y, w-z, x-y, x-z, y-z. and generate a new dataframe with 6 columns (two row names followed by the multiplied values). That's w x 0 0 0 1 w y 0 0 1 1 w z 0 0 0 1 x y 0 0 0 1 x z 0 0 0 1 y z 0 0 0 1 Thanksssssss. If you don't want

How to stretch checkbox item the full width of the combobox

我是研究僧i 提交于 2019-12-01 21:11:41
I have a multiply combobox with checkbox items <ComboBox x:Name="cmb" IsEditable="True" IsReadOnly="True" DropDownClosed="cmb_DropDownClosed"> <ComboBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <CheckBox Content="{Binding NmColumn }" HorizontalAlignment="Stretch" IsChecked="{Binding Path=bChecked, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Tag="{Binding IdColumn}" /> </StackPanel> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> When I click on checkbox all is well. But if the checkbox width less than the width of combobox, when I click to the right of the