nrt-math-utils


Namenrt-math-utils JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/etuzon/python-nrt-math-utils
SummaryMath utilities in Python
upload_time2024-07-10 19:31:15
maintainerNone
docs_urlNone
authorEyal Tuzon
requires_python>=3.8
licenseNone
keywords python python3 python-3 tool tools math mathematics utilities utils util nrt nrt-utils nrt-utilities math-utils math-utilities nrt-utilities nrt-math-utils nrt-math-utilities
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # Mathematics Utilities

### Mathematics utilities in Python.

![PyPI](https://img.shields.io/pypi/v/nrt-math-utils?color=blueviolet&style=plastic)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/nrt-math-utils?color=greens&style=plastic)
![PyPI - License](https://img.shields.io/pypi/l/nrt-math-utils?color=blue&style=plastic)
![PyPI - Downloads](https://img.shields.io/pypi/dd/nrt-math-utils?style=plastic)
![PyPI - Downloads](https://img.shields.io/pypi/dm/nrt-math-utils?color=yellow&style=plastic)
[![Coverage Status](https://coveralls.io/repos/github/etuzon/python-nrt-math-utils/badge.svg)](https://coveralls.io/github/etuzon/pytohn-nrt-math-utils)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/etuzon/python-nrt-math-utils?style=plastic)
![GitHub last commit](https://img.shields.io/github/last-commit/etuzon/python-nrt-math-utils?style=plastic)
[![DeepSource](https://app.deepsource.com/gh/etuzon/python-nrt-math-utils.svg/?label=active+issues&show_trend=false&token=Ly6vE3lLp94vOwUzDfMzb9Oy)](https://app.deepsource.com/gh/etuzon/python-nrt-math-utils/)

## MathUtil class

### Methods

| **Method**       | **Description**                                                                                           | **Parameters**                                                                                             | **Returns**                                               |
|------------------|-----------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------|
| `average`        | Calculates the weighted average of a list of numbers.                                                     | `numbers (list)` The list of numbers to calculate the average of.<br>`weights (list)` The list of weights. | `DecimalNumber` The average of the numbers.               |
| `floor`          | Returns the floor of a number.                                                                            | `number` The number to calculate the floor of.<br>`digits` Digits amount to cut from the number.           | `number type` The floor of the number.                    |
| `is_all_numbers` | Checks if all elements in a list are numbers.                                                             | `elements (list)` The list of elements to check.                                                           | `bool` True if all elements are numbers, False otherwise. |
| `max`            | Returns the maximum number from variable elements, which can be numbers or an iterable objects like list. | `*elements` Variable arguments, which can be numbers or an iterable objects like list.                     | `number type` The maximum number in the list.             |
| `min`            | Returns the minimum number from variable elements, which can be numbers or an iterable objects like list. | `*elements` Variable arguments, which can be numbers or an iterable objects like list.                     | `number type` The minimum number in the list.             |
| `sum_0_to_n`     | Returns the sum of numbers from 0 to n.                                                                   | `n` The number to sum up to.                                                                               | `number type` The sum of numbers from 0 to n.             |

### Examples:

- #### MathUtil.average

  **Code**
  ```python
  from nrt_math_utils.math_utils import MathUtil
  
  # Calculate the weighted average of a list of numbers
  average = MathUtil.average([1, 2, 3, 4, 5], [1, 5, 6, 7, 8])
  
  print(average)
  ```
  **Output**
  ```
  3.592593
  ```
  
- #### MathUtil.floor
        
  **Code**
  ```python
  from nrt_math_utils.math_utils import MathUtil
  
  # Calculate the floor of a number
  floor = MathUtil.floor(3.14159, 2)
  
  print(floor)
  ```
  **Output**
  ```
  3.14
  ```

- #### MathUtil.is_all_numbers
  
  **Code**
  ```python
  from nrt_math_utils.math_utils import MathUtil

  # Check if all elements in a list are numbers
  is_all_numbers = MathUtil.is_all_numbers([1, 2, 3, 4, 5])

  print(is_all_numbers)
  ```
  **Output**
  ```
  True
  ```

- #### MathUtil.max

  **Code**
  ```python
  from nrt_math_utils.math_utils import MathUtil

  # Get the maximum number from a list
  max_number = MathUtil.max(1, [2, 7, [8, 9]], 3, 4, 5)

  print(max_number)
  ```
  **Output**
  ```
  9
  ```
  
- #### MathUtil.min
    
  **Code**
  ```python
  from nrt_math_utils.math_utils import MathUtil

  # Get the minimum number from a list
  min_number = MathUtil.min(1, [2, 7, [0, 9]], 3, 4, 5)

  print(min_number)
  ```
  **Output**
  ```
  0
  ```

- #### MathUtil.sum_0_to_n
  
  **Code**
  ```python
  from nrt_math_utils.math_utils import MathUtil

  # Get the sum of numbers from 0 to n
  sum_0_to_n = MathUtil.sum_0_to_n(5)

  print(sum_0_to_n)
  ```
  **Output**
  ```
  15
  ```

## DecimalNumber class

Represents a decimal number with a fixed number of decimal places.

### Examples:

- #### Create a DecimalNumber object

  **Code**
  ```python
  from nrt_math_utils.nrt_numbers import DecimalNumber

  # Create a DecimalNumber object with a value of 3.14159 and 2 decimal places
  decimal_number = DecimalNumber(3.14159, 2)

  print(decimal_number)
  ```
  **Output**
  ```
  3.14
  ```
  
- #### Create a DecimalNumber object with default decimal places

  **Code**
  ```python
  from nrt_math_utils.nrt_numbers import DecimalNumber

  # Create a DecimalNumber object with a value of 3.14159 and default 6 decimal places
  decimal_number = DecimalNumber(3.1415926535897)
  print(decimal_number)
  ```

  **Output**
  ```
  3.141593
  ```

- #### Add two DecimalNumber objects

  **Code**
  ```python
  from nrt_math_utils.nrt_numbers import DecimalNumber

  # Create two DecimalNumber objects
  decimal_number_1 = DecimalNumber(3.14159, 2)
  decimal_number_2 = DecimalNumber(2.71828, 2)

  # Add the two DecimalNumber objects
  result = decimal_number_1 + decimal_number_2

  print(result)
  ```
  **Output**
  ```
  5.86
  ```
  
- #### Subtract a number from DecimalNumber

  **Code**
  ```python
  from nrt_math_utils.nrt_numbers import DecimalNumber

  # Create a DecimalNumber object
  decimal_number = DecimalNumber(3.14159, 2)
  
  # Subtract a number from the DecimalNumber object
  result = decimal_number - 1.23456
  
  print(result)
  ```

  **Output**
  ```
  1.91
  ```

- #### Multiply DecimalNumber with other number

  **Code**
  ```python
  from nrt_math_utils.nrt_numbers import DecimalNumber

  # Create a DecimalNumber object
  decimal_number = DecimalNumber(3.14159, 2)

  # Multiply the DecimalNumber object with another number
  result = decimal_number * 2
  
  print(result)
  ```

  **Output**
  ```
  6.28
  ```
  
- #### Compare DecimalNumber to other number

  **Code**
  ```python
  from nrt_math_utils.nrt_numbers import DecimalNumber

  # Create a DecimalNumber object
  decimal_number = DecimalNumber(3.14159, 2)
  
  # Compare the DecimalNumber object to another number
  result = decimal_number > 3.14
  
  print(result)
  ```

  **Output**
  ```
  True
  ```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/etuzon/python-nrt-math-utils",
    "name": "nrt-math-utils",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "python, python3, python-3, tool, tools, math, mathematics, utilities, utils, util, nrt, nrt-utils, nrt-utilities, math-utils, math-utilities, nrt-utilities, nrt-math-utils, nrt-math-utilities",
    "author": "Eyal Tuzon",
    "author_email": "Eyal Tuzon <eyal.tuzon.dev@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/85/5f/7678cc6fdb94d8b3f81d71f8e976fc47428d9e15aa84fe9874c5b80162af/nrt_math_utils-1.0.2.tar.gz",
    "platform": null,
    "description": "# Mathematics Utilities\r\n\r\n### Mathematics utilities in Python.\r\n\r\n![PyPI](https://img.shields.io/pypi/v/nrt-math-utils?color=blueviolet&style=plastic)\r\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/nrt-math-utils?color=greens&style=plastic)\r\n![PyPI - License](https://img.shields.io/pypi/l/nrt-math-utils?color=blue&style=plastic)\r\n![PyPI - Downloads](https://img.shields.io/pypi/dd/nrt-math-utils?style=plastic)\r\n![PyPI - Downloads](https://img.shields.io/pypi/dm/nrt-math-utils?color=yellow&style=plastic)\r\n[![Coverage Status](https://coveralls.io/repos/github/etuzon/python-nrt-math-utils/badge.svg)](https://coveralls.io/github/etuzon/pytohn-nrt-math-utils)\r\n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/etuzon/python-nrt-math-utils?style=plastic)\r\n![GitHub last commit](https://img.shields.io/github/last-commit/etuzon/python-nrt-math-utils?style=plastic)\r\n[![DeepSource](https://app.deepsource.com/gh/etuzon/python-nrt-math-utils.svg/?label=active+issues&show_trend=false&token=Ly6vE3lLp94vOwUzDfMzb9Oy)](https://app.deepsource.com/gh/etuzon/python-nrt-math-utils/)\r\n\r\n## MathUtil class\r\n\r\n### Methods\r\n\r\n| **Method**       | **Description**                                                                                           | **Parameters**                                                                                             | **Returns**                                               |\r\n|------------------|-----------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------|\r\n| `average`        | Calculates the weighted average of a list of numbers.                                                     | `numbers (list)` The list of numbers to calculate the average of.<br>`weights (list)` The list of weights. | `DecimalNumber` The average of the numbers.               |\r\n| `floor`          | Returns the floor of a number.                                                                            | `number` The number to calculate the floor of.<br>`digits` Digits amount to cut from the number.           | `number type` The floor of the number.                    |\r\n| `is_all_numbers` | Checks if all elements in a list are numbers.                                                             | `elements (list)` The list of elements to check.                                                           | `bool` True if all elements are numbers, False otherwise. |\r\n| `max`            | Returns the maximum number from variable elements, which can be numbers or an iterable objects like list. | `*elements` Variable arguments, which can be numbers or an iterable objects like list.                     | `number type` The maximum number in the list.             |\r\n| `min`            | Returns the minimum number from variable elements, which can be numbers or an iterable objects like list. | `*elements` Variable arguments, which can be numbers or an iterable objects like list.                     | `number type` The minimum number in the list.             |\r\n| `sum_0_to_n`     | Returns the sum of numbers from 0 to n.                                                                   | `n` The number to sum up to.                                                                               | `number type` The sum of numbers from 0 to n.             |\r\n\r\n### Examples:\r\n\r\n- #### MathUtil.average\r\n\r\n  **Code**\r\n  ```python\r\n  from nrt_math_utils.math_utils import MathUtil\r\n  \r\n  # Calculate the weighted average of a list of numbers\r\n  average = MathUtil.average([1, 2, 3, 4, 5], [1, 5, 6, 7, 8])\r\n  \r\n  print(average)\r\n  ```\r\n  **Output**\r\n  ```\r\n  3.592593\r\n  ```\r\n  \r\n- #### MathUtil.floor\r\n        \r\n  **Code**\r\n  ```python\r\n  from nrt_math_utils.math_utils import MathUtil\r\n  \r\n  # Calculate the floor of a number\r\n  floor = MathUtil.floor(3.14159, 2)\r\n  \r\n  print(floor)\r\n  ```\r\n  **Output**\r\n  ```\r\n  3.14\r\n  ```\r\n\r\n- #### MathUtil.is_all_numbers\r\n  \r\n  **Code**\r\n  ```python\r\n  from nrt_math_utils.math_utils import MathUtil\r\n\r\n  # Check if all elements in a list are numbers\r\n  is_all_numbers = MathUtil.is_all_numbers([1, 2, 3, 4, 5])\r\n\r\n  print(is_all_numbers)\r\n  ```\r\n  **Output**\r\n  ```\r\n  True\r\n  ```\r\n\r\n- #### MathUtil.max\r\n\r\n  **Code**\r\n  ```python\r\n  from nrt_math_utils.math_utils import MathUtil\r\n\r\n  # Get the maximum number from a list\r\n  max_number = MathUtil.max(1, [2, 7, [8, 9]], 3, 4, 5)\r\n\r\n  print(max_number)\r\n  ```\r\n  **Output**\r\n  ```\r\n  9\r\n  ```\r\n  \r\n- #### MathUtil.min\r\n    \r\n  **Code**\r\n  ```python\r\n  from nrt_math_utils.math_utils import MathUtil\r\n\r\n  # Get the minimum number from a list\r\n  min_number = MathUtil.min(1, [2, 7, [0, 9]], 3, 4, 5)\r\n\r\n  print(min_number)\r\n  ```\r\n  **Output**\r\n  ```\r\n  0\r\n  ```\r\n\r\n- #### MathUtil.sum_0_to_n\r\n  \r\n  **Code**\r\n  ```python\r\n  from nrt_math_utils.math_utils import MathUtil\r\n\r\n  # Get the sum of numbers from 0 to n\r\n  sum_0_to_n = MathUtil.sum_0_to_n(5)\r\n\r\n  print(sum_0_to_n)\r\n  ```\r\n  **Output**\r\n  ```\r\n  15\r\n  ```\r\n\r\n## DecimalNumber class\r\n\r\nRepresents a decimal number with a fixed number of decimal places.\r\n\r\n### Examples:\r\n\r\n- #### Create a DecimalNumber object\r\n\r\n  **Code**\r\n  ```python\r\n  from nrt_math_utils.nrt_numbers import DecimalNumber\r\n\r\n  # Create a DecimalNumber object with a value of 3.14159 and 2 decimal places\r\n  decimal_number = DecimalNumber(3.14159, 2)\r\n\r\n  print(decimal_number)\r\n  ```\r\n  **Output**\r\n  ```\r\n  3.14\r\n  ```\r\n  \r\n- #### Create a DecimalNumber object with default decimal places\r\n\r\n  **Code**\r\n  ```python\r\n  from nrt_math_utils.nrt_numbers import DecimalNumber\r\n\r\n  # Create a DecimalNumber object with a value of 3.14159 and default 6 decimal places\r\n  decimal_number = DecimalNumber(3.1415926535897)\r\n  print(decimal_number)\r\n  ```\r\n\r\n  **Output**\r\n  ```\r\n  3.141593\r\n  ```\r\n\r\n- #### Add two DecimalNumber objects\r\n\r\n  **Code**\r\n  ```python\r\n  from nrt_math_utils.nrt_numbers import DecimalNumber\r\n\r\n  # Create two DecimalNumber objects\r\n  decimal_number_1 = DecimalNumber(3.14159, 2)\r\n  decimal_number_2 = DecimalNumber(2.71828, 2)\r\n\r\n  # Add the two DecimalNumber objects\r\n  result = decimal_number_1 + decimal_number_2\r\n\r\n  print(result)\r\n  ```\r\n  **Output**\r\n  ```\r\n  5.86\r\n  ```\r\n  \r\n- #### Subtract a number from DecimalNumber\r\n\r\n  **Code**\r\n  ```python\r\n  from nrt_math_utils.nrt_numbers import DecimalNumber\r\n\r\n  # Create a DecimalNumber object\r\n  decimal_number = DecimalNumber(3.14159, 2)\r\n  \r\n  # Subtract a number from the DecimalNumber object\r\n  result = decimal_number - 1.23456\r\n  \r\n  print(result)\r\n  ```\r\n\r\n  **Output**\r\n  ```\r\n  1.91\r\n  ```\r\n\r\n- #### Multiply DecimalNumber with other number\r\n\r\n  **Code**\r\n  ```python\r\n  from nrt_math_utils.nrt_numbers import DecimalNumber\r\n\r\n  # Create a DecimalNumber object\r\n  decimal_number = DecimalNumber(3.14159, 2)\r\n\r\n  # Multiply the DecimalNumber object with another number\r\n  result = decimal_number * 2\r\n  \r\n  print(result)\r\n  ```\r\n\r\n  **Output**\r\n  ```\r\n  6.28\r\n  ```\r\n  \r\n- #### Compare DecimalNumber to other number\r\n\r\n  **Code**\r\n  ```python\r\n  from nrt_math_utils.nrt_numbers import DecimalNumber\r\n\r\n  # Create a DecimalNumber object\r\n  decimal_number = DecimalNumber(3.14159, 2)\r\n  \r\n  # Compare the DecimalNumber object to another number\r\n  result = decimal_number > 3.14\r\n  \r\n  print(result)\r\n  ```\r\n\r\n  **Output**\r\n  ```\r\n  True\r\n  ```\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Math utilities in Python",
    "version": "1.0.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/etuzon/python-nrt-math-utils/issues",
        "Homepage": "https://github.com/etuzon/python-nrt-math-utils",
        "documentation": "https://github.com/etuzon/python-nrt-math-utils/wiki"
    },
    "split_keywords": [
        "python",
        " python3",
        " python-3",
        " tool",
        " tools",
        " math",
        " mathematics",
        " utilities",
        " utils",
        " util",
        " nrt",
        " nrt-utils",
        " nrt-utilities",
        " math-utils",
        " math-utilities",
        " nrt-utilities",
        " nrt-math-utils",
        " nrt-math-utilities"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c329095c84f7b7b5610b671259fae75f8d778c9195e8ce2904f8ef665355dc59",
                "md5": "aab5f1312d72263dcbf3a1743b9aefd4",
                "sha256": "6c5822527fbee593adabae8272e48da02ec41e5b5ab981ab7d4c1f78ece76b8c"
            },
            "downloads": -1,
            "filename": "nrt_math_utils-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "aab5f1312d72263dcbf3a1743b9aefd4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 6312,
            "upload_time": "2024-07-10T19:31:13",
            "upload_time_iso_8601": "2024-07-10T19:31:13.904563Z",
            "url": "https://files.pythonhosted.org/packages/c3/29/095c84f7b7b5610b671259fae75f8d778c9195e8ce2904f8ef665355dc59/nrt_math_utils-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "855f7678cc6fdb94d8b3f81d71f8e976fc47428d9e15aa84fe9874c5b80162af",
                "md5": "b2789d5ef2a78b17f129f3bcac371137",
                "sha256": "0efc2bdb2e67d02bdb6110f4de0ae2ed7cfec1dd1597144a1cf2923dbbdf9c37"
            },
            "downloads": -1,
            "filename": "nrt_math_utils-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "b2789d5ef2a78b17f129f3bcac371137",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 6701,
            "upload_time": "2024-07-10T19:31:15",
            "upload_time_iso_8601": "2024-07-10T19:31:15.667571Z",
            "url": "https://files.pythonhosted.org/packages/85/5f/7678cc6fdb94d8b3f81d71f8e976fc47428d9e15aa84fe9874c5b80162af/nrt_math_utils-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-10 19:31:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "etuzon",
    "github_project": "python-nrt-math-utils",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "lcname": "nrt-math-utils"
}
        
Elapsed time: 0.32672s