A few questions about numeric data types

Hello all. Please see the following code:

https://ideone.com/U39eK

The code basically outputs several properties of the different numeric data types I chose. I wanted some information about the data types so as to more intelligently output numeric values into streams (for the dimension classes of my other project).

Please refer to the value labeled "digits (decimal)". Is this the maximum precision given by the data type? Can this number be used unaltered in a call to setprecision()? I ask because I did a test in line 22 (I added 5 to this number). I thought I was supposed to get 5 trailing zeroes (without fixed I would have gotten no extra zeroes), but it turned out I did not get those. I got different numbers, but if this was the maximum precision, where do these numbers come from???

Related question: See line 21, which is a modified version of line 22. If I use line 21 instead of line 22, I get really big outputs for double and long double, but I do get a bunch of non-zero significant digits. So what gives?? Where do these numbers come from? Are they "invented" somehow? Are they garbage in RAM? I just don't get it.

Thanks!
Bumping. Nobody?
What does "ios_base:fixed" mean for a long double? Check the reference. Do you really want to display a giant real number?

Use "ios_base:scientific" instead.


b2ee
Last edited on
I don't want to display it, but if fixed is set and a float is streamed in, I would have thought that only the significant digits would have been displayed and all others would have been set to zero, because after all they are not known.

In any case, I am not saying I will use fixed with float, double or long double; I am currently trying to understand the data types and this behavior I label as "strange".
I'm getting errors for the line testVal += pow(10, i);
I set val=10, and put in testVal += pow(val, i);
Type I used was long double val=10;

I believe they add to the amount of digits after the decimal point in the precision.
Notice how the float value changed with more digits.

I think you are getting the error in Visual Studio. Visual Studio has a hard time with the int data type and the pow() function. If you try the code in Visual Studio, you either do what you did or you provide a pow() overload with int's.
Topic archived. No new replies allowed.