So i read that long double
is 128bit
But look at this code
long double MaxLatticePaths(int xSize, int ySize)
{
long double sumMLP = 1;
long double halfling = xSize;
long double halfling2 = (xSize + ySize) - xSize;
for (int i = xSize + ySize; i > 0; i--)
{
sumMLP = sumMLP * (i / halfling / halfling2);
if (halfling > 1)
{
halfling--;
}
if (halfling2 > 1)
{
halfling2--;
}
}
return sumMLP;
}
int main()
{
cout.precision(2000);
cout << "\n" << MaxLatticePaths(2141, 2140) << "\n";
}
Output:
16315190298711506445464892598264322618004530270611808484780866384528342404142990947031068675180336432315693066114864362480616838595308779982326735844228704193859747658947455525469514212503972044689315566655370373661400711012020016116439559215383460785418453783899764258637079659818638577531691811097773176843497403749098178590357084265715939224640515837766721249964445425407422907713026146366955975530262422859128904600571726957991140807350490417141873207653107811667562463379032199939454947412011560169185406695112167355329690269203438031734174053765724124238771087854348059881325098161615945676620050984397854854452121645886626946657578990304834766661898136369869041936431091596482074847082061571981466253927611353079662496250812546118348009094113018221097833896823648389238307188213648816781186867374971727011472177232520488240752431293118492945262684802421055224211805518127741826303341935999960697567403126622636027961181349146209938242790709547705154379310869350978424238929211385961129809235418155295715641938448321789932432238943131503779648687971230484265855387248678802953305867827800519050353584130082264868408673861330156408398501291948396647365847353078278930897136242755569528982861528875154727717184788894566681318361398503312000918432261678422910400507459471524759366270976
Any higher than 2141, 2140
and it overflows. But how? This is like 1288 digits, 128bit
is only 38digits. Obviously there is something wrong in my code, because i wrote another simple program and assigned a larger but nowhere near this size digit and it overflowed. Can someone point out what's the bug in my code?