following the bit-level floating-point coding rules, implement the function with the following prototype:
/* Compute |f|- If f is NaN, then return f. */
float_bits float_absval(float_bits f);
For floating-point number f, this function computes |f|. If f is NaN, your function should simply return f.
Test your function by evaluating it for all 232 values of argument f and comparing the result to what would be obtained using your machine’s floating-point operations.
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Computer Systems: Program... -Access
Additional Engineering Textbook Solutions
Starting Out with Java: Early Objects (6th Edition)
Introduction to Programming Using Visual Basic (10th Edition)
Programming in C
Digital Fundamentals (11th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
- In C, write a function int setbit(int n, int i) to set the i^ᵗʰ bit of n if i^ᵗʰ bit is 0.arrow_forwardimplement anyEvenBit(x) Return 1 if any even bit in x is set to 1 you are only allowed to use the following eight operators: ! ~ & ^ | + << >> “Max ops” field gives the maximum number of operators you are allowed to use to implement each function /* * anyEvenBit - return 1 if any even-numbered bit in word set to 1* Examples anyEvenBit(0xA) = 0, anyEvenBit(0xE) = 1* Legal ops: ! ~ & ^ | + << >>* Max ops: 12*/int anyEvenBit(int x) {return 2;}arrow_forwardI want to write C or C++ functions that evaluate to ONE when the given conditions are true, and to ZERO when they are false. The following are the fourt conditions: int a(int x); //Any bit of x equals 0. int b(int x); // Any bit of x equals 1. int c(int x); //Any bit in the LSB of x equals 0. int d(int x); //Any bit in the MSB of x equals 1. The code should follow the bit-level integer coding rules, with the additional restriction that you may not use equality (==) or inequality (!=) tests.arrow_forward
- So this is a function that prints the two space-separated long integers denoting the respective minimum and maximum values that can be calculated by summing exactly four of the five integers. (The output can be greater than a 32 bit integer.) I want detailed explanation on the part of the code that is in bold and underlined in the starting of the function (long sum = *arr; int min = *arr; int max = *arr;). I cant understand the purpose and the logic behind this specific initialization. Sample Input 1 2 3 4 5 Sample Output 10 14 The actual code- void miniMaxSum(int arr_count, int* arr) { long sum = *arr; int min = *arr; int max = *arr; for(int i = 1; i < arr_count; i++){ sum = sum + arr[i]; if(arr[i] > max){ max = arr[i]; } if(arr[i] < min){ min = arr[i]; } } printf("%ld %ld", sum - max, sum - min); }arrow_forwardWrite a function setbits(x,p,n,y) that returns x with the n bits that begin at position p set to the rightmost n bits of y, leaving the other bits unchanged.arrow_forwardWrite code for a function (C++) with the following pro- totype: /* Addition that saturates to TMin or TMax */ int16_t saturating_add(int16_t x, int16_t y); Instead of overflowing the way normal two’s-complement addition does, satu- rating addition returns Tmax when there would be positive overflow, and TMin when there would be negative overflow. Saturating arithmetic is commonly used in programs that perform digital signal processing. Your function should follow the bit-level integer coding rules from as1.arrow_forward
- If you implement the function F(A,B,C,D)= Sum m (3,4,6,11,12,13,14) using a 8-1 MUX then which of the input position will be equal to D : a. I1 & I6 b. only I5 c. I2 & I6 & I7 d. Only I7 e. None of the choices f. I1 & I5arrow_forwardinside the cpu, mathematical oprations like addition subtraction ,multipulcation and division are done in bit-livel. To perform bit-livel opration in c programming ,bitwise operators are used. apply the knowledge you gained while learing bit wise operators. write a program to input two integers from user by using single scanf.computer and display the value for a and b, a|b,a theta b.arrow_forwardWrite a function that takes an unsigned integer andreturns the number of '1' bits it has(also known as the Hamming weight).For example, the 32-bit integer '11' has binaryrepresentation 00000000000000000000000000001011,so the function should return 3.T(n)- O(k) : k is the number of 1s present in binary representation.NOTE: this complexity is better than O(log n).e.g. for n = 00010100000000000000000000000000only 2 iterations are required.Number of loops isequal to the number of 1s in the binary representation."""def count_ones_recur(n):.arrow_forward
- Write a function that takes an unsigned integer andreturns the number of '1' bits it has(also known as the Hamming weight).For example, the 32-bit integer '11' has binaryrepresentation 00000000000000000000000000001011,so the function should return 3.T(n)- O(k) : k is the number of 1s present in binary representation.NOTE: this complexity is better than O(log n).e.g. for n = 00010100000000000000000000000000only 2 iterations are required..arrow_forwardSuppose we number the bytes in a w-bit word from 0 (least significant) to w/8 – 1 (most significant). Write code for the following C function, which will return an unsigned value in which byte i of argument x has been replaced by byte b: unsigned replace_byte (unsigned x, int i, unsigned char b); Here are some examples showing how the function should work: replace_byte(0x12345678, 2, 0xAB) --> 0x12AB5678 replace_byte(0x12345678, 0, 0xAB) --> 0x123456AB Bit-Level Integer Coding Rules In several of the following problems, we will artificially restrict what programming constructs you can use to help you gain a better understanding of the bit-level, logic, and arithmetic operations of C. In answering these problems, your code must follow these rules: Allowed operations All bit-level and logic operations. Left and right shifts, but only with shift amounts between 0 and w – 1. Addition and subtraction. Equality (==) and inequality (!=) tests. (Some of the problems do not allow…arrow_forwardImplement the function (in C or C++) with the following prototype: /** Implement a function which rotates a word left by n-bits, and returns that rotated value. Assume 0 <= n < w Examples: when x = 0x12345678 and w = 32: n=4 -> 0x23456781 n=20 -> 0x67812345 */ unsigned rotate_left(unsigned x, int n); The function should follow the bit-level integer coding rules above. Be careful of the case n = 0.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr