# High Precision Float (HPF) Platform
<!-- <!-- Optional: Add a logo if available -->
A pure Python implementation of a high-precision floating-point arithmetic class, designed to handle mathematical operations with enhanced precision beyond standard floating-point limitations.
## Features
- **High Precision**: Arbitrary precision arithmetic for both integer and fractional parts.
- **Multiple Initialization**: Supports initialization from `str`, `int`, and `float` types.
- **Operator Overloading**: Full support for `+`, `-`, `*`, `/`, `//`, and comparisons.
- **Negative Values**: Handles negative numbers with proper sign propagation.
- **Custom Precision**: Optional precision setting for division operations.
- **String Representation**: Clean string output with automatic trailing zero removal.
## Installation
### From PyPI
Using pip:
```bash
pip install hpf
```
### From Source
1. Use Source:
Simply include the `hpf.py` file in your project and import the class:
```python
from hpf import HighPrecisionFloat # or 'from hpf import hpf, HPF(both OK)'
```
2. Compile Yourself:
There are 2 methods:
- Use setup.py
```bash
git clone https://github.com/zprolab/hpf
cd hpf
pip install setuptools
setup.py install # Auto Install!
```
- Use build (recommend)
```bash
git clone https://github.com/zprolab/hpf
cd hpf
rm -rf ./dist
pip install setuptools build
python -m build # Auto Build!
pip install dist/*.whl
```
## Usage
### Test
```bash
python -m hpf
```
### Initialization
```python
from hpf import HighPrecisionFloat
```
### Abbreviations
```python
from hpf import HighPrecisionFloat as hpf
```
or
```python
from hpf import HighPrecisionFloat as HPF
```
or
```python
from hpf import hpf
```
or
```python
from hpf import HPF
```
```python
a = HighPrecisionFloat("3.14159265358979323846", precision=25)
b = HighPrecisionFloat(-42.75)
c = HighPrecisionFloat(1000)
```
### Basic Arithmetic
```python
x = HighPrecisionFloat("10.5")
y = HighPrecisionFloat("3.2")
print(x + y) # 13.7
print(x - y) # 7.3
print(x * y) # 33.6
print(x / y) # 3.28125
print(x // y) # 3
```
### Comparison Operations
```python
a = HighPrecisionFloat("100.001")
b = HighPrecisionFloat("100.002")
print(a < b) # True
print(a == b) # False
print(a >= b) # False
```
### Sign Manipulation
```python
num = HighPrecisionFloat("-123.45")
num = -num # Convert to positive
print(str(num)) # 123.45
num = +num # Pos marking (no-op)
print(str(num))
```
### Precision Control
```python
# Set precision during initialization
div1 = HighPrecisionFloat("22", precision=50)
div2 = HighPrecisionFloat("7", precision=50)
print(str(div1/div2))
```
## Method Overview
### Core Methods
- `__init__`: Constructor with value parsing
- `_add_abs/_sub_abs`: Internal absolute addition/subtraction
- `_mul_abs/_div_abs`: Internal absolute multiplication/division
- `_abs_greater`: Absolute value comparison
### (TODO) Operator Overloads
- `+`, `-`, `*`, `/`, `//`
- `==`, `!=`, (TODO)`<`, (TODO)`<=`, (TODO)`>`, (TODO)`>=`
### Utility Methods
- `__str__/__repr__`: String representation
- `neg()/pos()`: Sign manipulation
## Considerations
1. **Performance**: Operations on very large numbers or high precision settings may impact performance.
2. **Division Precision**: The `precision` parameter in division defaults to 10 decimal places. Increase this for more precise results.
3. **Zero Handling**: Trailing fractional zeros are automatically removed in string representation.
## License
MIT License - See [LICENSE](LICENSE) file for details.
## Author
Chenyun Z.
Created: Oct 27 2024
Last Updated: Feb 18 2025
## Something...
PyPI is a great invention to make package-managing easier!
GitHub Action is also a great invention to let we needn't to write `python -m build` again and again!
Raw data
{
"_id": null,
"home_page": "https://github.com/zprolab/hpf",
"name": "hpf",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.0",
"maintainer_email": null,
"keywords": "math",
"author": "Chenyun Zhang",
"author_email": "\"Chenyun Z.\" <zcy@hi-zcy.com>",
"download_url": "https://files.pythonhosted.org/packages/00/d0/f2c6c2ecd9802cf0a4b2d417c2c452c76dff4305462f7bfc599c1d894010/hpf-0.3.7.tar.gz",
"platform": null,
"description": "# High Precision Float (HPF) Platform\n\n<!-- <!-- Optional: Add a logo if available --> \n\nA pure Python implementation of a high-precision floating-point arithmetic class, designed to handle mathematical operations with enhanced precision beyond standard floating-point limitations.\n\n## Features\n\n- **High Precision**: Arbitrary precision arithmetic for both integer and fractional parts.\n- **Multiple Initialization**: Supports initialization from `str`, `int`, and `float` types.\n- **Operator Overloading**: Full support for `+`, `-`, `*`, `/`, `//`, and comparisons.\n- **Negative Values**: Handles negative numbers with proper sign propagation.\n- **Custom Precision**: Optional precision setting for division operations.\n- **String Representation**: Clean string output with automatic trailing zero removal.\n\n## Installation\n\n### From PyPI\n\nUsing pip:\n```bash\npip install hpf\n```\n\n### From Source\n\n1. Use Source:\n\nSimply include the `hpf.py` file in your project and import the class:\n\n```python\nfrom hpf import HighPrecisionFloat # or 'from hpf import hpf, HPF(both OK)'\n```\n\n2. Compile Yourself:\n\nThere are 2 methods: \n - Use setup.py\n```bash\ngit clone https://github.com/zprolab/hpf\ncd hpf \npip install setuptools\nsetup.py install # Auto Install!\n```\n - Use build (recommend)\n```bash\ngit clone https://github.com/zprolab/hpf\ncd hpf \nrm -rf ./dist\npip install setuptools build\npython -m build # Auto Build!\npip install dist/*.whl\n```\n\n## Usage\n\n### Test\n```bash\npython -m hpf\n```\n\n### Initialization\n```python\nfrom hpf import HighPrecisionFloat\n```\n\n### Abbreviations\n```python\nfrom hpf import HighPrecisionFloat as hpf\n```\nor\n```python\nfrom hpf import HighPrecisionFloat as HPF\n```\nor\n```python\nfrom hpf import hpf\n```\nor\n```python\nfrom hpf import HPF\n```\n\n```python\na = HighPrecisionFloat(\"3.14159265358979323846\", precision=25)\nb = HighPrecisionFloat(-42.75)\nc = HighPrecisionFloat(1000)\n```\n\n### Basic Arithmetic\n```python\nx = HighPrecisionFloat(\"10.5\")\ny = HighPrecisionFloat(\"3.2\")\n\nprint(x + y) # 13.7\nprint(x - y) # 7.3\nprint(x * y) # 33.6\nprint(x / y) # 3.28125\nprint(x // y) # 3\n```\n\n### Comparison Operations\n```python\na = HighPrecisionFloat(\"100.001\")\nb = HighPrecisionFloat(\"100.002\")\n\nprint(a < b) # True\nprint(a == b) # False\nprint(a >= b) # False\n```\n\n### Sign Manipulation\n```python\nnum = HighPrecisionFloat(\"-123.45\")\nnum = -num # Convert to positive\nprint(str(num)) # 123.45\n\nnum = +num # Pos marking (no-op)\nprint(str(num))\n```\n\n### Precision Control\n```python\n# Set precision during initialization\ndiv1 = HighPrecisionFloat(\"22\", precision=50)\ndiv2 = HighPrecisionFloat(\"7\", precision=50)\nprint(str(div1/div2))\n```\n\n## Method Overview\n\n### Core Methods\n- `__init__`: Constructor with value parsing\n- `_add_abs/_sub_abs`: Internal absolute addition/subtraction\n- `_mul_abs/_div_abs`: Internal absolute multiplication/division\n- `_abs_greater`: Absolute value comparison\n\n### (TODO) Operator Overloads\n- `+`, `-`, `*`, `/`, `//`\n- `==`, `!=`, (TODO)`<`, (TODO)`<=`, (TODO)`>`, (TODO)`>=`\n\n### Utility Methods\n- `__str__/__repr__`: String representation\n- `neg()/pos()`: Sign manipulation\n\n## Considerations\n\n1. **Performance**: Operations on very large numbers or high precision settings may impact performance.\n2. **Division Precision**: The `precision` parameter in division defaults to 10 decimal places. Increase this for more precise results.\n3. **Zero Handling**: Trailing fractional zeros are automatically removed in string representation.\n\n## License\nMIT License - See [LICENSE](LICENSE) file for details.\n\n## Author\nChenyun Z. \nCreated: Oct 27 2024 \nLast Updated: Feb 18 2025\n\n## Something...\nPyPI is a great invention to make package-managing easier!\n\nGitHub Action is also a great invention to let we needn't to write `python -m build` again and again!\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "A high precision floating-point arithmetic module",
"version": "0.3.7",
"project_urls": {
"Homepage": "https://github.com/zprolab/hpf"
},
"split_keywords": [
"math"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "4628d361afd065a8c745f09b29836fac2a5e70f4536797a12383bd746c086aa6",
"md5": "61a9b8279e545cfdb84e264477c878bd",
"sha256": "370b24b98754bc1d95dc06541143b9a963139226dc86bb63fe3202428e77ba40"
},
"downloads": -1,
"filename": "hpf-0.3.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "61a9b8279e545cfdb84e264477c878bd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.0",
"size": 6430,
"upload_time": "2025-02-18T12:10:48",
"upload_time_iso_8601": "2025-02-18T12:10:48.047057Z",
"url": "https://files.pythonhosted.org/packages/46/28/d361afd065a8c745f09b29836fac2a5e70f4536797a12383bd746c086aa6/hpf-0.3.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "00d0f2c6c2ecd9802cf0a4b2d417c2c452c76dff4305462f7bfc599c1d894010",
"md5": "ea57f65bad6fab9a68dcc5f92c742701",
"sha256": "fe2e32d33ec0755d9ef680162c58f0b52d182bf3e31de5c2e82349d48649da96"
},
"downloads": -1,
"filename": "hpf-0.3.7.tar.gz",
"has_sig": false,
"md5_digest": "ea57f65bad6fab9a68dcc5f92c742701",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.0",
"size": 6345,
"upload_time": "2025-02-18T12:10:49",
"upload_time_iso_8601": "2025-02-18T12:10:49.064964Z",
"url": "https://files.pythonhosted.org/packages/00/d0/f2c6c2ecd9802cf0a4b2d417c2c452c76dff4305462f7bfc599c1d894010/hpf-0.3.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-18 12:10:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "zprolab",
"github_project": "hpf",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "hpf"
}