Comments (5)
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.
from gmpy.
Thank you, useful answer!
from gmpy.
@Nov1kov, do you think there is some issue with the gmpy2 code?
from gmpy.
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.
from gmpy.
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...
from gmpy.
Related Issues (20)
- Dead paper link in comments
- 2.2.0: change in tagging convention? 🤔 HOT 8
- Abnormal situation of converting "mpz" to "str" HOT 4
- gmpy2 Sieve Example Code Problem HOT 10
- Add .bit_count() to xmpz type
- Type declarations to allow integration with type checking and linting tools HOT 2
- Probably incorrect error message. HOT 19
- Invalid mpq.__float__? HOT 5
- Intentional fallthroughs?
- Intentional fallthroughs? HOT 2
- format() should take into account rounding mode of the context?
- Incorrect signature for gmpy2.digits() in docs
- "Invalid conversion specification" error for align '=' value in format spec HOT 1
- Change defaults for format-style printing? HOT 1
- Conversion from mpz to numpy longdouble is incorrect HOT 10
- support in using gmpy2 HOT 6
- gmpy2 does not support trillion-digit Pi calculations. HOT 6
- Memory leak in gmpy2_cache HOT 9
- Memory leak when using gmpy2.ieee context manager HOT 3
- Access to abs() from C interface HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gmpy.