0

I have some float-pointing number (I don't know float is it, double or long double), and I want to convert It to the fraction. I look at the frexp function, and I get mantissa and exponent of float-pointing type (FPT) number. I look at the struct numbers_limits<float, double or long double>, and I get this fields: radix (2), digits (as I know, it is in the base radix), digits10, max_digits10. I think to conversion I must use max_digits10, but I don't sure, and unfortunately my known of English do not let me understand which of this fields I must use to most accurate conversion. As I know, mantissa always have limited sum of bits, but in decimal base it is unlimited decimal fraction. Anyway, how many digits in decimal representation of mantissa I must use to most accurate conversion from FPT to fraction?

Or maybe I must find in mantissa a period, and convert it to fraction as a periodic decimal number?

AC130
  • 27
  • 4

1 Answers1

0

You are not getting answers because you are headed the wrong way here. Presumably you are trying to find a rational representation in base 10, but floats are not stored base 10. So forget about the mantissa ans exponent thing. Here's a link to an answer to your question. Good luck!

Community
  • 1
  • 1
Steger
  • 887
  • 7
  • 16