Curiouscrab (talk | contribs) (added main template for workarounds) |
TheTrillion (talk | contribs) (No need to do ::reporter, just use parenthesis. Also, made the "!" in Snap! in italics.) |
||

(43 intermediate revisions by 21 users not shown) | |||

Line 1: | Line 1: | ||

− | {{ | + | {{block |

|name = () * () | |name = () * () | ||

− | |image = | + | |image = (() * ()) |

− | |||

|category = [[Operators Blocks|Operators]] | |category = [[Operators Blocks|Operators]] | ||

|type = [[Reporter Block|Reporter]] | |type = [[Reporter Block|Reporter]] | ||

|defaults = Blank insert; blank insert | |defaults = Blank insert; blank insert | ||

+ | |sb=yes | ||

}} | }} | ||

− | The '''() * ()''' [[block]] is an [[Operators | + | The '''() * ()''' [[Blocks|block]] is an [[Operators Block]] and a [[Reporter Block]]. The block multiplies the two values and reports the result. In [[Snap!|Snap''!'']], it will be shown as () × (). |

The numbers can be typed directly into the block, or Reporter blocks can be used instead. | The numbers can be typed directly into the block, or Reporter blocks can be used instead. | ||

Line 13: | Line 13: | ||

This block can be stacked inside itself - this can be used to fit more numbers in or calculate exponents. | This block can be stacked inside itself - this can be used to fit more numbers in or calculate exponents. | ||

− | == | + | ==Example Uses== |

+ | In many [[project]]s, numbers must be multiplied; this block will do the job. | ||

− | + | Some common uses for the () * () block: | |

− | <scratchblocks>(( | + | * Scripts in calculator simulations |

+ | <scratchblocks> | ||

+ | set [result v] to ((a) * (b)) | ||

+ | </scratchblocks> | ||

+ | * Multiplying lists of numbers | ||

+ | <scratchblocks> | ||

+ | set [result v] to (1) | ||

+ | set [item v] to (1) | ||

+ | repeat (length of [numbers v]) | ||

+ | set [result v] to ((result) * (item (item) of [numbers v])) | ||

+ | change [item v] by (1) | ||

+ | end | ||

+ | </scratchblocks> | ||

+ | * Math formulas | ||

+ | <scratchblocks> | ||

+ | ([sqrt v] of ((((y1) - (y2)) * ((y1) - (y2))) + (((x1) - (x2)) * ((x1) - (x2))))) //Pythagorean Theorem | ||

+ | </scratchblocks> | ||

+ | * Score multipliers | ||

+ | <scratchblocks> | ||

+ | set [score v] to ((score) * (2)) | ||

+ | </scratchblocks> | ||

+ | * [[Velocity]] | ||

+ | <scratchblocks> | ||

+ | when gf clicked | ||

+ | set [velocity v] to [0] | ||

+ | forever | ||

+ | if <key [space v] pressed?> then | ||

+ | change [velocity v] by (2) | ||

+ | set [velocity v] to ((velocity) * (0.87)) //simulates friction slowdown | ||

+ | </scratchblocks> | ||

+ | * [[Three-Dimensional Projects|3D]] Projects | ||

+ | |||

+ | ==Scientific Notation== <!-- Can anyone reproduce/confirm this? --> | ||

+ | In [[Scratch 1.4]] and previous versions, it sometimes converts very large numbers into scientific notation to save space. Scientific notation is simply the number in the form a*10<sup>b</sup>. These can be converted to a normal number by performing any mathematical function on it, such as adding. So if a [[variable]] named "number" has a value of 3*10<sup>3</sup> and you want to display it as a normal number, you can change it by: | ||

+ | <scratchblocks>((number) + (0))</scratchblocks> | ||

It will then report "3000". | It will then report "3000". | ||

==Workaround== | ==Workaround== | ||

− | {{ | + | {{main|List of Block Workarounds}} |

With natural numbers, this block can be replicated with the following code, assuming a is the first number and b is the second number: | With natural numbers, this block can be replicated with the following code, assuming a is the first number and b is the second number: | ||

Line 29: | Line 64: | ||

</scratchblocks> | </scratchblocks> | ||

− | The following code works for all cases (with the conditional). | + | The following code works for all cases (with the conditional). It divides by the reciprocal, the equivalent of multiplying. |

<scratchblocks> | <scratchblocks> | ||

− | if<(b) = (0)> | + | if <(b) = (0)> then |

set [product v] to [0] | set [product v] to [0] | ||

else | else | ||

− | set [product v] to ((a)/((1)/(b))) | + | set [product v] to ((a) / ((1) / (b))) |

end | end | ||

</scratchblocks> | </scratchblocks> | ||

Line 41: | Line 76: | ||

<scratchblocks> | <scratchblocks> | ||

− | delete | + | delete all of [num1 numbers v] //setup |

− | delete | + | delete all of [num2 numbers v] |

− | delete | + | delete all of [product digits v] |

set [product v] to [0] | set [product v] to [0] | ||

set [dec pos 1 v] to [0] | set [dec pos 1 v] to [0] | ||

set [dec pos 2 v] to [0] | set [dec pos 2 v] to [0] | ||

ask [num1] and wait | ask [num1] and wait | ||

− | if <(answer) < [0]> | + | if <(answer) < [0]> then |

set [count v] to [1] | set [count v] to [1] | ||

set [no 1 negative v] to [y] | set [no 1 negative v] to [y] | ||

Line 57: | Line 92: | ||

repeat (length of (answer)) | repeat (length of (answer)) | ||

change [count v] by (1) | change [count v] by (1) | ||

− | if <not <(letter (count) of (answer)) = [.]>> | + | if <not <(letter (count) of (answer)) = [.]>> then |

add (letter (count) of (answer)) to [num1 numbers v] | add (letter (count) of (answer)) to [num1 numbers v] | ||

else | else | ||

Line 64: | Line 99: | ||

end | end | ||

ask [num2] and wait | ask [num2] and wait | ||

− | if <(answer) < [0]> | + | if <(answer) < [0]> then |

set [count v] to [1] | set [count v] to [1] | ||

set [no 2 negative v] to [y] | set [no 2 negative v] to [y] | ||

Line 73: | Line 108: | ||

repeat (length of (answer)) | repeat (length of (answer)) | ||

change [count v] by (1) | change [count v] by (1) | ||

− | if <not <(letter (count) of (answer)) = [.]>> | + | if <not <(letter (count) of (answer)) = [.]>> then |

add (letter (count) of (answer)) to [num2 numbers v] | add (letter (count) of (answer)) to [num2 numbers v] | ||

else | else | ||

Line 90: | Line 125: | ||

add (letter (count) of (product)) to [product digits v] | add (letter (count) of (product)) to [product digits v] | ||

end | end | ||

− | if <not <(decimal position) = [0]>> | + | if <not <(decimal position) = [0]>> then |

insert [.] at ((length of [product digits v]) - ((decimal position) - (1))) of [product digits v] | insert [.] at ((length of [product digits v]) - ((decimal position) - (1))) of [product digits v] | ||

end | end | ||

− | if <<<(no 1 negative) = [y]> or <(no 2 negative) = [y]>> and <not <<(no 1 negative) = [y]> and <(no 2 negative) = [y]>>>> | + | if <<<(no 1 negative) = [y]> or <(no 2 negative) = [y]>> and <not <<(no 1 negative) = [y]> and <(no 2 negative) = [y]>>>> then |

insert [-] at (1 v) of [product digits v] | insert [-] at (1 v) of [product digits v] | ||

end | end | ||

set [product v] to (product digits) | set [product v] to (product digits) | ||

</scratchblocks> | </scratchblocks> | ||

− | |||

− | |||

− | |||

− | |||

− | |||

− | |||

− | |||

− | |||

==See Also== | ==See Also== | ||

− | *[[() + () (block)|() + ()]] | + | * [[() + () (block)|() + ()]] |

− | *[[() - () (block)|() - ()]] | + | * [[() - () (block)|() - ()]] |

− | *[[() | + | * [[() / () (block)|() / ()]] |

{{Operators Blocks}} | {{Operators Blocks}} | ||

+ | |||

[[Category:Operators Blocks]] | [[Category:Operators Blocks]] | ||

+ | [[de:()*() (Block)]] | ||

+ | [[id:() * () (balok)]] | ||

+ | [[ja:() * () (ブロック)]] | ||

+ | [[zh:Zho:() 乘 ()（积木）]][[ru:() * () (блок)]] |

## Latest revision as of 01:32, 28 May 2021

() * () | |

(() * ()) | |

Category |
Operators |

Type |
Reporter |

The **() * ()** block is an Operators Block and a Reporter Block. The block multiplies the two values and reports the result. In Snap*!*, it will be shown as () × ().

The numbers can be typed directly into the block, or Reporter blocks can be used instead.

This block can be stacked inside itself - this can be used to fit more numbers in or calculate exponents.

## Example Uses

In many projects, numbers must be multiplied; this block will do the job.

Some common uses for the () * () block:

- Scripts in calculator simulations

set [result v] to ((a) * (b))

- Multiplying lists of numbers

set [result v] to (1) set [item v] to (1) repeat (length of [numbers v]) set [result v] to ((result) * (item (item) of [numbers v])) change [item v] by (1) end

- Math formulas

([sqrt v] of ((((y1) - (y2)) * ((y1) - (y2))) + (((x1) - (x2)) * ((x1) - (x2))))) //Pythagorean Theorem

- Score multipliers

set [score v] to ((score) * (2))

when gf clicked set [velocity v] to [0] forever if <key [space v] pressed?> then change [velocity v] by (2) set [velocity v] to ((velocity) * (0.87)) //simulates friction slowdown

- 3D Projects

## Scientific Notation

In Scratch 1.4 and previous versions, it sometimes converts very large numbers into scientific notation to save space. Scientific notation is simply the number in the form a*10^{b}. These can be converted to a normal number by performing any mathematical function on it, such as adding. So if a variable named "number" has a value of 3*10^{3} and you want to display it as a normal number, you can change it by:

((number) + (0))

It will then report "3000".

## Workaround

*Main article: List of Block Workarounds*

With natural numbers, this block can be replicated with the following code, assuming a is the first number and b is the second number:

set [product v] to [0] repeat (b) change [product v] by (a)

The following code works for all cases (with the conditional). It divides by the reciprocal, the equivalent of multiplying.

if <(b) = (0)> then set [product v] to [0] else set [product v] to ((a) / ((1) / (b))) end

The following code accepts negative numbers with decimals:

delete all of [num1 numbers v] //setup delete all of [num2 numbers v] delete all of [product digits v] set [product v] to [0] set [dec pos 1 v] to [0] set [dec pos 2 v] to [0] ask [num1] and wait if <(answer) < [0]> then set [count v] to [1] set [no 1 negative v] to [y] else set [count v] to [0] set [no 1 negative v] to [n] end repeat (length of (answer)) change [count v] by (1) if <not <(letter (count) of (answer)) = [.]>> then add (letter (count) of (answer)) to [num1 numbers v] else set [dec pos 1 v] to ((length of (answer)) - (count)) end end ask [num2] and wait if <(answer) < [0]> then set [count v] to [1] set [no 2 negative v] to [y] else set [count v] to [0] set [no 2 negative v] to [n] end repeat (length of (answer)) change [count v] by (1) if <not <(letter (count) of (answer)) = [.]>> then add (letter (count) of (answer)) to [num2 numbers v] else set [dec pos 2 v] to ((length of (answer)) - (count)) end end set [num1 v] to (num1 numbers) set [num2 v] to (num2 numbers) repeat (num1) //start change [product v] by (num2) end set [decimal position v] to ((dec pos 1) + (dec pos 2)) set [count v] to [0] repeat (length of (product)) change [count v] by (1) add (letter (count) of (product)) to [product digits v] end if <not <(decimal position) = [0]>> then insert [.] at ((length of [product digits v]) - ((decimal position) - (1))) of [product digits v] end if <<<(no 1 negative) = [y]> or <(no 2 negative) = [y]>> and <not <<(no 1 negative) = [y]> and <(no 2 negative) = [y]>>>> then insert [-] at (1 v) of [product digits v] end set [product v] to (product digits)

## See Also

() + ()
• () - () • () * () • () / () • Pick Random () to () • () < () • () = () • () > () • () and () • () or () • Not () • Join ()() • Letter () of () • Length of () • () Mod () • Round () • () of ()More blocks... |