[Solved] doubles vs python 15 digits differences in values ?

i did a program in Basic 1.1 with some doubles vars D-02
and compared same values in python

and i dont get the same values?

how come after 7 digits there is such a big difference ?

Python = 0.019933199 55445826
Basic = 0.019933199 74393248

thanks

see
http://docs.python.org/3.3/tutorial/floatingpoint.html

still does not explian why it ha only 7 difits of precision!s

how do you print a list values ?

print (’ initial values i1 =’,i1,’ ax =’,ax,’ bx ‘,bx,’ s1=’,s1)

ax bx s1 goes from 1 value up to 6 values or more
so do i have to set a format for each index for the list

have to see if the format gives better precison then the normal print

thanks

did test with format

print (’ format =’,format(s1[i1], ‘.12g’))

and get same value

so it is in Basic program that seems not to give the same value
which is very strange to start at the 7 digits
i mean this is not at the end of the number more like 1/2 way
that is a huge error !

did a test in Xcell
get this number

0.0199332000000000000

even worst 7 digits only i guess!

Python = 0.019933199 55445826
Basic = 0.019933199 74393248

test with decimal module

format = 0.0199331995544582592228000095246898126788437366485595703125

thanks

double-precision float seems pretty fine:

“%.52f” % (7/6) == decimal.Decimal(7/6).to_eng_string()

That is not a huge error; It is a next-to-meaningless error. This is well within the know representation error for IEEE double variables and is almost certainly an accumulation error.

Are you seeing real, visible problems or are you just comparing the results for perfect accuracy? I would recommend just using the results because the difference will be indistinguishable to the human eye.

i’m running algos in old BASIC and trying to port to python
and the algo has many parameters and some are very sensitive
Diffusion equation - with second order derivatives

so while testing with min value for index i was comparing the 2 results and
almost same up to 7 digits which is like single precision number

but i’m working with 15 digiits so i assume the 2 programs should give almost same value for an equation like

X=0.02 * (0.99 + 0.02 * 0.333) and it is not

But the BASIC program i’m using is new and there might be some errors Too

total error is not that huge but to have only 7 digits valid on 15 for a simple equation i find it very strange!

thanks

with python how do you get max precision

or are you force to use decimal module which is way slower then using normal floats

i have an algo which might do 2 loops in sequence like 20 time 20 = 400 times
so how or what commands do i use to keep high precision with this algo ?

one loops has something like 2 or 4 calculations for max number of significatives digits up to 15 digits or as close as possible
then the other loop als have a few calculations

i know about the cumulative errors from the given datas but that is another matter which cannot be controled !

thanks

I believe it’s rather BASIC that gives imprecise results rather than Python, see my last post. Output of decimal module and regular “float” type (=int64?) are the same for 52 digits the decimal module returned for the test calculation.

did a tst this afternoon with a for loop up to 1000 add of 0.2
with float and with decimal
and it gives high precision with python

so i’m not worried anymore dont’ know why this error happen in BASIC
so will continue my algo in python with only floats number
that way there is not conversion between var type and no errors !

thanks

i’m pretty sure BASIC uses int32, hence low precision

no all var were DIM double

but in anyway i’ll keep doing it in python from now on!

if possible i dont really want to get back to Basic
mind you it is much simpler and less powerfull then python!

thanks