(Redirected from () * () (block))

"Times" redirects here. For other uses, see Time (disambiguation).
() * ()
(() * ())
Category Operators
Type Reporter
Introduced in 11Oct03 (0.x)

The () * () block is an Operators Block and a Reporter Block. It multiplies the numbers in its two given arguments together and reports the result.

Example Uses

The block is mainly used for calculations where multiplication is needed.

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

  • Scripts that require calculations
set [result v] to ((a) * (b))
  • Score multipliers
set [score v] to ((score) * (2))
  • Switching positive and negative values around.
set [my variable v] to ((my variable) * (-1))
  • Math formulas
([sqrt v] of ((((y1) - (y2)) * ((y1) - (y2))) + (((x1) - (x2)) * ((x1) - (x2))))) //Pythagorean Theorem
  • 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
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
  • Calculating factorials
when gf clicked
ask (Number) and wait
set [counter v] to (answer)
repeat ((answer) - (1))
change [counter v] by [-1]
set [output v] to ((output) * (counter))

Workaround

Main article: List of Block Workarounds


A workaround can be made for the () * () block by instead diving by the reciprocal.

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

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

set [product v] to [0]
repeat (b) // where b should be a whole number (not negative and does not have a decimal)
    change [product v] by (a)
end

The following code accepts negative numbers with decimals:

delete all of [num1 numbers v]
delete all of [num2 numbers v]
delete all of [product digits v]
set [dec pos 1 v] to [0]
set [count v] to [0]
repeat (length of (a))
    change [count v] by (1)
    if <not<(letter (count) of (a)) = [-]>> then
        if <(letter (count) of (a)) = [.]> then
            set [dec pos 1 v] to ((length of (a)) - (count))
        else
            add (letter (count) of (a)) to [num1 numbers v]
        end
    end
end
set [dec pos 2 v] to (0)
set [count v] to (0)
repeat (length of (b))
    change [count v] by (1)
    if <not <(letter (count) of (b)) = [-]>> then
        if <(letter (count) of (b)) = [.]> then
            set [dec pos 2 v] to ((length of (b)) - (count))
        else
            add (letter (count) of (b)) to [num2 numbers v]
        end
    end
end
set [num1 v] to (num1 numbers)
set [num2 v] to (num2 numbers)
set [product v] to [0]
repeat (num1)
    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
repeat until <[0] < ((length of [product digits v]) - ((decimal position) - (1)))>
    insert (0) at (1) of [product digits v]
end
insert [.] at ((length of [product digits v]) - ((decimal position) - (1))) of [product digits v]
if <not <<(a) < [0]> = <(b) < [0]>>> then
    insert [-] at (1) of [product digits v]
end
set [product v] to ((product digits) + (0))

See Also

Cookies help us deliver our services. By using our services, you agree to our use of cookies.