javascript,jquery,jquery-ui,slider,multiplication

Most of the issues in your original jsFiddle traced back to bad JS var names; here is how you would achieve the desired effect: function update() { var bill_slider = $('#bill_slider').slider('value'); var yearly_bill = (bill_slider * 12) $("#monthly_bill").text(bill_slider); $("#yearly_bill").text(yearly_bill); } $("#bill_slider").slider({ value: 1, min: 0, max: 450, step: 5, slide:...

c++,c,multiplication,negative-number

Recommend to use what explains the code best, unless one is working with an old platform or compiler. In that case, use negation. Following are some obscure differences: int format with non-2's complement: In days of yore, a multiplication by of 0 and -1 could result in 0 yet a...

operator-overloading,rust,multiplication

I guess this should work: impl<N> BitOr<Matrix<N>> for Matrix<N> where N: Mul<N> { type Output = Matrix<<N as Mul<N>>::Output>; fn bitor(self, other: Matrix<N>) -> Matrix<<N as Mul<N>>::Output> { if self.width() != other.width() || self.height() != other.height() { panic!("Matrices need to have equal dimensions"); } let mut out = Matrix::new(self.width(), self.height());...

javascript,math,optimization,multiplication,bigint

I made an interactive example $(function() { var update = function() { var itemA = $("#nrA").val(); var itemB = $("#nrB").val(); var start = new Date().getTime(); var result = new BigNumber(itemA).multiply(itemB.toString()) var end = new Date().getTime(); var total = end - start; $("#fact").val(result); $("#time").val(total + " ms"); }; $("#nrA").on("input", function() {...

You currently have: uint64_t res = (uint32_t) a * (uint32_t) b; You will want to promote the arguments to 64bit numbers before the multiplication. Therefore: uint64_t res = (uint64_t) a * b; ...

c++,assembly,64bit,multiplication

If you're using gcc and the version you have supports 128 bit numbers (try using __uint128_t) than performing the 128 multiply and extracting the upper 64 bits is likely to be the most efficient way of getting the result. If your compiler doesn't support 128 bit numbers, then Yakk's answer...

java,math,multiplication,string-length

It's pretty simple. Next time please show the working of your code. public int findMultiplesOf3(String value) { return (value.length()/3); } Edit Any length of the string which is less than 3 or not divisible by 3, the return value will only be a whole number. (For Ex 22/3 = 7.333...

swift,floating-point,operators,multiplication

There is no implicit numeric conversion in swift, so you have to do explicit conversion when dealing with different types and/or when the expected type is different than the result of the expression. In your case, j is an Int whereas powf expects a Float, so it must be converted...

$results = array(); for ($i = 1; $i <= 10; $i++){ $results[] = $i * 17.5; } echo implode(' | ', $results); Or better echo implode(' | ', range(17.5, 17.5*10, 17.5)); ...

The Intel manual lists the following variants of IMUL: F6 /5 IMUL r/m8* M Valid Valid AX? AL * r/m byte. F7 /5 IMUL r/m16 M Valid Valid DX:AX ? AX * r/m word. F7 /5 IMUL r/m32 M Valid Valid EDX:EAX ? EAX * r/m32. REX.W + F7 /5...

matlab,matrix,multidimensional-array,matrix-multiplication,multiplication

Find the number of rows and columns of your final matrix: n = min(size(a,1), size(b,1)); m = min(size(a,1), size(b,1)); Then extract only the relevant sections of a and b (using the : operator) for your multiplication: c = a(1:n,1:m).*b(1:n,1:m) ...

Two things for your problem. First, here is the reason of your problem of multiplication: different types. I and so Gare of type uint8. H is of type double. When you perform the multiplication, Matlab seems to use the most restrictive type, so here uint8. So the result of Hist(2)*G(2)...

python,object,matrix,int,multiplication

You are treating m1 as a nested list of integers: result[i][j] += m1[i][k] * m2[k][j] # ^^^^^^^^ It is not; it is merely a simple list of integers. m1[i] then is an integer object and you cannot index integers: >>> [3, 4, 2][0] 3 >>> [3, 4, 2][0][0] Traceback (most...

See if this helps x=seq(1:5) # x # 1 2 3 4 5 lag_x = c(x[-1],NA) # lag_x # 2 3 4 5 NA y = x * lag_x # y # 2 6 12 20 NA ...

python,table,formatting,multiplication

Print out the table in a matrix like fashion, each number formatted to a width of 4 (The numbers are right-aligned and strip out leading/trailing spaces on each line). I think that following code may pass, according to the given rules. But it's only a guess as I'm not...

python,syntax,syntax-error,multiplication

A couple of issues on line userAnswer = ...: Missing parentheses at the end input requires a single argument In order to fix these, try this: userAnswer = int(input("What is: {} * {}? ".format(numOne, numTwo))) ...

c++,matrix,cuda,multiplication

Matrix multiply can be implemented in a variety of ways. Compared to a naive implementation of matrix multiply that only uses global memory, yes, it's possible to speed it up using texture memory. Compared to a better-written version of matrix multiply that uses shared memory, it's not likely that texture...

matlab,multidimensional-array,multiplication

Yes, it is possible to do without the for loop, but whether this leads to a speed-up depends on the values of M and N. Your idea of a generalized matrix multiplication is interesting, but it is not exactly to the point here, because through the repeated use of the...

javascript,algorithm,data-structures,multiplication

There are couple of mistakes in the way you have written the algorithm. Below code should work. function karatSuba(x,y) { var x1,x0,y1,y0,base,m; base = 10; if((x<base)||(y<base)){ console.log( " X - y = " , x,y, x*y) return x * y; } var dummy_x = x.toString(); var dummy_y = y.toString(); var...

The problem is that some floating point numbers can't be represented accurately. If you need to compare them, or a higher level of precision, use bcmul $num_1 = 14.7; $num_2 = bcmul(2.1, 7, 1); if((string)$num_1 == $num_2){ $eq = "Equal"; }else{ $eq = "Unequal"; } echo $num_1.", ".$num_2.", ".$eq."<br>"; ...

php,xml,for-loop,foreach,multiplication

This should work for you: (You have to cast the return of simplexml_load_file() to double) $url = "list.xml"; $xml = simplexml_load_file($url); $entries = $xml->results->rate; $count = 0; $total = 1; $number = array(); foreach($entries as $entry){ $count++; $number[$count] = $entry->Bid; $total *= (double)$number[$count]; } echo "Total: " . $total; ...

vhdl,multiplication,hdl,fixed-point

The result of multiplying 19+1 bits to 19+1 bits is 39+1 bits, while your port is 40+1 bit long. For example let's multiply maximum possible values for 19-bits: 0x7FFFF * 0x7FFFF = 0x3FFFF00001 - so it's 39 bits (19 + 19 + carry) for unsigned result and +1 bit for...

prolog,multiplication,successor-arithmetics

thanks @false for the hint to this post: Prolog successor notation yields incomplete result and infinite loop The referenced PDF doc in this post helps clarifying a number of features regarding peano integers and how to get simple arithmetic to work - pages 11 and 12 are particularly interesing: http://ssdi.di.fct.unl.pt/flcp/foundations/0910/files/class_02.pdf...

The "easiest" way would be to do something naive, like reading the file once fully to get the number of rows/cols, then reading the file again to actually store the values in the matrix: unsigned int rows = 0; unsigned int cols = 0; std::string line; while (std::getline(inFile, line)) {...

Compute the difference between the old and new node values, then use the addition logic to add that difference to the node value.

python,python-2.7,numpy,multiplication

One way is to use the outer function of np.multiply (and transpose if you want the same order as in your question): >>> np.multiply.outer(x, y).T array([[3, 6], [4, 8]]) Most ufuncs in NumPy have this useful outer feature (add, subtract, divide, etc.). As @Akavall suggests, np.outer is equivalent for the...

If count and numdata are integral: int or long the result again will be integral (integer division), so the fractions gets lost; truncated, not even rounded. As a probability is between 0.0 and 1.0, and so numdata >= count, you'll get only 0 or 1. Simplest would be to make...

python,arrays,numpy,shapes,multiplication

use numpy.linalg.solve. It solves Ax = b, which gives x = inv(A) b, but this is more stable than solving for inv(A) and then multiplying it by b.

c,64bit,32-bit,multiplication,fixed-point

assume you are trying to multiple two 32-bit int to a 64-bit result manually, in your macro, ((HIGH_WORD(a) * HIGH_WORD(b)) << 32 shifts beyond the length of a int, so you have that error. if you want to make it work, first change BIG_MULL to a function, and: cast to...

c,algorithm,math,multiplication,integer-division

Here's a solution heavily inspired by Hacker's Delight that really uses only bit shifts: def divu9(n): q = n - (n >> 3) q = q + (q >> 6) q = q + (q>>12) + (q>>24); q = q >> 3 r = n - (((q << 2) <<...

matlab,matrix,filter,multiplication

Try this: %// you have done this mask = a(2,:)<=4; %// taking 2nd row and masked cols and doing operations on those elements alone a(2,mask) = a(2,mask).*exp(-0.5); Results: Input: a = 1 2 3 4 4 5 6 2 Output: >> a a = 1.0000 2.0000 3.0000 4.0000 2.4261 5.0000...

The time complexity of the piece of code you supplied is, of course, O(1), because there is an upper bound on how long it can take and will never exceed that upper bound on any inputs. Presumably, that's not the answer to the question you actually mean to ask. There...

c++,arrays,if-statement,multiplication,n-dimensional

I don't know the function of C, but i presume it would work like this (thought process / logic only, not actual code) nums = array(1, 2, 3, 4, 5) output space for left display column of numbers foreach (nums as header) { // this hopefully builds the top of...

python,math,python-3.x,multiplication

The reason for the difference is that integers can be represented accurately in binary, whereas many decimal numbers cannot (given finite memory). The float 0.1 is an example of this: >>> "%.32f" % 0.1 '0.10000000000000000555111512312578' It's not exactly 0.1. So multiplying by the float 0.1 is not quite the same...

floating-point,julia-lang,multiplication

Some options: Use the inbuilt Rational type. The most accurate and fastest way would be 16//100 * 16//100 If you're using very big numbers these might overflow, in which case you can use BigInts instead, big(16)//big(100) * big(16)//big(100) (you don't actually need to wrap them all in bigs, as the...

Something like this maybe?: data.frame( Map(function(x,y) if(all(is.numeric(x),is.numeric(y))) x * y else x, df1, df2) ) # a b c d #1 alpha 7 x 40 #2 beta 16 y 55 #3 gamma 27 z 72 Some benchmarking: smp <- sample(1:4,50000,replace=TRUE) df1big <- df1[,smp] df2big <- df2[,smp] lmfun <- function() {...

assembly,optimization,bit-manipulation,division,multiplication

That method is called, "Division by Invariant Multiplication". The constants that you're seeing are actually approximates of the reciprocal. So rather than computing: N / D = Q you do something like this instead: N * (1/D) = Q where 1/D is a reciprocal that can be precomputed. Fundamentally, reciprocals...

java,user-interface,division,multiplication

Here's something simpler, but it essentially does what you want out of your program. I added an ActionListener to each of the buttons to handle what I want, which was to respond to what was typed into the textbox. I just attach the ActionListener to the button, and then in...

c++,optimization,bit-shift,multiplication

This question has been bugging me for the past few days, so I decided to do some more investigation. My initial answer focused on the difference in data values between the two tests. My assertion was that the integer multiplication unit in the processor finishes an operation in fewer clock...

matrix,cuda,multiplication,sparse,cublas

I don't think that you can classify a matrix with half zeros as "sparse": the timing you have found are reasonable (actually the sparse algorithm is behaving pretty well!). Sparse algorithms are efficient only when considering matrices where most of the elements are zeros (for example, matrices coming out from...

php,recursion,numbers,multiplication

I didn't follow the entire discussion in the comments but if that relationship is correct then it's just a simple math equation: $cost = 5.4; $price = $cost + ($price*0.105) + ($price*0.1); Move all the term that contain $price on the left hand side: $price - 0.105 * $price -...

If X can have at most n digits and Y can have at most m digits, then X < 10 ^ n and Y < 10 ^ m This means that X * Y < 10 ^ n * 10 ^ m = 10 ^ (n + m) In other...

sql,sql-server,sum,multiplication

This is the query which returns desired result: SELECT LoyaltyPointTable.LoyaltyType, CASE WHEN LoyaltyPointTable.LoyaltyPointsId=4 THEN (SELECT COUNT(amount) FROM RedeemPointsTable where CustomerId=1) ELSE COUNT(CustomerTable.CustomerId) END as UserActions, CASE WHEN LoyaltyPointTable.LoyaltyPointsId=4 THEN (SELECT SUM(amount) FROM RedeemPointsTable where CustomerId=1)*Points ELSE SUM(LoyaltyPointTable.Points) END as TotalPoints FROM LoyaltyPointTable JOIN LoyaltyDetailsTable ON LoyaltyPointTable.LoyaltyPointsId =...

public String multiply(String ¢) { int $=0,_=¢.length(); while(0<=--_)$+=(¢.charAt(_)-0x30)<<(_&01l); return Integer.toString($); } ...

We paste the 'Channel' and substring of 'Hour' column together ('nm1'), concatenate the 'TV1Slope' and 'TV5Slope' vectors ('TV15'), match the 'nm1 vector with names of 'TV15' after removing the 'Slope' substring with sub, and get the corresponding 'TV15' value. Subset the columns with names starting with 'cols' using grep, do...

The result you are getting is not an error. It is simply in a formatting you don't expect / know yet. 7.959E-5is exactly the same as 0.00007959 it is just a different way of writing it down. Think of it as 7.959E-5 = 7.959 × (10 ^ (-5)) = 0.00007959....

c#,encryption,encoding,biginteger,multiplication

The problem is that reversing the arrays is not enough. Because they are unsigned they also require padding depending on the value at the end of the array. If the value at the end of the array is >= 128 the high bit of that value is set and the...

How about this : l1 = [1, 2, 3] l2 = [10, 100, 1000] l3 = [ x*y for x in l1 for y in l2] ...

python,matrix,pandas,multiplication

You could also use cartesian function from scikit-learn: from sklearn.utils.extmath import cartesian # Your data: df1 = pd.DataFrame({'quality1':list('ABC'), 'value':[1,2,3]}) df2 = pd.DataFrame({'quality2':list('DEF'), 'value':[1,10,100]}) # Make the matrix of labels: dfm = pd.DataFrame(cartesian((df1.quality1.values, df2.quality2.values)), columns=['quality1', 'quality2']) # Multiply values: dfm['value'] = df1.value.values.repeat(df2.value.size) * pd.np.tile(df2.value.values, df1.value.size) print dfm.set_index(['quality1', 'quality2'])...

vhdl,multiplication,equation,signed

Since x and y are of datatype signed, you can multiply them. However, there is no multiplication of signed with real. Even if there was, the result would be real (not signed or integer). So first, you need to figure out what you want (the semantics). Then you should add...

floating-point,verilog,multiplication

When you run this you should be getting warnings along the lines of: Port size (16 or 16) does not match connection size (64) for port 'a'. The port definition is at: calc.sv(2). Fora,b and o, as you have defined them as 16 bits and reals are 64 bits. Just...

You need {0:0.00} instead of {0:2} for your format specifier. Console.Write("Enter the circle's radius r: "); double r = double.Parse(Console.ReadLine()); double perim = (2 * Math.PI * r); double area = (Math.PI * (Math.Pow(r, 2))); Console.WriteLine("The circle perimeter is: {0:0.00}", perim); Console.WriteLine("The circle area is: {0:0.00}", area); For more info...

arrays,assembly,multiplication

So it turned that Phil was correct. I was rewriting my own data. The trick was to read the value, do the multiplication using bit shift, add the carry (if any) and only then write back to the array. This way I can multiply each element, by two and not...

It doesn't really get any faster than that, these are your options: numpy.outer >>> %timeit np.outer(a,b) 100 loops, best of 3: 9.79 ms per loop numpy.einsum >>> %timeit np.einsum('i,j->ij', a, b) 100 loops, best of 3: 16.6 ms per loop numba from numba.decorators import autojit @autojit def outer_numba(a, b): m...

python,python-2.7,multiplication

There is no need to reinvent the wheel. Use itertools.permutations to create 5-permutations of the digits, then check the result. import itertools for O, T, I, S, P in itertools.permutations((1,2,3,4,5,6,7,8,9), 5): OTTO = 1000 * O + 100 * T + 10 * T + O STOP = 1000 *...

I'm of the opinion implementing a Montgomery multiplier in numeric_std function calls may not improve simulation as much as you'd like (while giving synthesis eligibility). The issue is the number of dynamically elaborated subprogram calls vs. their operand sizes vs. fitting in your CPU-running-Modelsim's L1/L2/L3 caches. It does do wonders...

python,formatting,multiplication,presentation

You can add a dictionary with the operator descriptions: op_symbols = { add: '+', mul: '*', sub: '-', } and instead of str(op), use op_symbols[op]...

arrays,matlab,matrix,matrix-multiplication,multiplication

you can simply do mt = [1:n].'*[1:m] to achieve the matrix you desire. Otherwise, you have some syntax issues in the example code you posted....

python,algorithm,multiplication

The error is this one: f1 = Multiply(s1, pow2(n)) It should be: f1 = Multiply(s1, pow2(2*m)) Indeed, (a1*2^m+a0)*(b1*2^m+b0)=(a1*b1)*2^(2m) + (a0*b1+a1*b0)*2^m + (a0*b0) If n > (2*m), that is for an odd n, then you are doing things incorrectly......

c#,type-conversion,multiplication

You've got an integer overflow, since whenever you multiply two int you have int: this is interpreted as Int32 so far a * b * c * d * ee * f * g * h * i * j * k * l * m and only than converted...

jquery,input,sum,each,multiplication

Ok, this is how i figured out googoling and searching on other post on this site JSFIDDLE IS HERE, hope can help someone else: <div class="page"> <ul> <li>Quantità: <span><input type="text" name="Quantita" value="" class="quantita"></span></li> <li>Valore unitario: <span><input type="text" name="ValoreUnitario" value="" class="valore"></span></li> <li> Valore totale: <span><input type="text" name="ValoreTotale" value="0.00"...

python,matrix,vector,multiplication

The length of your second for loop is len(v) and you attempt to indexing v based on that so you got index Error . As a more pythonic way you can just use list comprehension and zip function : >>> from operator import mul >>> l,g=[1,0,0,1,0,0], [[0,1],[1,1],[1,0],[1,0],[1,1],[0,1]] >>> z=zip(*g) >>>...

c,formatting,output,multiplication,spaces

Here is a simple example of how to make constant length printouts using printf: int main(void) { char a[6][7]={"1","22","333","4444","55555","666666"}; int i; int value; for(i=0;i<sizeof(a)/sizeof(a[0]);i++) { value = atoi(a[i]); printf("%07d\n", value); //with leading zeros printf("% 7d\n", value); //with spaces } getchar(); return 0; } Here is the output: ...

javascript,for-loop,multiplication

You don't need another var. You can just use x*2. JavaScript is smart enough to evaluate the result and add it to the string as you would expect. "2 × " + x + " = " + x*2 + "<br />" Few notes: To denote "times" (like: "a times...

matlab,matrix,vectorization,multiplication

This could be one approach - %// Pre-processing part [m,n,r] = size(x) %// Get size N = m*n %// number of elements in one 3D slice %// ------------- PART 1: Get indices for each 3D slice %// Get the first mxm block of kron-corresponding indices and then add to %//...