Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/manu-bhadoria/noir-fixed-point
Fixed point library for Aztec's noir language
https://github.com/manu-bhadoria/noir-fixed-point
Last synced: 4 months ago
JSON representation
Fixed point library for Aztec's noir language
- Host: GitHub
- URL: https://github.com/manu-bhadoria/noir-fixed-point
- Owner: manu-bhadoria
- License: apache-2.0
- Created: 2023-12-04T07:47:21.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2023-12-04T13:33:46.000Z (12 months ago)
- Last Synced: 2024-04-14T02:10:21.424Z (7 months ago)
- Language: Roff
- Size: 387 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-noir - Fixed Point Library - The FixedPoint library offers precise fixed-point arithmetic operations tailored for Noir (Get Coding / Libraries)
README
![Fixed Point Image](fixed-point.png)
# noir-fixed-point
## Fixed point library for Aztec's noir languageThe FixedPoint library offers precise fixed-point arithmetic operations tailored for Noir's unique environment, where every value is fundamentally composed of Field elements. This library is crucial for cryptographic contexts and applications that require exact decimal calculations, such as DeFi applications.
### Features
Robust Fixed-Point Arithmetic: Perform addition, subtraction, multiplication, division, and comparison with fixed-point numbers.
Flexible Scaling: Easily manage the scale (number of decimal places) for precise calculations.
Optimized for Noir: Specifically designed for Noir, ensuring compatibility and efficiency within its ecosystem.### Installation
To use the FixedPoint library in your Noir project, include it as a dependency in your Noir project file.
UsageThe FixedPoint struct represents a fixed-point number with a value and a scale (number of decimal places). Here's how to use it:
Creating a FixedPoint Number```
let fixed_num = FixedPoint::new(value, scale);
```
### Arithmetic OperationsAddition
```
let result = FixedPoint::add(fixed1, fixed2);
```Subtraction
```
let result = FixedPoint::subtract(fixed1, fixed2);
```
Multiplication```
let result = FixedPoint::multiply(fixed1, fixed2);
```
Division```
let result = FixedPoint::divide(fixed1, fixed2);
```
### Comparison```
let is_greater = FixedPoint::is_greater_than(fixed1, fixed2);
let is_lesser = FixedPoint::is_lesser_than(fixed1, fixed2);
```
### Advanced OperationsPower
```
let result = FixedPoint::power(base, exponent);
```
### TestingComprehensive tests are included to ensure the reliability and accuracy of arithmetic operations. Run these tests to verify the functionality in your environment.
```
#[test]
fn test_positive_integer_power() {
let base = FixedPoint::new(2, 2);
let exponent = 3;
let result = FixedPoint::power(base, exponent);
assert(result.value == 8);
assert(result.scale == 2);
}
```### Contribution
Contributions are welcome! If you have suggestions for improvements or encounter any issues, please feel free to submit a pull request or raise an issue.
LicenseThis library is distributed under the Apache License 2.0. See the LICENSE file for more details.