so im trying to do recursive call to solve function that take integer argument and do recursively, and each recursive call, it power to decimal number i.e 2.2
def f1(x):
if x==0:
return 3
else:
return f1(x-1)**2.2
aw=f1(13)
print("succces")
as you can see, that the code above will generate output like below instead of “succes”:
File “/home/user/Dev/Programs/tesaja.py”, line 19, in f1
return f1(x-1)**2.2
[Previous line repeated 2 more times]
OverflowError: (34, ‘Numerical result out of range’)
i know that this might caused by floating point mechanism in python that only store limited digit, while int (if the power number is int) can hold bigger int, as mentioned below:
https://ksvi.mff.cuni.cz/~dingle/2021-2/prog_1/notes_2.html
e.g:
def f1(x):
if x==0:
return 3
else:
return f1(x-1)**3
aw=f1(13)
print("succces")
this will output fine/”succes” even the power number is 3 (bigger than 2.2)
i dunno if there is similiar problem with me since i wandering around stackofervlow and didnt find same spesific problem (duplicate),” some of it dont include recursive and power floating point”
so i hope you guys can give me solution and more insight about what caused this problem occured
bezzzz098 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.