Answer the question
In order to leave comments, you need to log in
C++: How to solve the problem about the mantissa and the sign of a float?
Hello, there is a problem: For the float data type, provide the ability to access both the whole number and separately its sign and mantissa. Actually the question is how to solve it, my attempts were unsuccessful, unfortunately. Thanks in advance.
Answer the question
In order to leave comments, you need to log in
unfortunately my attempts were not successful.
struct float_parts {
unsigned fraction:23;
unsigned exponent:8;
unsigned sign:1;
};
union float_and_parts {
float f;
struct float_parts parts;
};
The math.h
file contains frexp functions with signatures
float frexp( float num, int *exp);
double frexp( double num, int *exp);
long double frexp( long double num, int *exp);
double num, r;
int exp;
num = 6.0;
r = frexp( num, &exp);
printf("The matissa returned is::%lf",r);
printf("The exponent value stored in exp is::%d",exp);
The matissa returned is::0.750000
The exponent value stored in exp is::3
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question