Metadata-Version: 2.4
Name: rithmetic
Version: 0.0.14
Summary: Simple arithmetic lib for students
Home-page: https://github.com/Prashant-Aswal/rithmetic
Author: PrashantAswal
Author-email: prashant.aswal89@gmail.com
License: MIT
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: summary

**\__rithmetic__**

“rithmetic” is a budding python library which aims to provide arithmetic and math assistance to students using python to build math related functionality or apps.

**How to Install:**

Run the following command in Terminal/CLI –

- pip install rithmetic

If you are updating to a new version of rithmetic:

- pip install rithmetic --force-reinstall

After installation completes, run the following command in Terminal/CLI to see the welcome message –

- rith

To check the version of rithmetic, run the following command in Terminal/CLI –

- rith-version

**License and terms of use:**

rithmetic comes with the MIT license which means that anyone, anywhere can use it for any open source or even closed source application.

**Current functionality:**

1. Convert a number from one base to another (Converters)
2. Check/Verify if a number is from a specified base (Verifiers)
3. Add, Subtract, Multiply and Divide any two numbers in desired base (Operators)

**Best way to import:**

Import all the functions from rithmetic at once

from rithmetic import \*

**Functions:**

Converters

**base(num, fromB, toB)**

Converts any number from one base to another. (supported bases are base-2 to base-16)

num – any number | can be **int** or **float** or **str** type

fromB – base of ‘num’ | can be both **int** and **str** type

toB – ‘num’ gets converted to this base | can be both **int** and **str** type

Returns – The converted number in **int** or **str** or **float** type OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rithmetic import \*  
<br/>number = base(1111,2,16)  
print(number)

This will print ‘F’. As 1111 in binary gets converted to F in hexadecimal.

**dectosub(num, toB)**

Converts any number from Decimal to any other sub-decimal base. (supported bases are base-2 to base-9)

num – any number | can be **int** or **float** or **str** type

toB – ‘num’ gets converted to this base | can be both **int** and **str** type

Returns – The converted number in **int** or **str** type OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rithmetic import \*  
<br/>number = dectosub(23,5)  
print(number)

This will print 43. As 23 in decimal gets converted to 43 in base-5.

**subtodec(num, fromB)**

Converts any number from any sub-decimal base to Decimal. (supported bases are base-2 to base-9)

num – any number | can be **int** or **float** or **str** type

fromB – base of ‘num’ | can be both **int** and **str** type

Returns – The converted number in **int** or **float** type OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rithmetic import \*  
<br/>number = subtodec(25,6)  
print(number)

This will print 17. As 25 in base-6 gets converted to 17 in decimal.

Quick single parameter converters

- **_Decimal to another base:_**

**dectob2(num)**

**dectob3(num)**

**dectob4(num)**

**dectob5(num)**

**dectob6(num)**

**dectob7(num)**

**dectob8(num)**

**dectob9(num)**

**dectob11(num)**

**dectob12(num)**

**dectob13(num)**

**dectob14(num)**

**dectob15(num)**

**dectob16(num)**

num – any number | can be **int** or **float** or **str** type

Return – The converted number in **int** or **str** type OR ‘Invalid number’

- **_Any base to Decimal_**

**b2todec(num)**

**b3todec(num)**

**b4todec(num)**

**b5todec(num)**

**b6todec(num)**

**b7todec(num)**

**b8todec(num)**

**b9todec(num)**

**b11todec(num)**

**b12todec(num)**

**b13todec(num)**

**b14todec(num)**

**b15todec(num)**

**b16todec(num)**

num – any number | can be **int** or **float** or **str** type

Return – The converted number in **int** or **float** type OR ‘Invalid number’

Verifiers

**chkbase(num, base)**

Checks if a number is from a specified base. (supported bases are base-2 to base-16)

num – any number | can be **int** or **float** or **str** type

base – base of ‘num’ to be checked | can be both **int** and **str** type

Returns – True OR False OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rithmetic import \*  
<br/>check = chkbase('23F',16)  
print(check)

This will print True. As 23F is from base-16.

Quick single parameter verifiers

**chk2(num)**

**chk3(num)**

**chk4(num)**

**chk5(num)**

**chk6(num)**

**chk7(num)**

**chk8(num)**

**chk9(num)**

**chk10(num)**

**chk11(num)**

**chk12(num)**

**chk13(num)**

**chk14(num)**

**chk15(num)**

**chk16(num)**

num – any number | can be **int** or **float** or **str** type

Return – True OR False OR ‘Invalid number’

Operators

**add(num1, num2, Base)**

Adds two numbers in desired base. (supported bases are base-2 to base-16)

num1 – any number | can be **int** or **float** or **str** type

num2 – any number, which will be added to ‘num1’ | can be **int** or **float** or **str** type

Base– base of num1 and num2 | can be both **int** and **str** type

Returns – The resultant number in **int** or **str** type OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rithmetic import \*  
<br/>sum = add('2a',12,11)  
print(sum)

This will print 41. As (2a + 12) in base-11 is 41.

**sub(num1, num2, Base)**

Subtracts one number from another in desired base. (supported bases are base-2 to base-16)

num1 – any number | can be **int** or **float** or **str** type

num2 – any number, which will be subtracted from ‘num1’ | can be **int** or **float** or **str** type

Base– base of num1 and num2 | can be both **int** and **str** type

Returns – The resultant number in **int** or **str** type OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rithmetic import \*  
<br/>diff = sub(23,'6e',16)  
print(diff)

This will print -4B. As (23 – 6E) in base-16 is -4B.

**mul(num1, num2, Base)**

Multiplies two numbers in desired base. (supported bases are base-2 to base-16)

num1 – any number | can be **int** or **float** or **str** type

num2 – any number, which will be multiplied with ‘num1’ | can be **int** or **float** or **str** type

Base– base of num1 and num2 | can be both **int** and **str** type

Returns – The resultant number in **int** or **str** type OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rithmetic import \*  
<br/>prod = mul(12,24,11)  
print(prod)

This will print 288. As (12 \* 24) in base-11 is 288.

**div(num1, num2, Base)**

Divides a number by another in desired base. (supported bases are base-2 to base-16)

num1 – any number | can be **int** or **float** or **str** type

num2 – any number, ‘num1’ will be divided by this | can be **int** or **float** or **str** type

Base– base of num1 and num2 | can be both **int** and **str** type

Returns – The resultant number in **int** or **str** type OR ‘Invalid number’ OR ‘Invalid base value’

Example:

from rith import \*  
<br/>quo = div(22,13,13)  
print(quo)

This will print 1.99999999999999. AS (22 / 13) in base-13 is 1.99999999999999

**Disclaimer –** rithmetic functions do not round off any numbers and the max level of decimal points is set to 100. So, you will find some **str** type output values with a large number of decimal points (limited to a max of 100).
