The ValueError in "2*2*2*2*2" is a recent change to limit denial of service attacks. See
https://github.com/python/cpython/issues/95778 . In short, the value you want has 19729 digits in base-10, the conversion from the internal base-30 representation to base-10 cannot be done in linear time, and conversion from arbitrary-length/untrusted data input to integer is very common, making it hard to audit.
The limit of 4300 can be changed using https://docs.python.org/3.11/library/stdtypes.html#int-max-s... . Set it to 0 for unlimited. (I wonder if there will be a thread-local context for this setting in the future, or some other way to bypass the limit on an as-needed basis.)
In any case, your Python and C examples compute different values because you mistook a right-associative operator for a left-associative operator. On my Python 3.12.0a0:
>>> pow(pow(pow(pow(pow(2, 2), 2), 2), 2), 2)
4294967296
>>> ((((2**2)**2)**2)**2)**2
4294967296
>>> big = 2**2**2**2**2 # a**b is right-associative in Python
>>> len(str(big))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Exceeds the limit (4300) for integer string conversion
>>> import sys
>>> sys.set_int_max_str_digits(0)
>>> len(str(big))
19729
Your C example, when written to match your Python example, correctly gives "inf" as it is larger than the range of double, which is pow()'s return type:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char* argv[])
{
printf("%.0lf\n", pow(2, pow(2, pow(2, pow(2, pow(2, 2))))));
return EXIT_SUCCESS;
}
% gcc -o main -std=c18 -O2 -pipe -fPIC -fno-plt -fstack-protector-strong main.c && ./main
inf
Your C program, when written to match your Julia example for a 32-bit architecture (which uses Int32 by default), also gives 0, as it overflows 32-bit signed integers:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char* argv[])
{
int value = 2;
value = value * value;
value = value * value;
value = value * value;
value = value * value;
value = value * value;
printf("%d\n", value);
return EXIT_SUCCESS;
}
% gcc -o main -std=c18 -O2 -pipe -fPIC -fno-plt -fstack-protector-strong main.c && ./main
0