Sage - problem during dividing
I'm using https://sagecell.sagemath.org/ I tried divide by 2 some integers like:
test no 1:
integer to divide : 1178491952578374405023980117478966721
after divide by 2 : 589245976289187203169105266910167040
multiply by 2 to get integer before divide : 1178491952578374406338210533820334080
test no 2:
integer to divide : 1061618174439266951056499776554456999
after divide by 2 : 530809087219633493358671479116398592
multiply by 2 to get integer before divide : 1061618174439266986717342958232797184
test no 3:
integer to divide : 1272974170381429325805079139420165714
after divide by 2 : 636487085190714687068002546205327360
multiply by 2 to get integer before divide : 1272974170381429374136005092410654720
why result after divide is wrong??
If I change language from sage to python is even worst...
code:
import random
def delete_0(value):
report = False
len_s=len(value)
while report == False:
if value[len_s-1] == "0":
report = False
#print("przed :",value)
value=value[:-1]
#print("po :",value)
len_s=len(value)
if value[len_s-1] != "0":
report = True
if len(value)==1:
report = True
return value
def printStr(FloatNumber, Precision):
return "%0.*f" % (Precision, FloatNumber)
def gen_value(liczba):
d = liczba
l =[]
ile = len(str(d))
w = printStr(d,ile)
l = str(w).split(".")
w = l[1]
r = delete_0(w)
return l[0] +"."+r
#number to divide as random.randrange
number = 1272974170381429325805079139420165714 #random.randrange((2**119),2**120)
to_test = number
print("number to divide by 2 : ",number)
number =(number /2)
print("i-th divide: ",i," # after divide : ",number)
print("i-th divide: ",i," # after divide : ",Reals(120)(number))
print("number as more precisied: ",gen_value(number))
print("Test : after multiply * 2 is equal? ",(float(number)+float(number) ) == to_test)
Please display your test code. And also operating system, sage version, etc