Issues with C++ Precision

Krishna Bharadwaj

I saw a number of posts which spoke about how we can display a number with a given precision in C++, but I was wondering if there is a way to display non recurring numbers as say x.0 and recurring numbers of width specified by the setprecision method?

Escualo

If you knew in advance whether the number you want to print exhibits a recurring decimal expansion, then you could simply issue an statement along the lines of:

if is_recurring:
    print using expanded format
else
    print using fixed format

I imagine you do not know in advance. And the computer cannot, in general, know it either.

How would it test whether a few decimals (about 15 if you are using double precision) represent a recurring decimal?

Furthermore, how would you like to print it? Take, for instance, the classical example:

3227 / 555 = 5.814414414414414

How should I print it? Like this?

5.8144

or like that?

5.8144
   ***

It seems like a very difficult problem to address in general.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related