Question

Please do in Haskell programming language. Write a function intLog of type Integer -> Integer that...

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.

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
10. Write a function in HASKELL howManyBelowAverage that returns how many of three integer inputs are...
10. Write a function in HASKELL howManyBelowAverage that returns how many of three integer inputs are below its average value. (Hint: utilize the averageThree function.) howManyBelowAverage :: Integer -> Integer -> Integer -> Integer averageThree :: Integer -> Integer -> Integer -> Float AverageThree x y z = fromInteger(x+y+z) / 3.0 Can someone please help me solve the howManyBelowAverage function?
Programming in C language (not C++) Write a main function with a function call to a...
Programming in C language (not C++) Write a main function with a function call to a function called Calculation which has two integer arguments/ parameters. The function returns a character. Declare and initialize the necessary data variables and assign balues needed to make it executable and to prevent loss of information. //input 2 integer values //returns the characterequivalent of the higher of the two integer values char Calculation(int, int);
Programming Languages Write an ML function call ch. This function takes a tuple of length 4...
Programming Languages Write an ML function call ch. This function takes a tuple of length 4 and returns “yes” if the second element is greater than the first; otherwise, it returns "no". The function need not behave properly if there are less than or more than 4 elements; $ ch (4,5,6,7); no $ ch (7,9,8,4); yes
FOR C PROGRAMMING LANGUAGE Write a recursive C PROGRAMMING LANGUAGE function int sumStrlens(const char* str1, const...
FOR C PROGRAMMING LANGUAGE Write a recursive C PROGRAMMING LANGUAGE function int sumStrlens(const char* str1, const char* str2) which returns the sum of strlen(str1) and strlen(str2). You can assume that strlen(str2) is always strictly greater than strlen(str1) (strlen(str2) > strlen(str1)). You MAY NOT use any function from string.h. You MAY NOT use any square brackets([]) or any type of loops in function.
Using C++ Write a template function that accepts an integer parameter and returns its integer square...
Using C++ Write a template function that accepts an integer parameter and returns its integer square root. The function should return -1, if the argument passed is not integer. Demonstrate the function with a suitable driver program .
In C programming language write a function that takes an integer n as input and prints...
In C programming language write a function that takes an integer n as input and prints the following pattern on the screen: 1 (n times) 2 (n-1 times) .n (1 time) For example, if n was 5, the function should print 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will implement Queue Abstract Data Type with the following functions/methods.  Any build-in/pre-defined Queue function/library (e.g., java.util.Queue in Java) is NOT allowed to use in your code. push(Element):  insert the input Element (e.g., String or Integer in Java) to the end of the queue. pop(): remove the head element of the queue and print the head element on screen. count():  return the total number of elements in the queue...
***************PLEASE GIVE ANSWERS IN RACKET PROGRAMMING LANGUAGE ONLY****************** Write a recursive Racket function "update-if" that takes...
***************PLEASE GIVE ANSWERS IN RACKET PROGRAMMING LANGUAGE ONLY****************** Write a recursive Racket function "update-if" that takes two functions, f and g, and a list xs as parameters and evaluates to a list. f will be a function that takes one parameter and evaluates true or false. g will be a function that takes one parameter and evaluates to some output. The result of update-if should be a list of items such that if x is in xs and (f x)...
C programming 3. Write a do-while loop that displays: 0,10,20,30,40 4.Write nested for loops that displays...
C programming 3. Write a do-while loop that displays: 0,10,20,30,40 4.Write nested for loops that displays three rows of asterisks: ***** ***** ***** 5. Write a complete program that reads a set of integers using scant() until a sentinel value of -99 is read. Once that value is read, display the sum of the value read, exclusive of the -99. 6.Write a procedure(function, method named times10() that accepts an integer argument and displays the result of multiplying the argument by...
-RACKET LANGUAGE ONLY- Write a non-recursive Racket function "keep-short-norec" that takes an integer and a list...
-RACKET LANGUAGE ONLY- Write a non-recursive Racket function "keep-short-norec" that takes an integer and a list of strings as parameters and evaluates to a list of strings. The resulting list should be all strings on the original list, maintaining their relative order, whose string length is less than the integer parameter. For example, (keep-short-rec 3 '("abc" "ab" "a")) should evaluate to '("ab" "a") because these are the only strings shorter than 3. Your solution must not be recursive. You will...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT