Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Sage - problem during dividing

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??

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??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 =  896547011336364022365061955551376617 #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? ",number == to_test)

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 =  896547011336364022365061955551376617 #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? ",number ",(number*2) == to_test)

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
+"."+r

#number to divide as random.randrange
number =  896547011336364022365061955551376617 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? ",(number*2) ",(float(number)+float(number) ) == to_test)