When I run this code
from numba import jit
A,B,C,D = [int(i) for i in input().split()]
@jit()
def Z (A,B,C,D):
X = (A**B)*(C**D)
print(X)
return X
Z(A, B, C, D)
If I enter values of "2887969 614604076030 8478041 209676100616"
it returns 0
and that's not right.
The problem is that for integer representations for numbers, there are upper and lower limits of what can be represented.
In the type signature below, you can see that when I enter these numbers, the compiler assigns A and C to 32 bit integers (max value of around 2 billion) and B and D to 64 bit integers (max value of 1.84 * 10^19).
X is also a 64 bit integer, but the number you are trying to represent is far too large for it to contain, so it will not return accurate results.
You can view the types the compilers assigns with <function name>.inspect_types()
, or in your case Z.inspect_types()
.
Z (int32, int64, int32, int64)
--------------------------------------------------------------------------------
# File: C:\Users\wade.roberts\PycharmProjects\workspace\numba_workspace.py
# --- LINE 6 ---
@jit()
# --- LINE 7 ---
def Z(A, B, C, D):
# --- LINE 8 ---
# label 0
# A = arg(0, name=A) :: int32
# B = arg(1, name=B) :: int64
# C = arg(2, name=C) :: int32
# D = arg(3, name=D) :: int64
# $0.3 = A ** B :: int64
# del B
# del A
# $0.6 = C ** D :: int64
# del D
# del C
# X = $0.3 * $0.6 :: int64
# del $0.6
# del $0.3
X = (A ** B) * (C ** D)
# --- LINE 9 ---
# $0.8 = global(print: <built-in function print>) :: Function(<built-in function print>)
# del $0.8
# print(X)
# $0.10 = const(NoneType, None) :: none
# del $0.10
print(X)
# --- LINE 10 ---
# $0.12 = cast(value=X) :: int64
# del X
# return $0.12
return X