+ 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

13th Jan 2018, 6:03 PM
Otumian Empire
Otumian Empire - avatar
11 Réponses
+ 3
I will be back
13th Jan 2018, 6:10 PM
Otumian Empire
Otumian Empire - avatar
+ 3
21...26 = -ve
13th Jan 2018, 6:15 PM
Otumian Empire
Otumian Empire - avatar
+ 2
@John Wells could give me a reference please...
13th Jan 2018, 6:49 PM
Otumian Empire
Otumian Empire - avatar
+ 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???
14th Jan 2018, 6:45 AM
Otumian Empire
Otumian Empire - avatar
+ 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
13th Jan 2018, 6:38 PM
John Wells
John Wells - avatar
+ 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
13th Jan 2018, 7:11 PM
rafal
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 😞
13th Jan 2018, 6:23 PM
Faisal
Faisal - avatar
0
@Faisal it actually is predictable. If the value gets a single larger bit than the data size, it sets the sign bit.
13th Jan 2018, 6:42 PM
John Wells
John Wells - avatar
0
use long long
14th Jan 2018, 4:09 AM
Talluri Saisumanth
Talluri Saisumanth - avatar
- 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 😕
13th Jan 2018, 6:06 PM
Faisal
Faisal - avatar
- 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.
13th Jan 2018, 6:51 PM
John Wells
John Wells - avatar