Discuss Scratch
- Discussion Forums
- » Suggestions
- » Mathematical operations
- TheRailwayNoob87
-
100+ posts
Mathematical operations
Example project: Mini Calculator by TheRailwayNoob87
I would like to have better mathematical operators on Scratch. Although there are partly simple workarounds I would personally prefer these operators as own reporters on Scratch. Here are the 3 most requested operators and their workarounds:
1.: a^b - any number powered by a value
2.: (a)√b - any root of a number
3.: log(a) of (b) - logarithm of a number with any base
Although there are these workarounds, I really hope that Scratch will soon add these operators (especially the first 2 ones). The first one needs many loops and calculations (so it could get slow inside of a bigger project) and the second one has other numbers for a (not even and not even integers) for which in case of b<0 the result is undefined.
And I also hope this post was understandable.
_________________________________________________________________________________
Your TheRailwayNoob87, the very awesome and friendly Scratcher, who is regularly active.
A math joke: What happened to Windows 9?
—> 7 8 9. (read it out loud)
I would like to have better mathematical operators on Scratch. Although there are partly simple workarounds I would personally prefer these operators as own reporters on Scratch. Here are the 3 most requested operators and their workarounds:
1.: a^b - any number powered by a value
define (a)^(b)
if <(a) = [0]> then
// case 0^b
if <(b) = [0]> then
// case 0^0
set [result v] to [N]
// N = undefined
else
set [result v] to [0]
end
else
set [i v] to ([abs v] of (a))
set [i v] to ([e ^ v] of ((b)*([ln v] of (i))))
if <(a) < [0]> then
set [i v] to ([1]/(k))
// case negative numbers
end
set [result v] to (i)
end
2.: (a)√b - any root of a number
define (a)√(b)
if <((a) mod [2]) = [0]> then
// case even root and b<0 (there are other roots with undefined value at b<0, but they have no pattern)
if <(b) < [0]> then
set [result v] to [N]
// N = undefined
else
set [result v] to ([e ^ v] of (([ln v] of (b)) * ((1) / (a))))
end
else
set [result v] to ([e ^ v] of (([ln v] of (b)) * ((1) / (a))))
end
3.: log(a) of (b) - logarithm of a number with any base
define log(a) of (b)
set [result v] to (([log v] of (b))/([log v] of (a)))
Although there are these workarounds, I really hope that Scratch will soon add these operators (especially the first 2 ones). The first one needs many loops and calculations (so it could get slow inside of a bigger project) and the second one has other numbers for a (not even and not even integers) for which in case of b<0 the result is undefined.
And I also hope this post was understandable.
_________________________________________________________________________________
Your TheRailwayNoob87, the very awesome and friendly Scratcher, who is regularly active.
A math joke: What happened to Windows 9?
—> 7 8 9. (read it out loud)
Last edited by TheRailwayNoob87 (July 29, 2021 17:07:12)
- Discussion Forums
- » Suggestions
-
» Mathematical operations