[{"data":1,"prerenderedAt":1372},["ShallowReactive",2],{"doc-\u002Ferrors\u002Foverflowerror-numerical-result-out-of-range-fix":3},{"id":4,"title":5,"body":6,"description":1365,"extension":1366,"meta":1367,"navigation":63,"path":1368,"seo":1369,"stem":1370,"__hash__":1371},"content\u002Ferrors\u002Foverflowerror-numerical-result-out-of-range-fix.md","OverflowError: numerical result out of range (Fix)",{"type":7,"value":8,"toc":1331},"minimark",[9,13,21,28,31,36,195,202,206,212,215,234,237,245,249,252,272,275,279,285,331,334,357,360,379,382,417,420,429,436,444,448,453,456,534,544,548,551,596,599,603,606,609,612,620,627,630,718,725,733,739,805,808,811,824,828,831,835,915,918,922,925,945,949,952,1010,1017,1021,1024,1080,1083,1087,1090,1160,1163,1167,1170,1191,1194,1213,1217,1220,1249,1253,1257,1260,1267,1272,1282,1285,1292,1298,1302,1327],[10,11,5],"h1",{"id":12},"overflowerror-numerical-result-out-of-range-fix",[14,15,16,20],"p",{},[17,18,19],"code",{},"OverflowError: numerical result out of range"," means a calculation produced a number that is too large for Python to handle in that specific operation.",[14,22,23,24,27],{},"This error is common with floating-point math and functions from the ",[17,25,26],{},"math"," module. It is less common with normal Python integers.",[14,29,30],{},"If you are trying to fix it quickly, start by checking whether your input has become extremely large before the failing calculation.",[32,33,35],"h2",{"id":34},"quick-fix","Quick fix",[37,38,43],"pre",{"className":39,"code":40,"language":41,"meta":42,"style":42},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","import math\n\nx = 1000\n\n# This can raise OverflowError\n# result = math.exp(x)\n\n# Safer approach: check before calling\nif x > 709:\n    print(\"Number is too large for math.exp() with a float\")\nelse:\n    result = math.exp(x)\n    print(result)\n","python","",[17,44,45,58,65,79,84,91,97,102,108,127,150,158,183],{"__ignoreMap":42},[46,47,50,54],"span",{"class":48,"line":49},"line",1,[46,51,53],{"class":52},"sVHd0","import",[46,55,57],{"class":56},"su5hD"," math\n",[46,59,61],{"class":48,"line":60},2,[46,62,64],{"emptyLinePlaceholder":63},true,"\n",[46,66,68,71,75],{"class":48,"line":67},3,[46,69,70],{"class":56},"x ",[46,72,74],{"class":73},"smGrS","=",[46,76,78],{"class":77},"srdBf"," 1000\n",[46,80,82],{"class":48,"line":81},4,[46,83,64],{"emptyLinePlaceholder":63},[46,85,87],{"class":48,"line":86},5,[46,88,90],{"class":89},"sutJx","# This can raise OverflowError\n",[46,92,94],{"class":48,"line":93},6,[46,95,96],{"class":89},"# result = math.exp(x)\n",[46,98,100],{"class":48,"line":99},7,[46,101,64],{"emptyLinePlaceholder":63},[46,103,105],{"class":48,"line":104},8,[46,106,107],{"class":89},"# Safer approach: check before calling\n",[46,109,111,114,117,120,123],{"class":48,"line":110},9,[46,112,113],{"class":52},"if",[46,115,116],{"class":56}," x ",[46,118,119],{"class":73},">",[46,121,122],{"class":77}," 709",[46,124,126],{"class":125},"sP7_E",":\n",[46,128,130,134,137,141,145,147],{"class":48,"line":129},10,[46,131,133],{"class":132},"sptTA","    print",[46,135,136],{"class":125},"(",[46,138,140],{"class":139},"sjJ54","\"",[46,142,144],{"class":143},"s_sjI","Number is too large for math.exp() with a float",[46,146,140],{"class":139},[46,148,149],{"class":125},")\n",[46,151,153,156],{"class":48,"line":152},11,[46,154,155],{"class":52},"else",[46,157,126],{"class":125},[46,159,161,164,166,169,172,176,178,181],{"class":48,"line":160},12,[46,162,163],{"class":56},"    result ",[46,165,74],{"class":73},[46,167,168],{"class":56}," math",[46,170,171],{"class":125},".",[46,173,175],{"class":174},"slqww","exp",[46,177,136],{"class":125},[46,179,180],{"class":174},"x",[46,182,149],{"class":125},[46,184,186,188,190,193],{"class":48,"line":185},13,[46,187,133],{"class":132},[46,189,136],{"class":125},[46,191,192],{"class":174},"result",[46,194,149],{"class":125},[14,196,197,198,201],{},"A common fix is to validate very large values before calling functions like ",[17,199,200],{},"math.exp()"," or raising very large numbers to a power.",[32,203,205],{"id":204},"what-this-error-means","What this error means",[14,207,208,211],{},[17,209,210],{},"OverflowError"," happens when a numeric result is outside the allowed range for that operation.",[14,213,214],{},"A few important points:",[216,217,218,222,227],"ul",{},[219,220,221],"li",{},"It usually appears in float-based calculations.",[219,223,224,225,171],{},"It often happens with functions like ",[17,226,200],{},[219,228,229,230,233],{},"The message ",[17,231,232],{},"numerical result out of range"," means the answer is too large to fit in the numeric type being used.",[14,235,236],{},"In beginner code, this often happens when numbers keep growing and there is no limit check before the calculation.",[14,238,239,240,171],{},"If you want a broader introduction to Python exceptions, see ",[241,242,244],"a",{"href":243},"\u002Flearn\u002Fpython-errors-and-exceptions-explained\u002F","Python errors and exceptions explained",[32,246,248],{"id":247},"why-this-happens","Why this happens",[14,250,251],{},"Common causes include:",[216,253,254,260,263,269],{},[219,255,256,257,171],{},"You call a math function with a very large value, such as ",[17,258,259],{},"math.exp(1000)",[219,261,262],{},"You raise a number to a very large power in float arithmetic.",[219,264,265,266,171],{},"You convert a huge integer to a float with ",[17,267,268],{},"float()",[219,270,271],{},"Your program multiplies values in a loop until they become too large.",[14,273,274],{},"This happens because floats have a maximum size. Python integers are different and can grow much larger.",[32,276,278],{"id":277},"example-that-causes-the-error","Example that causes the error",[14,280,281,282,284],{},"A simple example is ",[17,283,259],{},":",[37,286,288],{"className":39,"code":287,"language":41,"meta":42,"style":42},"import math\n\nresult = math.exp(1000)\nprint(result)\n",[17,289,290,296,300,320],{"__ignoreMap":42},[46,291,292,294],{"class":48,"line":49},[46,293,53],{"class":52},[46,295,57],{"class":56},[46,297,298],{"class":48,"line":60},[46,299,64],{"emptyLinePlaceholder":63},[46,301,302,305,307,309,311,313,315,318],{"class":48,"line":67},[46,303,304],{"class":56},"result ",[46,306,74],{"class":73},[46,308,168],{"class":56},[46,310,171],{"class":125},[46,312,175],{"class":174},[46,314,136],{"class":125},[46,316,317],{"class":77},"1000",[46,319,149],{"class":125},[46,321,322,325,327,329],{"class":48,"line":81},[46,323,324],{"class":132},"print",[46,326,136],{"class":125},[46,328,192],{"class":174},[46,330,149],{"class":125},[14,332,333],{},"The error happens on this line:",[37,335,337],{"className":39,"code":336,"language":41,"meta":42,"style":42},"result = math.exp(1000)\n",[17,338,339],{"__ignoreMap":42},[46,340,341,343,345,347,349,351,353,355],{"class":48,"line":49},[46,342,304],{"class":56},[46,344,74],{"class":73},[46,346,168],{"class":56},[46,348,171],{"class":125},[46,350,175],{"class":174},[46,352,136],{"class":125},[46,354,317],{"class":77},[46,356,149],{"class":125},[14,358,359],{},"Why?",[216,361,362,368,371,376],{},[219,363,364,367],{},[17,365,366],{},"exp(x)"," means (e^x)",[219,369,370],{},"Exponential growth becomes huge very quickly",[219,372,373,375],{},[17,374,200],{}," returns a float",[219,377,378],{},"That result is too large to fit in a normal float",[14,380,381],{},"You can compare this with a smaller value:",[37,383,385],{"className":39,"code":384,"language":41,"meta":42,"style":42},"import math\n\nprint(math.exp(10))\n",[17,386,387,393,397],{"__ignoreMap":42},[46,388,389,391],{"class":48,"line":49},[46,390,53],{"class":52},[46,392,57],{"class":56},[46,394,395],{"class":48,"line":60},[46,396,64],{"emptyLinePlaceholder":63},[46,398,399,401,403,405,407,409,411,414],{"class":48,"line":67},[46,400,324],{"class":132},[46,402,136],{"class":125},[46,404,26],{"class":174},[46,406,171],{"class":125},[46,408,175],{"class":174},[46,410,136],{"class":125},[46,412,413],{"class":77},"10",[46,415,416],{"class":125},"))\n",[14,418,419],{},"Expected output:",[37,421,423],{"className":39,"code":422,"language":41,"meta":42,"style":42},"22026.465794806718\n",[17,424,425],{"__ignoreMap":42},[46,426,427],{"class":48,"line":49},[46,428,422],{"class":77},[14,430,431,432,435],{},"That works because ",[17,433,434],{},"exp(10)"," is still within float range.",[14,437,438,439,443],{},"If you are working with math functions, the ",[241,440,442],{"href":441},"\u002Fstandard-library\u002Fpython-math-module-overview\u002F","Python math module overview"," is a useful reference.",[32,445,447],{"id":446},"how-to-fix-it","How to fix it",[449,450,452],"h3",{"id":451},"check-inputs-before-doing-the-calculation","Check inputs before doing the calculation",[14,454,455],{},"This is often the best fix.",[37,457,459],{"className":39,"code":458,"language":41,"meta":42,"style":42},"import math\n\nx = 1000\n\nif x > 709:\n    print(\"Input is too large for math.exp()\")\nelse:\n    print(math.exp(x))\n",[17,460,461,467,471,479,483,495,510,516],{"__ignoreMap":42},[46,462,463,465],{"class":48,"line":49},[46,464,53],{"class":52},[46,466,57],{"class":56},[46,468,469],{"class":48,"line":60},[46,470,64],{"emptyLinePlaceholder":63},[46,472,473,475,477],{"class":48,"line":67},[46,474,70],{"class":56},[46,476,74],{"class":73},[46,478,78],{"class":77},[46,480,481],{"class":48,"line":81},[46,482,64],{"emptyLinePlaceholder":63},[46,484,485,487,489,491,493],{"class":48,"line":86},[46,486,113],{"class":52},[46,488,116],{"class":56},[46,490,119],{"class":73},[46,492,122],{"class":77},[46,494,126],{"class":125},[46,496,497,499,501,503,506,508],{"class":48,"line":93},[46,498,133],{"class":132},[46,500,136],{"class":125},[46,502,140],{"class":139},[46,504,505],{"class":143},"Input is too large for math.exp()",[46,507,140],{"class":139},[46,509,149],{"class":125},[46,511,512,514],{"class":48,"line":99},[46,513,155],{"class":52},[46,515,126],{"class":125},[46,517,518,520,522,524,526,528,530,532],{"class":48,"line":104},[46,519,133],{"class":132},[46,521,136],{"class":125},[46,523,26],{"class":174},[46,525,171],{"class":125},[46,527,175],{"class":174},[46,529,136],{"class":125},[46,531,180],{"class":174},[46,533,416],{"class":125},[14,535,536,537,539,540,543],{},"For many systems, ",[17,538,200],{}," overflows somewhere above about ",[17,541,542],{},"709"," because of float limits.",[449,545,547],{"id":546},"use-smaller-values-or-scale-numbers-down","Use smaller values or scale numbers down",[14,549,550],{},"Sometimes your formula works, but the numbers are too large in their current form.",[37,552,554],{"className":39,"code":553,"language":41,"meta":42,"style":42},"value = 1_000_000\nscaled_value = value \u002F 1000\n\nprint(scaled_value)\n",[17,555,556,566,581,585],{"__ignoreMap":42},[46,557,558,561,563],{"class":48,"line":49},[46,559,560],{"class":56},"value ",[46,562,74],{"class":73},[46,564,565],{"class":77}," 1_000_000\n",[46,567,568,571,573,576,579],{"class":48,"line":60},[46,569,570],{"class":56},"scaled_value ",[46,572,74],{"class":73},[46,574,575],{"class":56}," value ",[46,577,578],{"class":73},"\u002F",[46,580,78],{"class":77},[46,582,583],{"class":48,"line":67},[46,584,64],{"emptyLinePlaceholder":63},[46,586,587,589,591,594],{"class":48,"line":81},[46,588,324],{"class":132},[46,590,136],{"class":125},[46,592,593],{"class":174},"scaled_value",[46,595,149],{"class":125},[14,597,598],{},"Scaling only helps if it still makes sense for your problem.",[449,600,602],{"id":601},"rewrite-the-formula-to-avoid-huge-intermediate-results","Rewrite the formula to avoid huge intermediate results",[14,604,605],{},"Sometimes the final answer is reasonable, but one step in the middle becomes huge.",[14,607,608],{},"For example, if a formula creates a very large exponent and then divides later, try rewriting it so the calculation stays smaller throughout.",[14,610,611],{},"This depends on the formula, but the goal is simple:",[216,613,614,617],{},[219,615,616],{},"avoid creating giant temporary numbers",[219,618,619],{},"combine operations in a safer order when possible",[449,621,623,624],{"id":622},"catch-the-error-with-try-except","Catch the error with ",[17,625,626],{},"try-except",[14,628,629],{},"If large input is possible, you can prevent your program from crashing.",[37,631,633],{"className":39,"code":632,"language":41,"meta":42,"style":42},"import math\n\nx = 1000\n\ntry:\n    result = math.exp(x)\n    print(result)\nexcept OverflowError:\n    print(\"The number is too large for this calculation.\")\n",[17,634,635,641,645,653,657,664,682,692,703],{"__ignoreMap":42},[46,636,637,639],{"class":48,"line":49},[46,638,53],{"class":52},[46,640,57],{"class":56},[46,642,643],{"class":48,"line":60},[46,644,64],{"emptyLinePlaceholder":63},[46,646,647,649,651],{"class":48,"line":67},[46,648,70],{"class":56},[46,650,74],{"class":73},[46,652,78],{"class":77},[46,654,655],{"class":48,"line":81},[46,656,64],{"emptyLinePlaceholder":63},[46,658,659,662],{"class":48,"line":86},[46,660,661],{"class":52},"try",[46,663,126],{"class":125},[46,665,666,668,670,672,674,676,678,680],{"class":48,"line":93},[46,667,163],{"class":56},[46,669,74],{"class":73},[46,671,168],{"class":56},[46,673,171],{"class":125},[46,675,175],{"class":174},[46,677,136],{"class":125},[46,679,180],{"class":174},[46,681,149],{"class":125},[46,683,684,686,688,690],{"class":48,"line":99},[46,685,133],{"class":132},[46,687,136],{"class":125},[46,689,192],{"class":174},[46,691,149],{"class":125},[46,693,694,697,701],{"class":48,"line":104},[46,695,696],{"class":52},"except",[46,698,700],{"class":699},"sZMiF"," OverflowError",[46,702,126],{"class":125},[46,704,705,707,709,711,714,716],{"class":48,"line":110},[46,706,133],{"class":132},[46,708,136],{"class":125},[46,710,140],{"class":139},[46,712,713],{"class":143},"The number is too large for this calculation.",[46,715,140],{"class":139},[46,717,149],{"class":125},[14,719,720,721,171],{},"This is useful when you expect bad or extreme input. For a beginner guide, see ",[241,722,724],{"href":723},"\u002Fhow-to\u002Fhow-to-handle-exceptions-in-python\u002F","how to handle exceptions in Python",[449,726,728,729,732],{"id":727},"use-decimal-in-some-cases","Use ",[17,730,731],{},"decimal"," in some cases",[14,734,735,736,738],{},"The ",[17,737,731],{}," module can help when you need more control over precision.",[37,740,742],{"className":39,"code":741,"language":41,"meta":42,"style":42},"from decimal import Decimal\n\nx = Decimal(\"100\")\nresult = x ** 2\nprint(result)\n",[17,743,744,757,761,781,795],{"__ignoreMap":42},[46,745,746,749,752,754],{"class":48,"line":49},[46,747,748],{"class":52},"from",[46,750,751],{"class":56}," decimal ",[46,753,53],{"class":52},[46,755,756],{"class":56}," Decimal\n",[46,758,759],{"class":48,"line":60},[46,760,64],{"emptyLinePlaceholder":63},[46,762,763,765,767,770,772,774,777,779],{"class":48,"line":67},[46,764,70],{"class":56},[46,766,74],{"class":73},[46,768,769],{"class":174}," Decimal",[46,771,136],{"class":125},[46,773,140],{"class":139},[46,775,776],{"class":143},"100",[46,778,140],{"class":139},[46,780,149],{"class":125},[46,782,783,785,787,789,792],{"class":48,"line":81},[46,784,304],{"class":56},[46,786,74],{"class":73},[46,788,116],{"class":56},[46,790,791],{"class":73},"**",[46,793,794],{"class":77}," 2\n",[46,796,797,799,801,803],{"class":48,"line":86},[46,798,324],{"class":132},[46,800,136],{"class":125},[46,802,192],{"class":174},[46,804,149],{"class":125},[14,806,807],{},"But this is not a magic fix.",[14,809,810],{},"Important:",[216,812,813,818,821],{},[219,814,815,817],{},[17,816,731],{}," can help in some situations",[219,819,820],{},"very large calculations can still become slow or impractical",[219,822,823],{},"you still need to think about input size and formula design",[32,825,827],{"id":826},"step-by-step-debugging-tips","Step-by-step debugging tips",[14,829,830],{},"When this error appears, use a simple process.",[449,832,834],{"id":833},"_1-print-the-value-before-the-failing-line","1. Print the value before the failing line",[37,836,838],{"className":39,"code":837,"language":41,"meta":42,"style":42},"import math\n\nx = 1000\nprint(x)\nprint(type(x))\n\nresult = math.exp(x)\nprint(result)\n",[17,839,840,846,850,858,868,883,887,905],{"__ignoreMap":42},[46,841,842,844],{"class":48,"line":49},[46,843,53],{"class":52},[46,845,57],{"class":56},[46,847,848],{"class":48,"line":60},[46,849,64],{"emptyLinePlaceholder":63},[46,851,852,854,856],{"class":48,"line":67},[46,853,70],{"class":56},[46,855,74],{"class":73},[46,857,78],{"class":77},[46,859,860,862,864,866],{"class":48,"line":81},[46,861,324],{"class":132},[46,863,136],{"class":125},[46,865,180],{"class":174},[46,867,149],{"class":125},[46,869,870,872,874,877,879,881],{"class":48,"line":86},[46,871,324],{"class":132},[46,873,136],{"class":125},[46,875,876],{"class":699},"type",[46,878,136],{"class":125},[46,880,180],{"class":174},[46,882,416],{"class":125},[46,884,885],{"class":48,"line":93},[46,886,64],{"emptyLinePlaceholder":63},[46,888,889,891,893,895,897,899,901,903],{"class":48,"line":99},[46,890,304],{"class":56},[46,892,74],{"class":73},[46,894,168],{"class":56},[46,896,171],{"class":125},[46,898,175],{"class":174},[46,900,136],{"class":125},[46,902,180],{"class":174},[46,904,149],{"class":125},[46,906,907,909,911,913],{"class":48,"line":104},[46,908,324],{"class":132},[46,910,136],{"class":125},[46,912,192],{"class":174},[46,914,149],{"class":125},[14,916,917],{},"This helps you confirm what value is being passed in.",[449,919,921],{"id":920},"_2-find-which-operation-is-growing-too-fast","2. Find which operation is growing too fast",[14,923,924],{},"Look for:",[216,926,927,930,935,940],{},[219,928,929],{},"repeated multiplication",[219,931,932,933],{},"exponentiation with ",[17,934,791],{},[219,936,937,938],{},"calls like ",[17,939,200],{},[219,941,942,943],{},"conversion to ",[17,944,268],{},[449,946,948],{"id":947},"_3-check-for-accidental-float-conversion","3. Check for accidental float conversion",[14,950,951],{},"A very large integer may exist safely, but converting it to float can fail.",[37,953,955],{"className":39,"code":954,"language":41,"meta":42,"style":42},"big_number = 10 ** 1000\n\nprint(type(big_number))\nprint(float(big_number))  # Can raise OverflowError\n",[17,956,957,972,976,991],{"__ignoreMap":42},[46,958,959,962,964,967,970],{"class":48,"line":49},[46,960,961],{"class":56},"big_number ",[46,963,74],{"class":73},[46,965,966],{"class":77}," 10",[46,968,969],{"class":73}," **",[46,971,78],{"class":77},[46,973,974],{"class":48,"line":60},[46,975,64],{"emptyLinePlaceholder":63},[46,977,978,980,982,984,986,989],{"class":48,"line":67},[46,979,324],{"class":132},[46,981,136],{"class":125},[46,983,876],{"class":699},[46,985,136],{"class":125},[46,987,988],{"class":174},"big_number",[46,990,416],{"class":125},[46,992,993,995,997,1000,1002,1004,1007],{"class":48,"line":81},[46,994,324],{"class":132},[46,996,136],{"class":125},[46,998,999],{"class":699},"float",[46,1001,136],{"class":125},[46,1003,988],{"class":174},[46,1005,1006],{"class":125},"))",[46,1008,1009],{"class":89},"  # Can raise OverflowError\n",[14,1011,1012,1013,171],{},"If you need to understand float conversion better, see ",[241,1014,1016],{"href":1015},"\u002Freference\u002Fpython-float-function-explained\u002F","Python float() function explained",[449,1018,1020],{"id":1019},"_4-test-with-smaller-input","4. Test with smaller input",[14,1022,1023],{},"Try a smaller value to confirm the cause.",[37,1025,1027],{"className":39,"code":1026,"language":41,"meta":42,"style":42},"import math\n\nprint(math.exp(10))\nprint(math.exp(100))\n# print(math.exp(1000))  # likely to overflow\n",[17,1028,1029,1035,1039,1057,1075],{"__ignoreMap":42},[46,1030,1031,1033],{"class":48,"line":49},[46,1032,53],{"class":52},[46,1034,57],{"class":56},[46,1036,1037],{"class":48,"line":60},[46,1038,64],{"emptyLinePlaceholder":63},[46,1040,1041,1043,1045,1047,1049,1051,1053,1055],{"class":48,"line":67},[46,1042,324],{"class":132},[46,1044,136],{"class":125},[46,1046,26],{"class":174},[46,1048,171],{"class":125},[46,1050,175],{"class":174},[46,1052,136],{"class":125},[46,1054,413],{"class":77},[46,1056,416],{"class":125},[46,1058,1059,1061,1063,1065,1067,1069,1071,1073],{"class":48,"line":81},[46,1060,324],{"class":132},[46,1062,136],{"class":125},[46,1064,26],{"class":174},[46,1066,171],{"class":125},[46,1068,175],{"class":174},[46,1070,136],{"class":125},[46,1072,776],{"class":77},[46,1074,416],{"class":125},[46,1076,1077],{"class":48,"line":86},[46,1078,1079],{"class":89},"# print(math.exp(1000))  # likely to overflow\n",[14,1081,1082],{},"If smaller values work and larger ones fail, you have confirmed that range is the problem.",[449,1084,1086],{"id":1085},"_5-check-loops-for-unbounded-growth","5. Check loops for unbounded growth",[14,1088,1089],{},"This is a very common beginner mistake.",[37,1091,1093],{"className":39,"code":1092,"language":41,"meta":42,"style":42},"value = 2.0\n\nfor i in range(20):\n    value = value ** 2\n    print(i, value)\n",[17,1094,1095,1104,1108,1130,1143],{"__ignoreMap":42},[46,1096,1097,1099,1101],{"class":48,"line":49},[46,1098,560],{"class":56},[46,1100,74],{"class":73},[46,1102,1103],{"class":77}," 2.0\n",[46,1105,1106],{"class":48,"line":60},[46,1107,64],{"emptyLinePlaceholder":63},[46,1109,1110,1113,1116,1119,1122,1124,1127],{"class":48,"line":67},[46,1111,1112],{"class":52},"for",[46,1114,1115],{"class":56}," i ",[46,1117,1118],{"class":52},"in",[46,1120,1121],{"class":132}," range",[46,1123,136],{"class":125},[46,1125,1126],{"class":77},"20",[46,1128,1129],{"class":125},"):\n",[46,1131,1132,1135,1137,1139,1141],{"class":48,"line":81},[46,1133,1134],{"class":56},"    value ",[46,1136,74],{"class":73},[46,1138,575],{"class":56},[46,1140,791],{"class":73},[46,1142,794],{"class":77},[46,1144,1145,1147,1149,1152,1155,1158],{"class":48,"line":86},[46,1146,133],{"class":132},[46,1148,136],{"class":125},[46,1150,1151],{"class":174},"i",[46,1153,1154],{"class":125},",",[46,1156,1157],{"class":174}," value",[46,1159,149],{"class":125},[14,1161,1162],{},"If a loop keeps squaring or multiplying a number, it can grow out of range very quickly.",[32,1164,1166],{"id":1165},"common-places-beginners-see-this","Common places beginners see this",[14,1168,1169],{},"You will often see this error in code like:",[216,1171,1172,1178,1183,1188],{},[219,1173,1174,1175,1177],{},"using ",[17,1176,200],{}," with large numbers",[219,1179,1174,1180,1182],{},[17,1181,791],{}," with very large float values",[219,1184,1185,1186],{},"converting a huge integer with ",[17,1187,268],{},[219,1189,1190],{},"scientific or financial formulas copied from examples without input checks",[14,1192,1193],{},"Common causes at a glance:",[216,1195,1196,1201,1204,1207,1210],{},[219,1197,1198,1200],{},[17,1199,200],{}," called with a very large number",[219,1202,1203],{},"very large exponent with float arithmetic",[219,1205,1206],{},"converting an extremely large integer to float",[219,1208,1209],{},"unbounded growth inside a loop",[219,1211,1212],{},"a formula that produces huge intermediate values",[32,1214,1216],{"id":1215},"related-errors-to-compare","Related errors to compare",[14,1218,1219],{},"Sometimes this error is confused with other exceptions.",[216,1221,1222,1231,1240],{},[219,1223,1224,1230],{},[241,1225,1227],{"href":1226},"\u002Ferrors\u002Fvalueerror-in-python-causes-and-fixes\u002F",[17,1228,1229],{},"ValueError"," happens when the input itself is invalid, not just too large.",[219,1232,1233,1239],{},[241,1234,1236],{"href":1235},"\u002Ferrors\u002Fmemoryerror-in-python-causes-and-fixes\u002F",[17,1237,1238],{},"MemoryError"," happens when Python runs out of memory.",[219,1241,1242,1248],{},[241,1243,1245],{"href":1244},"\u002Ferrors\u002Ftypeerror-vs-valueerror-in-python-explained\u002F",[17,1246,1247],{},"TypeError vs ValueError in Python explained"," helps when the real problem is the wrong kind of value, not its size.",[32,1250,1252],{"id":1251},"faq","FAQ",[449,1254,1256],{"id":1255},"does-python-integers-overflow","Does Python integers overflow?",[14,1258,1259],{},"Normal Python integers can grow very large, so this error is more common with float-based operations and some math functions.",[449,1261,1263,1264,1266],{"id":1262},"why-does-mathexp-fail-but-large-integers-work","Why does ",[17,1265,200],{}," fail but large integers work?",[14,1268,1269,1271],{},[17,1270,200],{}," returns a float, and floats have a maximum size. Python integers are handled differently and can grow much larger.",[449,1273,1275,1276,1278,1279,1281],{"id":1274},"can-try-except-fix-overflowerror","Can ",[17,1277,626],{}," fix ",[17,1280,210],{},"?",[14,1283,1284],{},"It can stop your program from crashing, but you still need to decide what your program should do when numbers become too large.",[449,1286,1288,1289,1291],{"id":1287},"should-i-use-decimal-to-avoid-this-error","Should I use ",[17,1290,731],{}," to avoid this error?",[14,1293,1294,1295,1297],{},"Sometimes, but not always. ",[17,1296,731],{}," can help in some cases, but very large calculations can still become impractical.",[32,1299,1301],{"id":1300},"see-also","See also",[216,1303,1304,1308,1313,1317,1323],{},[219,1305,1306],{},[241,1307,244],{"href":243},[219,1309,1310],{},[241,1311,1312],{"href":723},"How to handle exceptions in Python",[219,1314,1315],{},[241,1316,442],{"href":441},[219,1318,1319],{},[241,1320,1322],{"href":1321},"\u002Fstandard-library\u002Fmath.pow-function-explained","math.pow() function explained",[219,1324,1325],{},[241,1326,1016],{"href":1015},[1328,1329,1330],"style",{},"html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sutJx, html code.shiki .sutJx{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#6A737D;--shiki-dark-font-style:inherit}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":42,"searchDepth":60,"depth":60,"links":1332},[1333,1334,1335,1336,1337,1346,1353,1354,1355,1364],{"id":34,"depth":60,"text":35},{"id":204,"depth":60,"text":205},{"id":247,"depth":60,"text":248},{"id":277,"depth":60,"text":278},{"id":446,"depth":60,"text":447,"children":1338},[1339,1340,1341,1342,1344],{"id":451,"depth":67,"text":452},{"id":546,"depth":67,"text":547},{"id":601,"depth":67,"text":602},{"id":622,"depth":67,"text":1343},"Catch the error with try-except",{"id":727,"depth":67,"text":1345},"Use decimal in some cases",{"id":826,"depth":60,"text":827,"children":1347},[1348,1349,1350,1351,1352],{"id":833,"depth":67,"text":834},{"id":920,"depth":67,"text":921},{"id":947,"depth":67,"text":948},{"id":1019,"depth":67,"text":1020},{"id":1085,"depth":67,"text":1086},{"id":1165,"depth":60,"text":1166},{"id":1215,"depth":60,"text":1216},{"id":1251,"depth":60,"text":1252,"children":1356},[1357,1358,1360,1362],{"id":1255,"depth":67,"text":1256},{"id":1262,"depth":67,"text":1359},"Why does math.exp() fail but large integers work?",{"id":1274,"depth":67,"text":1361},"Can try-except fix OverflowError?",{"id":1287,"depth":67,"text":1363},"Should I use decimal to avoid this error?",{"id":1300,"depth":60,"text":1301},"Master overflowerror numerical result out of range fix in our comprehensive Python beginner guide.","md",{},"\u002Ferrors\u002Foverflowerror-numerical-result-out-of-range-fix",{"title":5,"description":1365},"errors\u002Foverflowerror-numerical-result-out-of-range-fix","OSJ0BgfdA6YnoU4u6PvR5adJ_cC1ocxFd8dEw1l1tUI",1777585480791]