Closed Nov1kov closed 6 months ago
Could you please explain more?
I believe, this is explained in the decimal module documentation. Namely, here:
There are some small differences between arithmetic on Decimal objects and arithmetic
on integers and floats. When the remainder operator % is applied to Decimal objects,
the sign of the result is the sign of the dividend rather than the sign of the divisor:
>>> (-7) % 4
1
>>> Decimal(-7) % Decimal(4)
Decimal('-3')
The integer division operator // behaves analogously, returning the integer part of
the true quotient (truncating towards zero) rather than its floor, so as to preserve
the usual identity x == (x // y) * y + x % y:
>>> -7 // 4
-2
>>> Decimal(-7) // Decimal(4)
Decimal('-1')
mpz_fdiv_q() (used by mpz(a)//b) round down to -oo. The remainder has same sign as the divisor.
What is the best way to convert to Decimal from gmpy2 types?
In general, you could use as_integer_ratio() method to get exact value of mpfr as a fraction.
What is the nearest way to use gmpy2 instead of "py - Decimal" types?
The point of the decimal module is correctly rounded decimal floating point arithmetic. There is no way to use gmpy2 to do same: it offers binary floating point arithmetic.
Thank you, useful answer!
@Nov1kov, do you think there is some issue with the gmpy2 code?
No, I think this is not an error, I did not find a similar question or place to ask my question.
I hope this ticket will help others.
I did not find a similar question or place to ask my question.
It's fine to do here. Perhaps, "Discussions" forum could be better, but...
Hello, thank you for great tool.
I want to improve performance with gmpy2 with big numbers. But in some cases, I can't use analog from gmpy2.
Could you please explain more?
TypeError: conversion from mpz to Decimal is not supported