+ 2
How best do you solve the issue of numbers.. Int, float, double, long etc.. In factorial (w.r.t. recursions)??
why was there a negative value when the arg > 16... when arg is 23...25 result is +ve when arg is 26...33 results is -ve when arg is 34... (I'm tired) result is 0 when arg is 100000000000000000000000000000000000000000000000000000000 I hope you get the point, it returned 2147483647! = (nothing came) "a.exe has stopped working" . was the pop up msg this is funny.. any vivid explanation please... https://code.sololearn.com/c3gJmMVHzJsg/?ref=app
11 Answers
+ 3
I will be back
+ 3
21...26 = -ve
+ 2
@John Wells could give me a reference please...
+ 2
i did... but at an instance the limit for +ve Increased slightly... so how can you use CPP for a huge project that deals with numbers without the fear of a numerical flaw???
+ 1
You might wish to create a BigInteger class to provide what you want. GitHub has one already coded and you will likely hit SoloLearn's timeout limit of 4 or 5 CPU seconds.
https://github.com/panks/BigInteger/blob/master/BigIntegerSingleFile.cpp
+ 1
how about using floats? calculate with for loop, after every sum check if its bigger than 10, if yes devide sum by 10 and rise a counter to know how many times you devided and show result like 1.64466321804 * 10^counter, it should let you calculate more numbers
EDIT:
something like this:
https://code.sololearn.com/cLNiczd2x8AB/?ref=app
0
Because C++'s data values can only hold a certain amount of bytes (ie. int = 4 bytes, double = 8, etc.), larger numbers, such as 21!, will be larger than the data type it is assigned to. Because of this, it basically freaks out and sets it to a negative value for some reason. Besides assigning it to a larger data value, I don't really know if there's anything else that can be done about that đ
0
@Faisal it actually is predictable. If the value gets a single larger bit than the data size, it sets the sign bit.
0
use long long
- 1
By switching any longs you have to long long may expand the range a bit more but I'm still not sure how to continue it beyond that đ
- 1
I put link in my post. I've looked at code and it seemed to be right and no issues raised. Don't know if anyone is using it.