Questions tagged [multiplication]

Multiplication is the mathematical operation of scaling one number by another. It is an elementary operation of most programming languages and is typically denoted by the symbol *.

Multiplication is the mathematical operation of scaling one number by another.

It is an elementary arithmetic operation in most programming languages along with addition, subtraction, division and sometimes modulo.

It is typically denoted by * (asterisk symbol) in programming, and × (cross symbol) in math.

Example (math): multiplication of numbers 3 and 4

3 × 4 = 12

See also: Multiplication on Wikipedia

2530 questions
44
votes
4 answers

How can a query multiply 2 cell for each row MySQL?

I want to multiply 2 cells for each row and put the value of that in the last column called Total. Can this be done by a normal query? Example: Pieces | Price | Total 6 | 4 | null // should be 24 2 | 10 | null // should be 10
Arne Nouwynck
  • 495
  • 1
  • 4
  • 6
43
votes
5 answers

Getting the high part of 64 bit integer multiplication

In C++, say that: uint64_t i; uint64_t j; then i * j will yield an uint64_t that has as value the lower part of the multiplication between i and j, i.e., (i * j) mod 2^64. Now, what if I wanted the higher part of the multiplication? I know that…
Matteo Monti
  • 8,362
  • 19
  • 68
  • 114
43
votes
3 answers

Python and Powers Math

I've been learning Python but I'm a little confused. Online instructors tell me to use the operator ** as opposed to ^ when I'm trying to raise to a certain number. Example: print 8^3 Gives an output of 11. But what I'm look for (I'm told) is more…
Interrupt
  • 965
  • 3
  • 9
  • 16
42
votes
1 answer

Variables Multiplication for the factorial calculation

I'm making a script that calculates the factorial for a given number, but I'm having some problems with the multiplication. Note: the factorial for is given by: 9!=9*8*7*6*5*4*3*2*1 Here's my code: #!/bin/bash echo "Insert an Integer" read…
UraniumSnake
  • 465
  • 1
  • 4
  • 7
40
votes
14 answers

How to multiply in Javascript? problems with decimals

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…
gustavomanolo
  • 787
  • 1
  • 9
  • 18
37
votes
2 answers

Why do these two multiplication operations give different results?

Why do I need to add an "L" letter to get the correct long value? And what is the other value? long oneYearWithL = 1000*60*60*24*365L; long oneYearWithoutL = 1000*60*60*24*365; System.out.println(oneYearWithL);//gives correct calculation result :…
fareed
  • 3,034
  • 6
  • 37
  • 65
35
votes
2 answers

C# decimal multiplication strange behavior

I noticed a strange behavior when multiplying decimal values in C#. Consider the following multiplication operations: 1.1111111111111111111111111111m * 1m = 1.1111111111111111111111111111 // OK 1.1111111111111111111111111111m * 2m =…
user1126360
  • 403
  • 1
  • 4
  • 8
31
votes
3 answers

What's the best C++ way to multiply unsigned integers modularly safely?

Let's say that you are using and types like std::uint8_t and std::uint16_t, and want to do operations like += and *= on them. You'd like arithmetic on these numbers to wrap around modularly, like typical in C/C++. This ordinarily works,…
Myria
  • 3,372
  • 1
  • 24
  • 42
31
votes
5 answers

Pandas: Elementwise multiplication of two dataframes

I know how to do element by element multiplication between two Pandas dataframes. However, things get more complicated when the dimensions of the two dataframes are not compatible. For instance below df * df2 is straightforward, but df * df3 is a…
Zhubarb
  • 11,432
  • 18
  • 75
  • 114
30
votes
9 answers

Fast multiplication/division by 2 for floats and doubles (C/C++)

In the software I'm writing, I'm doing millions of multiplication or division by 2 (or powers of 2) of my values. I would really like these values to be int so that I could access the bitshift operators int a = 1; int b = a<<24 However, I cannot,…
B. Decoster
  • 7,723
  • 1
  • 32
  • 52
30
votes
10 answers

How can I perform multiplication, using bitwise operators?

I am working through a problem which I was able to solve, all but for the last piece—I am not sure how one can do multiplication using bitwise operators: 0*8 = 0 1*8 = 8 2*8 = 16 3*8 = 24 4*8 = 32 Is there an approach to solve this?
James Raitsev
  • 92,517
  • 154
  • 335
  • 470
30
votes
3 answers

Strassen's algorithm for matrix multiplication

Can someone please explain strassen's algorithm for matrix multiplication in an intuitive way? I've gone through (well, tried to go through) the explanation in the book and wiki but it's not clicking upstairs. Any links on the web that use a lot of…
29
votes
2 answers

JavaScript multiplying by 100 giving weird result

I have: var a = 0.0532; var b = a * 100; b should be returning 5.32 but instead it's returning 5.319999999999999. How do I fix this? JSFiddle here: http://jsfiddle.net/9f2K8/
user3213420
  • 351
  • 1
  • 5
  • 11
26
votes
2 answers

MUL function in assembly

I am trying to execute simple multiplication in Assembly. However, I do not see the registers change when the MUL function is called. mov bx, 5 mov cx, 10 mul cx
James Clark
  • 301
  • 1
  • 5
  • 7
25
votes
3 answers

Quickly square a double

I am looking for the fastest way to square a double (double d). So far I came up with two approaches: 1. d*d 2. Math.pow(d, 2) To test the performance I set up three test cases, in each I generate random numbers using the same seed for the three…
Samuel
  • 18,286
  • 18
  • 52
  • 88