SFML community forums
General => General discussions => Topic started by: Azaral on February 06, 2014, 09:52:36 pm
-
Is there a class that allows for any number of digits before and after the decimal point for C++? Something that will allow me to have numbers that are bigger or smaller than what I can get with the standard data types.
-
Have you already searched for "big integer c++" or "big decimal c++"?
GMP (https://gmplib.org/) is a known library.
Out of curiosity, what do you need it for?
-
Strings ? you can use them for arbitrarily big numbers (at least while you have memory..), you just need to implement the basic math operations on them and it should work.
It shouldn't be hard to make it work, but it will most likely have bad performance..
If you want something serious, I heard https://gmplib.org/ works fine.
-
Forgive me for asking, but out of curiosity, what could you possibly need more than the 19.26 decimal digits that long double gives you? Also, I don't think there is any way to store any number larger without losing precision.
edit: I guess you can ignore this post, other higher beings are more knowledgeable :)
-
Have you already searched for "big integer c++" or "big decimal c++"?
GMP (https://gmplib.org/) is a known library.
Out of curiosity, what do you need it for?
I have searched for something similar and I found gmp. I was just trying to find more options.
I'm working on a particle accretion simulator for fun and working with really small numbers. I'm not getting enough precision with the numbers.
Forgive me for asking, but out of curiosity, what could you possibly need more than the 19.26 decimal digits that long double gives you? Also, I don't think there is any way to store any number larger without losing precision.
edit: I guess you can ignore this post, other higher beings are more knowledgeable :)
I am using long double, but it is rounding numbers off. I calculate something with 13 decimals, and it is rounding off at 4 in some cases. I'm also getting read outs out equal numbers not being equal.
One such example is the gravitational constant, 0.0000000000667384. Already using up 11 decimals (I've had to truncate it to prevent getting 0 for results from rounding).
When calculating gravitational forces, you can easily get over the 19 decimals.
Fg = G * ( M1 + M2) / R ^ 2
If M1 + M2 = 1 and R ^ 2 (the squared distance between 1 and 2) is 2822400 (1680 * 1680, one side of my screen to the other).
Fg = G * 1 / 2,822,400 = 0.000000000000000023645975 ( 24 decimals )
-
0.000000000000000023645975 ( 24 decimals )
I think you misunderstand the concept of floating point; it's about significant digits, not zeros. See also this thread (http://en.sfml-dev.org/forums/index.php?topic=14264.0).
Most problems related to precision can be solved by using algorithms which are numerically stable, not by larger data types. The prime example here is the inversion of matrices. Before employing external libraries, make sure there's really no way to minimize rounding errors (it might require some reading about numerical methods).
-
If all your numbers are that small, there's no need to add so many zeros. You can simple move the decimal point down and if you ever need to output something add a few zeros or use the scientific notation.
-
Well, they are small now, but I plan to allow the particle to gather up and squeeze a group of smaller particles into bigger particles. Eventually there will be really big particles that will be making numbers that are much bigger.
-
Well, they are small now, but I plan to allow the particle to gather up and squeeze a group of smaller particles into bigger particles. Eventually there will be really big particles that will be making numbers that are much bigger.
And you still would be able to have bigger numbers without using larger data types.