Do integer calculations inside a decimal bracket use floats?

I’m investigating the accuracy of solutions to an equation.
I’m using this line in the hope that the calculation using x,y,n (all Integers) will be accurate to the precision set by the decimal.context.prec I choose.

z = Decimal(((xy10**n)-(xy))/((10x)-y))

Am I correct that the calculation will be performed to the accuracy of the decimal.context.prec or will floats be used inside the brackets ?

Thanks

The calculations are performed before calling Decimal, and thus use floats. You should convert your variables to Decimal before performing the calculation.

Will this work ? (I’m still a bit newbie on Python)

xD = Decimal(x)
yD = Decimal(y)
nD = Decimal(n)
z = ((xD yD 10**nD)-(xD yD))/((10 xD)-yD)

Thanks

I think it should, as long as x, y and n are integers. If they are floats, it is usually better to use strings. Compare:

>>> from decimal import Decimal
>>> Decimal(0.1)
Decimal('0.1000000000000000055511151231257827021181583404541015625')
>>> Decimal("0.1")
Decimal('0.1')
>>>

Thanks, yes all int()s