Git Product home page Git Product logo

Comments (5)

skirpichev avatar skirpichev commented on September 26, 2024 1

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.

Nov1kov avatar Nov1kov commented on September 26, 2024

Thank you, useful answer!

from gmpy.

skirpichev avatar skirpichev commented on September 26, 2024

@Nov1kov, do you think there is some issue with the gmpy2 code?

from gmpy.

Nov1kov avatar Nov1kov commented on September 26, 2024

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.

skirpichev avatar skirpichev commented on September 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.