- Raymond
Well yea, kinda but I'm a bit confused as I don't know about printf at all. So I hope there was an easy way to do it with cout
olli
- Raymond
I just need to show 10+ digits in cout but that number sometimes will be 5 digits sometimes 10. So I don't want extra zeros either
- Raymond
You mean by editing the default values though right? I'm trying to avoid that because I'm still studying and don't want to change anything default yet
Anonymous
Anonymous
you can do this as well
Anonymous
Anonymous
it is even easier
- Raymond
You mean in the same file within the code? How can I do that?
- Raymond
like this?
- Raymond
double test = 10.f / 3.f;
std::precision cout << test;
- Raymond
If this worked it would've been the best but it doesn't
Anonymous
Anonymous
here is the code and output
DEviL
Hiii
Anonymous
dd does not have as many digits as d
Anonymous
so it is not padded with 0s
Anonymous
- Raymond
Ok something is weird... When I put this code
double test = 10.f / 3.f;
std::cout << std::setprecision(100) << test;
It gives me this result
3.3333332538604736328125 instead of 3.333333333333333333333333
- Raymond
Why?
Anonymous
Anonymous
if you do 10/3 in decimal you will have 3.3333 repeating forever
Anonymous
which is an irrational number in the decimal number system
Anonymous
10 / 3 is also an irrational number in the binary number system
- Raymond
But I~m not expecting a perfect result on this but It`s at least suppose to give me more tahan 10+ digits of 333333
Anonymous
no because that is not the accuracy that 64 bits is capable of
- Raymond
👍
Anonymous
i mean 32 bits
Anonymous
so change the f into a double cast
Anonymous
((double) 10) / ((double) 3)
Anonymous
Anonymous
a float at best has 7 decimal digits of precision
Anonymous
a double has 15
Anonymous
after that it becomes iffy and you cannot really get accurate things
Anonymous
the 7th and 15th respectfully are a guess
- Raymond
That was a really good explanation. Thank you very much
Anonymous
so if you really want to be accurate you have to get limited to 6 for float and 14 for double
Anonymous
you are welcome
- Raymond
You would think that C++ would not have that basic issue but wow. Can't believe this is still an issue in 2018 in C++
Anonymous
C++ is a poorly designed language
Anonymous
it is not designed for accuracy
Anonymous
it is designed for speed
- Raymond
What do you recommend best for calculations for like currencies?
Anonymous
fortran
Anonymous
or mathematica
Anonymous
these are the most accurate you can get
Anonymous
but it depends what kind of currencies are you talking about
- Raymond
Wow... now those are hardcore dude. I can't do that yet. I gotto get better at CPP first
- Raymond
Crypto Currencies
Anonymous
because my recollection is that currencies only need 5 decimal places
- Raymond
So I desperately need 10+ digits decimals calculations
Anonymous
which is easily done in C++
Anonymous
or or or you can do normalization techniques
- Raymond
Just Bitcoin itself is 8 decimals after the dot
- Raymond
Others are more different
- Raymond
What is that normalization?
Anonymous
you could just work on the other end of the spectrum in your actual code base
Anonymous
well technically unnormalization
Anonymous
you find the percentage it is of the maximum you can have
Anonymous
so let's say you only want it to be 100 tokens total
Anonymous
and you want to have digits that are below 0.001
Anonymous
what you do is you find a way to normalize these such that the lowest value is 1
Anonymous
and work in that way
Anonymous
so for bitcoin you find out that their lowest decimal place is 10^-8
Anonymous
so just multiply everything by 10^8
Anonymous
then deal with the tokens there
Anonymous
and pretend that 1 token is however much of the current price
Anonymous
so if the price of one token is 10k, and we allow fractions of tokens
Anonymous
we create a mini token which we use for our own calculations
Anonymous
that one will be 10k / number of mini tokens needed for one token
Anonymous
my bad this is not actually normalization
Anonymous
i do not know what this would be called
- Raymond
Wow. That pretty cool. I love to see that there's at least a work around for that. I don;t need it yet but I will in the future for sure.
Anonymous
already is
Anonymous
that is how a lot of electronics designers work with sensor data
- Raymond
I see
Anonymous
they have a range that the sensor data can be in
- Raymond
Cool
Anonymous
and have a binary output from that