multiplication

.NET multiplication optimization

Does the compiler optimize out any multiplications by 1? That is, consider: int a = 1; int b = 5 * a; Will the expression 5 * a be optimized into just 5? If not, will it if a is defined as: const int a = 1; ...

Russian Peasant Multiplication

Here is my short implementation of Russian Peasant Multiplication. How can it be improved? Restrictions : only works when a>0,b>0 for(p=0;p+=(a&1)*b,a!=1;a>>=1,b<<=1); ...

Matrix implementation benchmarks, should I whip myself?

Hello. I'm trying to find out some matrix multiplication/inversion benchmarks online. My C++ implementation can currently invert a 100 x 100 matrix in 38 seconds, but compared to this benchmark I found, my implementation's performances really suck. I don't know if it's a super-optimized something or if really you can easily invert a 200 ...

Multiplying 23 bit datatypes in a system with no long long

I am trying to implement floating point operations in a microcontroller and so far I have had ample success. The problem lies in the way I do multiplication in my computer and it works fine: unsigned long long gig,mm1,mm2; unsigned long m,m1,m2; mm1 = f1.float_parts.mantissa; mm2 = f2.float_parts.mantissa; m1 = f1.float_parts.mantiss...

Fast Fourier Transform - Multiplying Polynomials?

Hi guys, i just don't understand how to perform a FFT on two polynomials such as X^2+1 and X+1...can anyone step by step go through the process with me? Thanks very much ...

C language: #DEFINEd value messes up 8-bit multiplication. Why?

I have the following C code: #define PRR_SCALE 255 ... uint8_t a = 3; uint8_t b = 4; uint8_t prr; prr = (PRR_SCALE * a) / b; printf("prr: %u\n", prr); If I compile this (using an msp430 platform compiler, for an small embedded OS called contiki) the result is 0 while I expected 191. (uint8_t is typedef'ed as an unsigned char) If I ch...

Understanding Schönhage-Strassen algorithm (huge integer multiplication)

Hi, I need to multiply several 1000s digits long integers as efficiently as possible in Python. The numbers are read from a file. I am trying to implement the Schönhage-Strassen algorithm for integer multiplication, but I am stuck on understanding the definition and mathematics behind it, specially the Fast Fourier Transform. Any help ...

How do you multiply two 64-bit numbers in x86 assembler?

Possible Duplicate: How can I multiply two 64bit numbers using x86 assembly language? How do you multiply two 64-bit numbers in x86 assembler? This question is important for historical reasons. Presumably, Joel meant 386 assembler. Related question How do you multiply two 64bit numbers in assembly ...

Javascript multiplication w/value stored in another cell.

Update: Final Fix: $('.gasamount').sum(); var num = $(this).attr("id").replace(/[A-Za-z$,-]/g, ""); $('#gasmoney'+num).val(<cfoutput>#mileage#</cfoutput> * $(this).val()); $('.gasmoney').sum(); What I've been trying to accomplish: Create a set value for a row of cells. Multiply the user's value by a stored amount. Get th...

What's better multiplication by 2 or adding the number to itself ? BIGnums

I need some help deciding what is better performance wise. I'm working with bigints (more then 5 million digits) and most of the computation (if not all) is in the part of doubling the current bigint. So i wanted to know is it better to multiply every cell (part of the bigint) by 2 then mod it and you know the rest. Or is it better just...

Multiplying two 32 bit numbers without using 64 bit int ...

We are doing some 32bit * 32bit multiplication using the following algorithm Let us we want to multiply a (32 bit) with b (32 bit), both signed, a = ah * 2^16 + al [ah - Higher 16 bits, al - Lower 16 bits] b = bh * 2^16 + bl [bh - Higher 16 bits, bl - Lower 16 bits] We are effectively doing Result = (al * bl) + (((ah * bl) + (al * b...

C : erroneous output for "(long long int) = (long long int) * (double)"?

long long int A = 3289168178315264; long long int B = 1470960727228416; double D = sqrt(5); long long int out = A + B*D; printf("%lld",out); This gives result : -2147483648 I am not able to figure out why (it should be a positive result). Can somebody help? ...

Is there an easy way to find two values that, when multiplied together, produce an exact bit pattern?

For testing purposes, I need to find two 64-bit integer values that exactly multiply to a 128-bit intermediate value with a specific bit pattern. Obviously, I can generate the desired intermediate value and divide by random values until I find a combination that works, but is there a more efficient way? ...

JQuery Multiplication of 2 selects

Folks, I'm trying to multiple the values of 2 select dropdowns whenever either of them are changed and then display that value. This is what I have (which of course doesn't work) - Any ideas? TIA! EDIT EDIT EDIT EDIT EDIT EDIT Thanks everyone for the help - I've updated the JQuery to reflect the attempts I've made based on all your ...

Fast Multiplication

Hi! I'm writing code for a microprocessor with fast integer arithmetic and not so fast float arithmetic. I need to divide an integer by a number from 1 to 9 and convert result back to integer. I made a float array with members like 0, 1, 0.5, 0.3333 etc. But i think there is MAGIC constants (like 0x55555556) for a numbers except (1/3)....

Matrix Multiplication To Rotate An Image In C#

I need to write a program that uses matrix multiplication to rotate an image (a simple square), based on the center of the square, a certain amount of degree based on what I need. Any help on this would be greatly appreciated. I almost have no clue as to what I'm doing because I have not taken so much as a glance at Calculus. ...

.Net and multiplication of singles

Can anyone explain this weirdness: Dim result as single = 0 result = CType("8.01", Single) * 100 ' result=801.0 as expected result = CType("8.02", Single) * 100 ' result=802.000061 --- not expected Further to the above result = 8.02 * 100 ' result = 802.0 as expected ...

quick/fast integer multiplication in ruby?

Hi there, I am trying to make a quick/efficient Mandelbrot implementation in Ruby. A long long time ago, one way to speed it up was using fixed point integers instead of floats. So i made the following benchmark, comparing float and integer raising to a square, using multiplication or square ** operand. require 'benchmark' Benchmark....

matrix multiplication for integral types using BLAS

Is there an equivalent of dgemm (from BLAS) for integral types? I only know of dgemm, sgemm for double precision / single precision matrices, but would like to have it for matrices that are of integral type such as int (or short int...). Note: I'm not looking for a solution that involves converting to float/double, and am looking for a ...

Python long multiplication

I'm in need of an algorithm faster than the current normal python long multiplication , I tried to find a decent karatsuba implementation , but I can't. def main(): a=long(raw_input()) if(a<0): a=a*-1 a=((a*(a+1)/2)-1) print(-a) else: a=(a*(a+1))/2 print(a) main() As you see , it's nothing complica...