Given float f which of the C statements would allow you to a

Given float f; which of the C statements would allow you to access the binary equiva-
lent of f:

The answer is

* (unsigned long*) (&f)

can you explain this thoroughly?

why there is a * outside and inside the parenthesis

Solution

In this case, the calling convention is that all arguments are promoted before being passed to the function. So if f receives a double but the parameter has type float (which is perfectly valid) the compiler has to emit code that converts the double to a float prior to executing the function\'s body.

Converting in the opposite direction, if the value is outside the range that can be held, the behaviour is undefined. If the value is in range, but can\'t be held exactly, then the result is one of the two nearest values that can be held, chosen in a way that the implementation defines. This means that there will be a loss of precision.

Binary operations between different integral types are performed within a \"common\" type defined by so called usual arithmetic conversions.

In your case the \"common\" type is unsigned int. This means that int operand (your b) will get converted to unsigned int before the comparison, as well as for the purpose of performing subtraction.


down voteaccepted

Binary operations between different integral types are performed within a \"common\" type defined by so called usual arithmetic conversions.

In your case the \"common\" type is unsigned int. This means that int operand (your b) will get converted to unsigned int before the comparison, as well as for the purpose of performing subtraction.

Given float f; which of the C statements would allow you to access the binary equiva- lent of f: The answer is * (unsigned long*) (&f) can you explain this

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site