Computer Science, asked by divyasankar960, 1 month ago

Math.floor(x / Math.pow(2, y)) Which of the below expressions works faster and produces the same result? We can assume both x and y are positive integers.

Answers

Answered by rohithspacejet
0

Answer:

floor is fast because floor is easy than power calculation also it wont be exact

Answered by vishakasaxenasl
0

Answer:

Math.floor(x) is faster as compared to Math.pow(2,y)

Explanation:

floor() function

floor() function is used to round the given digit into an integer. It simply ignores the decimal part of the digit and stores only the mantissa part.

for example:

num = 25.32

print(Math.floor(num))

#output: 25

pow() function

pow() function is used to calculate the power of the number under the given range.

For example:

num = 5

print(Math.pow(5,3))

#output: 125

The floor () function is faster than the pow function because it does not perform any complex and long computation while the pow function takes more time to compute the power by multiplying the number to itself under the given range.

#SPJ2

Similar questions