Please do in Haskell programming language. Write a function intLog of type Integer -> Integer that returns the exponent of the largest power of 2 less than its integer argument. Your function need not behave well if the parameter is negative. Try your function on intLog 468.
intLog :: (Integer) -> (Integer)
intLog (a) = (x) where
x = (floor . logBase 2.0 . fromIntegral)
(a-1)
main = do
print(intLog (468))
OUTPUT - 8
intLog function accepts the argument as a returns output by
x.
the function finds the exponent of the largest power of 2 less than
its integer argument using the log.
Floor performs the conversion in the opposite direction (from
Fractional to Integral), as shown by its type.
fromIntegral call makes the type of the parameter compatible with
what the compiler expects, as well as the use of 2.0 (a Fractional
literal) for the base.
//THANK YOU
Get Answers For Free
Most questions answered within 1 hours.