Skip to content

Releases: 144881-Studios/pymodule

PyModule: decimal

06 Oct 05:54
4862449
Compare
Choose a tag to compare

Update information:

  1. bug fixes:
    (1) Add decimals modulo ZeroDivisionError
    (2) Catch a number not in “decimal” class
  2. add sum function(self.sum(var1,var2,*vars))
  3. More accurate division. Uses self / value to keep 100 digits after the decimal point as a infinite decimal places. Uses decimal(1) / decimal(7) will return 0.1428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571428571423. Or uses advanced function self.placediv(othernum,places,last="round"). Uses decimal(19).placediv(decimal(16),2) will return 1.19.

PyModule: decimal

04 Oct 12:43
7703168
Compare
Choose a tag to compare

bug fixes

PyModule: decimal

04 Oct 12:42
7703168
Compare
Choose a tag to compare

bug fixes

PyModule: numbmod

12 Sep 14:09
9ac85cf
Compare
Choose a tag to compare

BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBIG update!
Verified. Release ID: d

PyModule: vector1d

28 Aug 13:10
7703168
Compare
Choose a tag to compare

Uses from vector1d import * for best!
This module uses another module: numbmod. Please download it later than v0.0-beta 1.
Verified. Release ID: b

PyModule: decimal

01 Oct 02:41
7703168
Compare
Choose a tag to compare

A very accurate module!

You can use it to perform addition, subtraction, multiplication, division and remainder operations.

Use a sign or absolute value for it.
Now supports scientific number.

How to install and import this module:

  1. Download this module.
  2. Move these modules to sys.path.
  3. Type from decimal import * .

How to use:

>>> a = decimal(2)
>>> b = decimal(5.0)
>>> c = decimal("0.123456789")
>>> d = decimal(0)
>>> e = decimal("-2.5")
>>> a
2
>>> b
5
>>> c
0.123456789
>>> d
0
>>> e
-2.5
>>> a + b
7
>>> a - b
-3
>>> -a
-2
>>> -e
2.5
>>> abs(e)
2.5
>>> len(c)
1
>>> c.len()
[1, 9]
>>> a * b
10
>>> c * d
0
>>> c * c
0.015241578750190521
>>> c * c * c
0.001881676371789154860897069
>>> f = scidecimal("1.729271E10000")

Verified. Release ID: g

PyModule: char

20 Aug 15:57
1ef74a9
Compare
Choose a tag to compare

Uses from char import * for best.
Verified. Release ID: 8

PyModule: vector1d

28 Aug 08:28
7703168
Compare
Choose a tag to compare
PyModule: vector1d Pre-release
Pre-release

Beta version. Uses from vector import * for best!
This module uses another module: numbmod. Please download it later than v0.0-beta 1.
Verified. Release ID: a

PyModule: fraction

12 Sep 14:23
7703168
Compare
Choose a tag to compare
PyModule: fraction Pre-release
Pre-release

How to install and import this module:

  1. Download numbmod v0.1.2.
  2. Download this module.
  3. Move these modules to sys.path.
  4. Type from fraction import * .

Start to use

Improper fraction:

>>> a = fraction(1,2)
>>> b = fraction(2,3)
>>> c = fraction(9,4)
>>> d = fraction(2.6)
>>> e = fraction(-1,3)
>>> a
1/2
>>> b
2/3
>>> c
9/4
>>> d
13/5
>>> e
-1/3
>>> a + b
5/6
>>> a - b
1/6
>>> b - a
-1/6
>>> a * b
1/3
>>> a / b
3/4
>>> b / a
4/3
>>> b // a
1
>>> a ** 2
1/4
>>> b ** 3
8/27
>>> a.oppo()
2/1
>>> c ** b.oppo()
3.375
>>> float(a)
0.5
>>> -e
1/3
>>> a.write()
1
-
2
>>>
fraction.write(b ** 3)
8 
--
27
fraction.write(b ** 5)
32 
---
243
fraction.write(e ** 6)
 1 
---
729
>>> fraction(0)
0/1
>>> fraction(1,0)
Traceback(most recent call last):
  File '<stdin>', line 1, in <module>
    fraction(1,0)
ZeroDivisionError: division by zero

Mixed fraction:

>>> a = ifraction(0,1,3)
>>> a
0 1/3
>>> b = ifraction(2,6,9)
>>> b
2 2/3
>>> c = ifraction(1,1,18,neg=True)
>>> c
-1 1/18
>>> d = ifraction(0,9,10,neg=True)
>>> d
-0 9/10

source code:

from numbmod import math as _m
from numbmod import xor
class fraction(object) :
    def __init__(self,d,c=1) :
        if type(d) == fraction :
            dd = d
            cc = fraction(c)
            d = (dd/cc).d
            c = (dd/cc).c
        elif type(d) == ifraction :
            if d.neg :
                dd = fraction(-(d.a*d.c+d.d),d.c)
            else :
                dd = fraction(d.a*d.c+d.d,d.c)
            if type(c) == ifraction :
                if c.neg :
                    cc = fraction(-(c.a*c.c+c.d),c.c)
                else :
                    cc = fraction(c.a*c.c+c.d,c.c)
            else :
                cc = fraction(c)
            d = (dd/cc).d
            c = (dd/cc).c
        else :
            if type(c) == fraction :
                dd = fraction(d)
                cc = c
                d = (dd/cc).d
                c = (dd/cc).c
            elif type(c) == ifraction :
                if c.neg :
                    cc = fraction(-(c.a*c.c+c.d),c.c)
                else :
                    cc = fraction(c.a*c.c+c.d,c.c)
                if type(d) == ifraction :
                    if d.neg :
                        dd = fraction(-(d.a*d.c+d.d),d.c)
                    else :
                        dd = fraction(d.a*d.c+d.d,d.c)
                else :
                    dd = fraction(d)
                d = (dd/cc).d
                c = (dd/cc).c
            elif type(d) == float or type(c) == float :
                p = 10**max(_m.decimallen(d),_m.decimallen(c))
                d *= p
                c *= p
                d = round(d)
                c = round(c)
            if d < 0 and c < 0 : # -|
                d = -d #            |
                c = -c #            |
            elif d < 0 or c < 0 : # -- Set negative fraction.
                d = -abs(d)
                c = abs(c)
            d / c # Check
            gcd = _m.prime.gcd(d,c) # Get greatest common divisor.
            d //= gcd # -|
            c //= gcd # --- Reduce fraction.
        self.d = d
        self.c = c
    def __str__(self) :
        return str(self.d) + "/" + str(self.c)
    def __repr__(self) :
        return str(self.d) + "/" + str(self.c)
    def __float__(self) :
        return self.d / self.c
    def __eq__(self,other) :
        lcm = _m.prime.lcm(self.c,other.c) # Get least common mutiple.
        self.d *= (lcm//self.c) # --|
        other.d *= (lcm//other.c) # -- 
        return self.d == other.d
    def __gt__(self,other) :
        lcm = _m.prime.lcm(self.c,other.c) # Get least common mutiple.
        self.d *= (lcm//self.c) # --|
        other.d *= (lcm//other.c) # -- 
        return self.d > other.d
    def __lt__(self,other) :
        lcm = _m.prime.lcm(self.c,other.c) # Get least common mutiple.
        self.d *= (lcm//self.c) # --|
        other.d *= (lcm//other.c) # -- 
        return self.d < other.d
    def __ge__(self,other) :
        lcm = _m.prime.lcm(self.c,other.c) # Get least common mutiple.
        self.d *= (lcm//self.c) # --|
        other.d *= (lcm//other.c) # -- 
        return self.d >= other.d
    def __le__(self,other) :
        lcm = _m.prime.lcm(self.c,other.c) # Get least common mutiple.
        self.d *= (lcm//self.c) # --|
        other.d *= (lcm//other.c) # -- 
        return self.d <= other.d
    def __ne__(self,other) :
        lcm = _m.prime.lcm(self.c,other.c) # Get least common mutiple.
        self.d *= (lcm//self.c) # --|
        other.d *= (lcm//other.c) # -- 
        return self.d != other.d
    def __abs__(self) :
        return fraction(abs(self.d),abs(self.c))
    def __add__(self,other) :
        lcm = _m.prime.lcm(self.c,other.c)
        return fraction(self.d*(lcm//self.c)+other.d*(lcm//other.c),lcm)
    def __sub__(self,other) :
        lcm = _m.prime.lcm(self.c,other.c)
        return fraction(self.d*(lcm//self.c)-other.d*(lcm//other.c),lcm)
    def __mul__(self,other) :
        return fraction(self.d*other.d,self.c*other.c)
    def __truediv__(self,other) :
        return fraction(self.d*other.c,self.c*other.d)
    def __floordiv__(self,other) :
        return round(float((self/other)-((self/other)%fraction(1))))
    def __pos__(self) :
        return self * fraction(1)
    def __neg__(self) :
        return self * fraction(-1)
    def __mod__(self,other) :
        while self >= fraction(0) :
            self = self - other
        return self + other
    def __pow__(self,other,mod=None) :
        if type(mod) in [int,float,complex,fraction] :
            mod = fraction(mod)
            if type(other) == int :
                res = fraction(1)
                if _m.isnature(other) :
                    for i in range(other) :
                        res *= self
                else :
                    for i in range(other) :
                        res /= self
                res %= mod
                return res
            else :
                return pow(float(self),float(other),float(mod))
        else :
            if type(other) == int :
                res = fraction(1)
                if _m.isnature(other) :
                    for i in range(other) :
                        res *= self
                else :
                    for i in range(other) :
                        res /= self
                return res
            else :
                return pow(float(self),float(other))
    def oppo(self) :
        return fraction(self.c,self.d)
    def write(self) :
        return str(self.d).center(max(len(str(self.d)),len(str(self.c)))) + "\n" + ("-"*max(len(str(self.d)),len(str(self.c)))) + "\n" + str(self.c).center(max(len(str(self.d)),len(str(self.c))))
class ifraction(fraction) :
    def __init__(self,a,d=0,c=1,neg=False) :
        frac = fraction(a) + fraction(d,c)
        if frac < fraction(0) :
            frac = -frac
            neg = not neg
        d = frac.d
        c = frac.c
        a = d // c
        d = abs(d) % c
        self.a = a
        self.d = d
        self.c = c
        self.neg = neg
    def __str__(self) :
        return "-" * self.neg + str(self.a) + " " + str(self.d) + "/" + str(self.c)
    def __repr__(self) :
        return "-" * self.neg + str(self.a) + " " + str(self.d) + "/" + str(self.c)
    def __float__(self) :
        if self.neg :
            return -(self.a + (self.d / self.c))
        else :
            return self.a + (self.d / self.c)
    def __eq__(self,other) :
        return fraction(self) == fraction(other)
    def __gt__(self,other) :
        return fraction(self) > fraction(other)
    def __lt__(self,other) :
        return fraction(self) < fraction(other)
    def __ge__(self,other) :
        return fraction(self) >= fraction(other)
    def __le__(self,other) :
        return fraction(self) <= fraction(other)
    def __ne__(self,other) :
        return fraction(self) != fraction(other)
    def __abs__(self) :
        return ifraction(self.a,self.d,self.c)
    def __add__(self,other) :
        return ifraction(0,(fraction(self)+fraction(other)).d,(fraction(self)+fraction(other)).c)
    def __sub__(self,other) :
        return ifraction(0,(fraction(self)-fraction(other)).d,(fraction(self)-fraction(other)).c)
    def __mul__(self,other) :
        return ifraction(0,(fraction(self)*fraction(other)).d,(fraction(self)*fraction(other)).c)
    def __truediv__(self,other) :
        return ifraction(0,(fraction(self)/fraction(other)).d,(fraction(self)/fraction(other)).c)
    def __floordiv__(self,other) :
        return fraction(self.a*self.c+self.d,self.c) // fraction(other.a*other.c+other.d,other.c)
    def __pos__(self) :
        return self
    def __neg__(self) :
        self.neg = not self.neg
        return self
    def __mod__(self,other) :
        return ifraction(0,(fraction(self)%fraction(other)).d,(fraction(self)%fraction(other)).c)
    def __pow__(self,other,mod=None) :
        if type(mod) in [int,float,complex,fraction,ifraction] :
            if type(other) == int :
                return ifraction(0,pow(fraction(self),other,mod).d,pow(fraction(self),other,mod).c)
            else :
                return pow(float(self),float(other),float(mod))
        else :
            if type(other) == int :
                return ifraction(0,pow(fraction(self),other).d,pow(fraction(self),other).c)
            else :
                return pow(float(self),float(other))
    def oppo(self) :
        return ifraction(fraction(self).oppo())
    def write(self) :
        return (" "*len(str(self.a))) + str(self.d).center(ma...
Read more

PyModule: decimal

30 Sep 15:00
7703168
Compare
Choose a tag to compare
PyModule: decimal Pre-release
Pre-release

A very accurate module!

You can use it to perform addition, subtraction, multiplication, division and remainder operations.
Use a sign or absolute value for it.

How to install and import this module:

  1. Download this module.
  2. Move these modules to sys.path.
  3. Type from decimal import * .

How to use:

>>> a = decimal(2)
>>> b = decimal(5.0)
>>> c = decimal("0.123456789")
>>> d = decimal(0)
>>> e = decimal("-2.5")
>>> a
2
>>> b
5
>>> c
0.123456789
>>> d
0
>>> e
-2.5
>>> a + b
7
>>> a - b
-3
>>> -a
-2
>>> -e
2.5
>>> abs(e)
2.5
>>> len(c)
1
>>> c.len()
[1, 9]
>>> a * b
10
>>> c * d
0
>>> c * c
0.015241578750190521
>>> c * c * c
0.001881676371789154860897069

Verified. Release ID: f