Skip to main content

Repeating digits of rational numbers

Project description

This package provides a way to access repeating decimals in the decimal representation of rational numbers.

class object

>>> from dvtDecimal import *

Once package importation completed, you have to create a rational number using:

  • one of its fraction representation
>>> f = dvtDecimal(-604, 260)

for the fraction whose numerator is -604 and denominator is 260.

  • its usual decimal representation
>>> f = dvtDecimal(2.5)
  • the repeating decimals as a string
>>> f = dvtDecimal('00765')

thus creating a number (w/o irregular part) between 0 and 1. In the example, 0.007650076500765... and so on.

object methods

Once you created the object for example, you can access to those methods and variables:

>>> f.dispResults()
For fraction: -604 / 260
    integer   part : -2
    irregular part : 0.3
    periodic  part : [2, 3, 0, 7, 6, 9]
    mixed fraction : [-2, 21, 65]
Operation in Python gives : -2.3230769230769233
>>> f.initValues
[-604, 260]
>>> f.simpValues
[-151, 65]
>>> f.isDecimal()
False
>>> f.dotWrite(20)
-2.32307692307692307692
>>> f.intPart
-2
>>> f.irrPart
0.3
>>> f.repPart
[2, 3, 0, 7, 6, 9]
>>> f.repPartC
230769
>>> f.periodLen
6
>>> f.gcd
4
>>> f.mixedF
[-2, 21, 65]
>>> f.sign
-1

Entering via repeating decimals string allows:

>>> f = dvtDecimal('0123456789')
>>> f = dvtDecimal(*f.simpValues)
>>> f.simpValues
[13717421, 1111111111]

dvtDecimal also supports minimal operations (+,-,*,/) in between elements of the class but also with integers:

>>> f = dvtDecimal(1, 5)
>>> g = dvtDecimal(10, 3)
>>> h = f + g
>>> h.mixedF
[3, 8, 15]
>>> i = f / g
>>> i.mixedF
[0, 3, 50]
>>> f = dvtDecimal(1, 5)
>>> g = 5
>>> h = f * g
>>> h.isDecimal()
True
>>> f = dvtDecimal(1, 5)
>>> g = dvtDecimal(7, 5)
>>> h = f - g
>>> h.simpValues
[-6, 5]

further...

More operations!

about

dvtDecimal is rather an attempt to publish on the PyPi packages index than a fully completed python project, I do not recommend dvtDecimal usage for professionnal use. You have to consider this package as an experiment.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dvtDecimal-0.9.3.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

dvtDecimal-0.9.3-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page