From 0b64cbfe3655dbc8f1b217856a20710595353d0f Mon Sep 17 00:00:00 2001 From: K1-R1 <77465250+K1-R1@users.noreply.github.com> Date: Thu, 1 Aug 2024 13:32:12 +0100 Subject: [PATCH] Deprecate Fixed Point library (#278) --- CHANGELOG.md | 5 +- README.md | 4 +- docs/book/src/SUMMARY.md | 1 - docs/book/src/fixed_point/index.md | 87 --- docs/book/src/index.md | 4 - examples/Forc.lock | 8 - examples/Forc.toml | 1 - examples/fixed_point/Forc.toml | 8 - examples/fixed_point/src/main.sw | 60 -- libs/src/fixed_point.sw | 8 - libs/src/fixed_point/ifp128.sw | 570 ------------------ libs/src/fixed_point/ifp256.sw | 570 ------------------ libs/src/fixed_point/ifp64.sw | 570 ------------------ libs/src/fixed_point/ufp128.sw | 483 --------------- libs/src/fixed_point/ufp32.sw | 507 ---------------- libs/src/fixed_point/ufp64.sw | 502 --------------- libs/src/lib.sw | 1 - tests/Forc.lock | 184 ------ tests/Forc.toml | 23 - .../fixed_point/ifp128_div_test/.gitignore | 2 - .../src/fixed_point/ifp128_div_test/Forc.toml | 8 - tests/src/fixed_point/ifp128_div_test/mod.rs | 1 - .../fixed_point/ifp128_div_test/src/main.sw | 24 - .../fixed_point/ifp128_div_test/tests/mod.rs | 22 - tests/src/fixed_point/ifp128_test/.gitignore | 2 - tests/src/fixed_point/ifp128_test/Forc.toml | 8 - tests/src/fixed_point/ifp128_test/mod.rs | 1 - tests/src/fixed_point/ifp128_test/src/main.sw | 130 ---- .../src/fixed_point/ifp128_test/tests/mod.rs | 22 - .../fixed_point/ifp256_div_test/.gitignore | 2 - .../src/fixed_point/ifp256_div_test/Forc.toml | 8 - tests/src/fixed_point/ifp256_div_test/mod.rs | 1 - .../fixed_point/ifp256_div_test/src/main.sw | 25 - .../fixed_point/ifp256_div_test/tests/mod.rs | 22 - tests/src/fixed_point/ifp256_test/.gitignore | 2 - tests/src/fixed_point/ifp256_test/Forc.toml | 8 - tests/src/fixed_point/ifp256_test/mod.rs | 1 - tests/src/fixed_point/ifp256_test/src/main.sw | 130 ---- .../src/fixed_point/ifp256_test/tests/mod.rs | 22 - .../src/fixed_point/ifp64_div_test/.gitignore | 2 - .../src/fixed_point/ifp64_div_test/Forc.toml | 8 - tests/src/fixed_point/ifp64_div_test/mod.rs | 1 - .../fixed_point/ifp64_div_test/src/main.sw | 32 - .../fixed_point/ifp64_div_test/tests/mod.rs | 22 - .../src/fixed_point/ifp64_exp_test/.gitignore | 2 - .../src/fixed_point/ifp64_exp_test/Forc.toml | 8 - tests/src/fixed_point/ifp64_exp_test/mod.rs | 1 - .../fixed_point/ifp64_exp_test/src/main.sw | 28 - .../fixed_point/ifp64_exp_test/tests/mod.rs | 21 - .../src/fixed_point/ifp64_mul_test/.gitignore | 2 - .../src/fixed_point/ifp64_mul_test/Forc.toml | 8 - tests/src/fixed_point/ifp64_mul_test/mod.rs | 1 - .../fixed_point/ifp64_mul_test/src/main.sw | 33 - .../fixed_point/ifp64_mul_test/tests/mod.rs | 22 - .../src/fixed_point/ifp64_pow_test/.gitignore | 2 - .../src/fixed_point/ifp64_pow_test/Forc.toml | 8 - tests/src/fixed_point/ifp64_pow_test/mod.rs | 1 - .../fixed_point/ifp64_pow_test/src/main.sw | 28 - .../fixed_point/ifp64_pow_test/tests/mod.rs | 21 - tests/src/fixed_point/ifp64_test/.gitignore | 2 - tests/src/fixed_point/ifp64_test/Forc.toml | 8 - tests/src/fixed_point/ifp64_test/mod.rs | 1 - tests/src/fixed_point/ifp64_test/src/main.sw | 145 ----- tests/src/fixed_point/ifp64_test/tests/mod.rs | 22 - tests/src/fixed_point/mod.rs | 23 - .../fixed_point/ufp128_div_test/.gitignore | 2 - .../src/fixed_point/ufp128_div_test/Forc.toml | 8 - tests/src/fixed_point/ufp128_div_test/mod.rs | 1 - .../fixed_point/ufp128_div_test/src/main.sw | 25 - .../fixed_point/ufp128_div_test/tests/mod.rs | 22 - tests/src/fixed_point/ufp128_test/.gitignore | 2 - tests/src/fixed_point/ufp128_test/Forc.toml | 8 - tests/src/fixed_point/ufp128_test/mod.rs | 1 - tests/src/fixed_point/ufp128_test/src/main.sw | 70 --- .../src/fixed_point/ufp128_test/tests/mod.rs | 22 - .../src/fixed_point/ufp32_div_test/.gitignore | 2 - .../src/fixed_point/ufp32_div_test/Forc.toml | 8 - tests/src/fixed_point/ufp32_div_test/mod.rs | 1 - .../fixed_point/ufp32_div_test/src/main.sw | 32 - .../fixed_point/ufp32_div_test/tests/mod.rs | 22 - .../src/fixed_point/ufp32_exp_test/.gitignore | 2 - .../src/fixed_point/ufp32_exp_test/Forc.toml | 8 - tests/src/fixed_point/ufp32_exp_test/mod.rs | 1 - .../fixed_point/ufp32_exp_test/src/main.sw | 28 - .../fixed_point/ufp32_exp_test/tests/mod.rs | 21 - .../src/fixed_point/ufp32_mul_test/.gitignore | 2 - .../src/fixed_point/ufp32_mul_test/Forc.toml | 8 - tests/src/fixed_point/ufp32_mul_test/mod.rs | 1 - .../fixed_point/ufp32_mul_test/src/main.sw | 33 - .../fixed_point/ufp32_mul_test/tests/mod.rs | 22 - .../src/fixed_point/ufp32_pow_test/.gitignore | 2 - .../src/fixed_point/ufp32_pow_test/Forc.toml | 8 - tests/src/fixed_point/ufp32_pow_test/mod.rs | 1 - .../fixed_point/ufp32_pow_test/src/main.sw | 28 - .../fixed_point/ufp32_pow_test/tests/mod.rs | 21 - .../fixed_point/ufp32_root_test/.gitignore | 2 - .../src/fixed_point/ufp32_root_test/Forc.toml | 8 - tests/src/fixed_point/ufp32_root_test/mod.rs | 1 - .../fixed_point/ufp32_root_test/src/main.sw | 28 - .../fixed_point/ufp32_root_test/tests/mod.rs | 22 - tests/src/fixed_point/ufp32_test/.gitignore | 2 - tests/src/fixed_point/ufp32_test/Forc.toml | 8 - tests/src/fixed_point/ufp32_test/mod.rs | 1 - tests/src/fixed_point/ufp32_test/src/main.sw | 70 --- tests/src/fixed_point/ufp32_test/tests/mod.rs | 22 - .../src/fixed_point/ufp64_div_test/.gitignore | 2 - .../src/fixed_point/ufp64_div_test/Forc.toml | 8 - tests/src/fixed_point/ufp64_div_test/mod.rs | 1 - .../fixed_point/ufp64_div_test/src/main.sw | 32 - .../fixed_point/ufp64_div_test/tests/mod.rs | 22 - .../src/fixed_point/ufp64_exp_test/.gitignore | 2 - .../src/fixed_point/ufp64_exp_test/Forc.toml | 8 - tests/src/fixed_point/ufp64_exp_test/mod.rs | 1 - .../fixed_point/ufp64_exp_test/src/main.sw | 28 - .../fixed_point/ufp64_exp_test/tests/mod.rs | 21 - .../src/fixed_point/ufp64_mul_test/.gitignore | 2 - .../src/fixed_point/ufp64_mul_test/Forc.toml | 8 - tests/src/fixed_point/ufp64_mul_test/mod.rs | 1 - .../fixed_point/ufp64_mul_test/src/main.sw | 33 - .../fixed_point/ufp64_mul_test/tests/mod.rs | 22 - .../src/fixed_point/ufp64_pow_test/.gitignore | 2 - .../src/fixed_point/ufp64_pow_test/Forc.toml | 8 - tests/src/fixed_point/ufp64_pow_test/mod.rs | 1 - .../fixed_point/ufp64_pow_test/src/main.sw | 28 - .../fixed_point/ufp64_pow_test/tests/mod.rs | 21 - .../fixed_point/ufp64_root_test/.gitignore | 2 - .../src/fixed_point/ufp64_root_test/Forc.toml | 8 - tests/src/fixed_point/ufp64_root_test/mod.rs | 1 - .../fixed_point/ufp64_root_test/src/main.sw | 28 - .../fixed_point/ufp64_root_test/tests/mod.rs | 22 - tests/src/fixed_point/ufp64_test/.gitignore | 2 - tests/src/fixed_point/ufp64_test/Forc.toml | 8 - tests/src/fixed_point/ufp64_test/mod.rs | 1 - tests/src/fixed_point/ufp64_test/src/main.sw | 70 --- tests/src/fixed_point/ufp64_test/tests/mod.rs | 22 - tests/src/harness.rs | 1 - 136 files changed, 7 insertions(+), 5474 deletions(-) delete mode 100644 docs/book/src/fixed_point/index.md delete mode 100644 examples/fixed_point/Forc.toml delete mode 100644 examples/fixed_point/src/main.sw delete mode 100644 libs/src/fixed_point.sw delete mode 100644 libs/src/fixed_point/ifp128.sw delete mode 100644 libs/src/fixed_point/ifp256.sw delete mode 100644 libs/src/fixed_point/ifp64.sw delete mode 100644 libs/src/fixed_point/ufp128.sw delete mode 100644 libs/src/fixed_point/ufp32.sw delete mode 100644 libs/src/fixed_point/ufp64.sw delete mode 100644 tests/src/fixed_point/ifp128_div_test/.gitignore delete mode 100644 tests/src/fixed_point/ifp128_div_test/Forc.toml delete mode 100644 tests/src/fixed_point/ifp128_div_test/mod.rs delete mode 100644 tests/src/fixed_point/ifp128_div_test/src/main.sw delete mode 100644 tests/src/fixed_point/ifp128_div_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ifp128_test/.gitignore delete mode 100644 tests/src/fixed_point/ifp128_test/Forc.toml delete mode 100644 tests/src/fixed_point/ifp128_test/mod.rs delete mode 100644 tests/src/fixed_point/ifp128_test/src/main.sw delete mode 100644 tests/src/fixed_point/ifp128_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ifp256_div_test/.gitignore delete mode 100644 tests/src/fixed_point/ifp256_div_test/Forc.toml delete mode 100644 tests/src/fixed_point/ifp256_div_test/mod.rs delete mode 100644 tests/src/fixed_point/ifp256_div_test/src/main.sw delete mode 100644 tests/src/fixed_point/ifp256_div_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ifp256_test/.gitignore delete mode 100644 tests/src/fixed_point/ifp256_test/Forc.toml delete mode 100644 tests/src/fixed_point/ifp256_test/mod.rs delete mode 100644 tests/src/fixed_point/ifp256_test/src/main.sw delete mode 100644 tests/src/fixed_point/ifp256_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ifp64_div_test/.gitignore delete mode 100644 tests/src/fixed_point/ifp64_div_test/Forc.toml delete mode 100644 tests/src/fixed_point/ifp64_div_test/mod.rs delete mode 100644 tests/src/fixed_point/ifp64_div_test/src/main.sw delete mode 100644 tests/src/fixed_point/ifp64_div_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ifp64_exp_test/.gitignore delete mode 100644 tests/src/fixed_point/ifp64_exp_test/Forc.toml delete mode 100644 tests/src/fixed_point/ifp64_exp_test/mod.rs delete mode 100644 tests/src/fixed_point/ifp64_exp_test/src/main.sw delete mode 100644 tests/src/fixed_point/ifp64_exp_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ifp64_mul_test/.gitignore delete mode 100644 tests/src/fixed_point/ifp64_mul_test/Forc.toml delete mode 100644 tests/src/fixed_point/ifp64_mul_test/mod.rs delete mode 100644 tests/src/fixed_point/ifp64_mul_test/src/main.sw delete mode 100644 tests/src/fixed_point/ifp64_mul_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ifp64_pow_test/.gitignore delete mode 100644 tests/src/fixed_point/ifp64_pow_test/Forc.toml delete mode 100644 tests/src/fixed_point/ifp64_pow_test/mod.rs delete mode 100644 tests/src/fixed_point/ifp64_pow_test/src/main.sw delete mode 100644 tests/src/fixed_point/ifp64_pow_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ifp64_test/.gitignore delete mode 100644 tests/src/fixed_point/ifp64_test/Forc.toml delete mode 100644 tests/src/fixed_point/ifp64_test/mod.rs delete mode 100644 tests/src/fixed_point/ifp64_test/src/main.sw delete mode 100644 tests/src/fixed_point/ifp64_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/mod.rs delete mode 100644 tests/src/fixed_point/ufp128_div_test/.gitignore delete mode 100644 tests/src/fixed_point/ufp128_div_test/Forc.toml delete mode 100644 tests/src/fixed_point/ufp128_div_test/mod.rs delete mode 100644 tests/src/fixed_point/ufp128_div_test/src/main.sw delete mode 100644 tests/src/fixed_point/ufp128_div_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ufp128_test/.gitignore delete mode 100644 tests/src/fixed_point/ufp128_test/Forc.toml delete mode 100644 tests/src/fixed_point/ufp128_test/mod.rs delete mode 100644 tests/src/fixed_point/ufp128_test/src/main.sw delete mode 100644 tests/src/fixed_point/ufp128_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ufp32_div_test/.gitignore delete mode 100644 tests/src/fixed_point/ufp32_div_test/Forc.toml delete mode 100644 tests/src/fixed_point/ufp32_div_test/mod.rs delete mode 100644 tests/src/fixed_point/ufp32_div_test/src/main.sw delete mode 100644 tests/src/fixed_point/ufp32_div_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ufp32_exp_test/.gitignore delete mode 100644 tests/src/fixed_point/ufp32_exp_test/Forc.toml delete mode 100644 tests/src/fixed_point/ufp32_exp_test/mod.rs delete mode 100644 tests/src/fixed_point/ufp32_exp_test/src/main.sw delete mode 100644 tests/src/fixed_point/ufp32_exp_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ufp32_mul_test/.gitignore delete mode 100644 tests/src/fixed_point/ufp32_mul_test/Forc.toml delete mode 100644 tests/src/fixed_point/ufp32_mul_test/mod.rs delete mode 100644 tests/src/fixed_point/ufp32_mul_test/src/main.sw delete mode 100644 tests/src/fixed_point/ufp32_mul_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ufp32_pow_test/.gitignore delete mode 100644 tests/src/fixed_point/ufp32_pow_test/Forc.toml delete mode 100644 tests/src/fixed_point/ufp32_pow_test/mod.rs delete mode 100644 tests/src/fixed_point/ufp32_pow_test/src/main.sw delete mode 100644 tests/src/fixed_point/ufp32_pow_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ufp32_root_test/.gitignore delete mode 100644 tests/src/fixed_point/ufp32_root_test/Forc.toml delete mode 100644 tests/src/fixed_point/ufp32_root_test/mod.rs delete mode 100644 tests/src/fixed_point/ufp32_root_test/src/main.sw delete mode 100644 tests/src/fixed_point/ufp32_root_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ufp32_test/.gitignore delete mode 100644 tests/src/fixed_point/ufp32_test/Forc.toml delete mode 100644 tests/src/fixed_point/ufp32_test/mod.rs delete mode 100644 tests/src/fixed_point/ufp32_test/src/main.sw delete mode 100644 tests/src/fixed_point/ufp32_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ufp64_div_test/.gitignore delete mode 100644 tests/src/fixed_point/ufp64_div_test/Forc.toml delete mode 100644 tests/src/fixed_point/ufp64_div_test/mod.rs delete mode 100644 tests/src/fixed_point/ufp64_div_test/src/main.sw delete mode 100644 tests/src/fixed_point/ufp64_div_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ufp64_exp_test/.gitignore delete mode 100644 tests/src/fixed_point/ufp64_exp_test/Forc.toml delete mode 100644 tests/src/fixed_point/ufp64_exp_test/mod.rs delete mode 100644 tests/src/fixed_point/ufp64_exp_test/src/main.sw delete mode 100644 tests/src/fixed_point/ufp64_exp_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ufp64_mul_test/.gitignore delete mode 100644 tests/src/fixed_point/ufp64_mul_test/Forc.toml delete mode 100644 tests/src/fixed_point/ufp64_mul_test/mod.rs delete mode 100644 tests/src/fixed_point/ufp64_mul_test/src/main.sw delete mode 100644 tests/src/fixed_point/ufp64_mul_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ufp64_pow_test/.gitignore delete mode 100644 tests/src/fixed_point/ufp64_pow_test/Forc.toml delete mode 100644 tests/src/fixed_point/ufp64_pow_test/mod.rs delete mode 100644 tests/src/fixed_point/ufp64_pow_test/src/main.sw delete mode 100644 tests/src/fixed_point/ufp64_pow_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ufp64_root_test/.gitignore delete mode 100644 tests/src/fixed_point/ufp64_root_test/Forc.toml delete mode 100644 tests/src/fixed_point/ufp64_root_test/mod.rs delete mode 100644 tests/src/fixed_point/ufp64_root_test/src/main.sw delete mode 100644 tests/src/fixed_point/ufp64_root_test/tests/mod.rs delete mode 100644 tests/src/fixed_point/ufp64_test/.gitignore delete mode 100644 tests/src/fixed_point/ufp64_test/Forc.toml delete mode 100644 tests/src/fixed_point/ufp64_test/mod.rs delete mode 100644 tests/src/fixed_point/ufp64_test/src/main.sw delete mode 100644 tests/src/fixed_point/ufp64_test/tests/mod.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 367d377f..6970b2b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Description of the upcoming release here. - [#265](https://github.com/FuelLabs/sway-libs/pull/265) Enables the metadata events now that the Rust SDK supports wrapped heap types. - [#269](https://github.com/FuelLabs/sway-libs/pull/269) Hashes the string "admin" and with the bits of an Identity when creating a storage slot to storage an admin in the Admin Library. +- [#278](https://github.com/FuelLabs/sway-libs/pull/278) Deprecates the Fixed Point number library. ### Fixed @@ -34,7 +35,7 @@ Description of the upcoming release here. #### Breaking - [#263](https://github.com/FuelLabs/sway-libs/pull/263) Removes the `TwosComplement` trait in favor of `WrappingNeg`. - + The following demonstrates the breaking change. While this example code uses the `I8` type, the same logic may be applied to the `I16`, `I32`, `I64`, `I128`, and `I256` types. Before: @@ -80,3 +81,5 @@ After: ```sway let my_negative_i8: I8 = I8::neg_try_from(1u8).unwrap(); ``` + +- [#278](https://github.com/FuelLabs/sway-libs/pull/278) Deprecates the Fixed Point number library. The Fixed Point number library is no longer available. diff --git a/README.md b/README.md index a9498260..4792cdf8 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,11 @@ For implementation details on the libraries please see the [Sway Libs Docs](http #### Math -- [Fixed Point Number](https://docs.fuel.network/docs/sway-libs/fixed_point/) is an interface to implement fixed-point numbers. - [Signed Integers](https://docs.fuel.network/docs/sway-libs/queue/) is an interface to implement signed integers. +> **NOTE:** +> The Fixed Point Number library has been deprecated pending a re-write. + #### Data Structures - [Queue](https://docs.fuel.network/docs/sway-libs/queue/) is a linear data structure that provides First-In-First-Out (FIFO) operations. diff --git a/docs/book/src/SUMMARY.md b/docs/book/src/SUMMARY.md index a2a49269..499bdaa0 100644 --- a/docs/book/src/SUMMARY.md +++ b/docs/book/src/SUMMARY.md @@ -14,7 +14,6 @@ - [Reentrancy Guard Library](./reentrancy/index.md) - [Bytecode Library](./bytecode/index.md) - [Merkle Library](./merkle/index.md) -- [Fixed Point Number Library](./fixed_point/index.md) - [Signed Integers Library](./signed_integers/index.md) - [Queue Library](./queue/index.md) - [Upgradability](./upgradability/index.md) diff --git a/docs/book/src/fixed_point/index.md b/docs/book/src/fixed_point/index.md deleted file mode 100644 index 0ce58768..00000000 --- a/docs/book/src/fixed_point/index.md +++ /dev/null @@ -1,87 +0,0 @@ -# Fixed Point Number Library - -The Fixed Point Number Library provides a library to use fixed-point numbers in Sway. It has 3 distinct unsigned types: `UFP32`, `UFP64` and `UFP128` as well as 3 signed types `IFP64`, `IFP128` and `IFP256`. These types are stack allocated. - -This type is stored as a `u32`, `u64` or `U128` under the hood. Therefore the size can be known at compile time and the length is static. - -For implementation details on the Fixed Point Number Library please see the [Sway Libs Docs](https://fuellabs.github.io/sway-libs/master/sway_libs/fixed_point/index.html). - -## Importing the Fixed Point Number Library - -In order to use the Fixed Point Number Library, Sway Libs must be added to the `Forc.toml` file and then imported into your Sway project. To add Sway Libs as a dependency to the `Forc.toml` file in your project please see the [Getting Started](../getting_started/index.md). - -To import the Fixed Point Number Library to your Sway Smart Contract, add the following to your Sway file: - -```sway -{{#include ../../../../examples/fixed_point/src/main.sw:import}} -``` - -## Supported Fixed Point Numbers - -### Signed Fixed Point Numbers - -We currently support the following signed Fixed Point numbers: - -- `IFP64` -- `IFP128` -- `IFP256` - -In order to use the `IFP64`, `IFP128` or `IFP256` types, import them into your Sway project like so: - -```sway -{{#include ../../../../examples/fixed_point/src/main.sw:import_ifp}} -``` - -### Unsigned Fixed Point Numbers - -We currently support the following unsigned Fixed Point numbers: - -- `UFP32` -- `UFP64` -- `UFP128` - -In order to use the `UFP32`, `UFP64` or `UFP128` types, import them into your Sway project like so: - -```sway -{{#include ../../../../examples/fixed_point/src/main.sw:import_ufp}} -``` - -## Basic Functionality - -### Instantiating a New Fixed Point Number - -Once imported, any signed or unsigned Fixed Point number type can be instantiated by defining a new variable and calling the `from` function. - -```sway -{{#include ../../../../examples/fixed_point/src/main.sw:instantiating_ufp}} -``` - -### Basic mathematical Functions - -Basic arithmetic operations are working as usual. - -```sway -{{#include ../../../../examples/fixed_point/src/main.sw:mathematical_ops}} -``` - -### Advanced mathematical Functions Supported - -We currently support the following advanced mathematical functions: - -#### Exponential - -```sway -{{#include ../../../../examples/fixed_point/src/main.sw:exponential}} -``` - -#### Square Root - -```sway -{{#include ../../../../examples/fixed_point/src/main.sw:square_root}} -``` - -#### Power - -```sway -{{#include ../../../../examples/fixed_point/src/main.sw:power}} -``` diff --git a/docs/book/src/index.md b/docs/book/src/index.md index a9f6d6b2..b5fa21ae 100644 --- a/docs/book/src/index.md +++ b/docs/book/src/index.md @@ -50,10 +50,6 @@ The [Merkle Proof](./merkle/index.md) Library is used to verify Binary Merkle Tr Math Libraries are libraries which provide mathematic functions or number types that are outside of the std-lib's scope. -### [Fixed Point Number Library](./fixed_point/index.md) - -The [Fixed Point Number](./fixed_point/index.md) Library is an interface to implement fixed-point numbers. - ### [Signed Integers](./signed_integers/index.md) The [Signed Integers](./signed_integers/index.md) Library is an interface to implement signed integers. diff --git a/examples/Forc.lock b/examples/Forc.lock index 3b656c76..95cde592 100644 --- a/examples/Forc.lock +++ b/examples/Forc.lock @@ -55,14 +55,6 @@ dependencies = [ name = "core" source = "path+from-root-E19CE48B3E858B72" -[[package]] -name = "fixed_point_examples" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - [[package]] name = "merkle_examples" source = "member" diff --git a/examples/Forc.toml b/examples/Forc.toml index 24b65428..89770e88 100644 --- a/examples/Forc.toml +++ b/examples/Forc.toml @@ -10,7 +10,6 @@ members = [ "./asset/setting_src20_attributes", "./asset/supply_docs", "./bytecode", - "./fixed_point", "./merkle", "./ownership", "./pausable/pausable", diff --git a/examples/fixed_point/Forc.toml b/examples/fixed_point/Forc.toml deleted file mode 100644 index 4b28498e..00000000 --- a/examples/fixed_point/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "fixed_point_examples" - -[dependencies] -sway_libs = { path = "../../libs" } diff --git a/examples/fixed_point/src/main.sw b/examples/fixed_point/src/main.sw deleted file mode 100644 index ddd32da1..00000000 --- a/examples/fixed_point/src/main.sw +++ /dev/null @@ -1,60 +0,0 @@ -library; - -// ANCHOR: import -use sway_libs::fixed_point::*; -// ANCHOR_END: import - -// ANCHOR: import_ifp -use sway_libs::fixed_point::{ifp128::IFP128, ifp256::IFP256, ifp64::IFP64,}; -// ANCHOR_END: import_ifp - -// ANCHOR: import_ufp -use sway_libs::fixed_point::{ufp128::UFP128, ufp32::UFP32, ufp64::UFP64,}; -// ANCHOR_END: import_ufp - -fn instantiating_ufp() { - // ANCHOR: instantiating_ufp - let mut ufp32_value = UFP32::from(0u32); - let mut ufp64_value = UFP64::from(0u64); - let mut ufp128_value = UFP128::from((0u64, 0u64)); - // ANCHOR_END: instantiating_ufp -} - -// ANCHOR: mathematical_ops -fn add_ufp(val1: UFP64, val2: UFP64) { - let result: UFP64 = val1 + val2; -} - -fn subtract_ufp(val1: UFP64, val2: UFP64) { - let result: UFP64 = val1 - val2; -} - -fn multiply_ufp(val1: UFP64, val2: UFP64) { - let result: UFP64 = val1 * val2; -} - -fn divide_ufp(val1: UFP64, val2: UFP64) { - let result: UFP64 = val1 / val2; -} -// ANCHOR_END: mathematical_ops - -fn exponential() { - // ANCHOR: exponential - let ten = UFP64::from_uint(10); - let res = UFP64::exp(ten); - // ANCHOR_END: exponential -} - -fn square_root() { - // ANCHOR: square_root - let ufp64_169 = UFP64::from_uint(169); - let res = UFP64::sqrt(ufp64_169); - // ANCHOR_END: square_root -} - -fn power() { - // ANCHOR: power - let five = UFP64::from_uint(5); - let res = five.pow(3u32); - // ANCHOR_END: power -} diff --git a/libs/src/fixed_point.sw b/libs/src/fixed_point.sw deleted file mode 100644 index 0410cfe0..00000000 --- a/libs/src/fixed_point.sw +++ /dev/null @@ -1,8 +0,0 @@ -library; - -pub mod ufp32; -pub mod ufp64; -pub mod ufp128; -pub mod ifp64; -pub mod ifp128; -pub mod ifp256; diff --git a/libs/src/fixed_point/ifp128.sw b/libs/src/fixed_point/ifp128.sw deleted file mode 100644 index 3a25a68b..00000000 --- a/libs/src/fixed_point/ifp128.sw +++ /dev/null @@ -1,570 +0,0 @@ -library; -// A wrapper library around the type for mathematical functions operating with signed 128-bit fixed point numbers. -use std::math::{Exponent, Power, Root}; -use ::fixed_point::ufp64::UFP64; - -/// The 128-bit signed fixed point number type. -/// -/// # Additional Information -/// -/// Represented by an underlying `UFP64` number and a boolean. -pub struct IFP128 { - /// The underlying value representing the `IFP128` type. - underlying: UFP64, - /// The underlying boolean representing a negative value for the `IFP128` type. - non_negative: bool, -} - -impl From for IFP128 { - /// Creates IFP128 from UFP64. Note that IFP128::from(1) is 1 / 2^32 and not 1. - fn from(value: UFP64) -> Self { - Self { - underlying: value, - non_negative: true, - } - } -} - -impl IFP128 { - /// The size of this type in bits. - /// - /// # Returns - /// - /// [u64] - The defined size of the `IFP128` type. - /// - /// # Examples - /// - /// ``sway - /// use sway_libs::fixed_point::ifp128::IFP128; - /// - /// fn foo() { - /// let bits = IFP128::bits(); - /// assert(bits == 72); - /// } - /// ``` - pub fn bits() -> u64 { - 72 - } - - /// The largest value that can be represented by this type. - /// - /// # Returns - /// - /// * [IFP128] - The newly created `IFP128` struct. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp128::IFP128, ufp64::UFP64}; - /// - /// fn foo() { - /// let ifp128 = IFP128::max(); - /// assert(ifp128.underlying() == UFP64::max()); - /// } - /// ``` - pub fn max() -> Self { - Self::from(UFP64::max()) - } - - /// The smallest value that can be represented by this type. - /// - /// # Returns - /// - /// * [IFP128] - The newly created `IFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp128::IFP128, ufp64::UFP64}; - /// - /// fn foo() { - /// let ifp128 = IFP128::min(); - /// assert(ifp128.underlying() == UFP64::min()); - /// } - /// ``` - pub fn min() -> Self { - Self { - underlying: UFP64::min(), - non_negative: false, - } - } - - /// The zero value of this type. - /// - /// # Returns - /// - /// * [IFP128] - The newly created `IFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp128::IFP128, ufp64::UFP64}; - /// - /// fn foo() { - /// let ifp128 = IFP128::zero(); - /// assert(ifp128.underlying() == UFP64::zero()); - /// } - /// ``` - pub fn zero() -> Self { - Self::from(UFP64::zero()) - } - - /// Inverts the sign for this type. - /// - /// # Returns - /// - /// * [IFP128] - The newly created `IFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::ifp128::IFP128; - /// - /// fn foo() { - /// let ifp128 = IFP128::zero(); - /// assert(ifp128.non_negative()); - /// let reverse = ifp128.sign_inverse(); - /// assert(!reverse.non_negative()); - /// } - /// ``` - pub fn sign_reverse(self) -> Self { - Self { - underlying: self.underlying, - non_negative: !self.non_negative, - } - } - - /// Returns whether a `IFP128` is set to zero. - /// - /// # Returns - /// - /// * [bool] -> True if the `IFP128` is zero, otherwise false. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::ifp128::IFP128; - /// - /// fn foo() { - /// let ifp128 = IFP128::zero(); - /// assert(ifp128.is_zero()); - /// } - /// ``` - pub fn is_zero(self) -> bool { - self.underlying == UFP64::zero() - } - - /// Returns the underlying `UFP64` representing the `IFP128`. - /// - /// # Returns - /// - /// * [UFP64] - The `UFP64` representing the `IFP128`. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp128::IFP128, ufp64::UFP64}; - /// - /// fn foo() { - /// let ifp128 = IFP128::zero(); - /// assert(ifp128.underlying() == UFP64::zero()); - /// } - /// ``` - pub fn underlying(self) -> UFP64 { - self.underlying - } - - /// Returns the underlying bool representing the postive or negative state of the IFP128. - /// - /// # Returns - /// - /// * [bool] - The `bool` representing whether the `IFP128` is non-negative or not. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::ifp128::IFP128; - /// - /// fn foo() { - /// let ifp128 = IFP128::zero(); - /// assert(ifp128.non_negative() == false); - /// } - /// ``` - pub fn non_negative(self) -> bool { - self.non_negative - } -} - -impl core::ops::Eq for IFP128 { - fn eq(self, other: Self) -> bool { - self.underlying == other.underlying - && (self.underlying == Self::zero() - .underlying - || self.non_negative == other.non_negative) - } -} - -impl core::ops::Ord for IFP128 { - fn gt(self, other: Self) -> bool { - if self.non_negative && !other.non_negative { - true - } else if !self.non_negative && other.non_negative { - false - } else if self.non_negative && other.non_negative { - self.underlying > other.underlying - } else { - self.underlying < other.underlying - } - } - - fn lt(self, other: Self) -> bool { - if self.non_negative && !other.non_negative { - false - } else if !self.non_negative && other.non_negative { - true - } else if self.non_negative && other.non_negative { - self.underlying < other.underlying - } else { - self.underlying > other.underlying - } - } -} - -impl core::ops::Add for IFP128 { - /// Add a IFP128 to a IFP128. Panics on overflow. - fn add(self, other: Self) -> Self { - let mut underlying = self.underlying; - let mut non_negative = self.non_negative; - if self.non_negative && !other.non_negative { - if self.underlying > other.underlying { - underlying = self.underlying - other.underlying; - } else { - underlying = other.underlying - self.underlying; - non_negative = false; - } - } else if !self.non_negative && other.non_negative { - if self.underlying > other.underlying { - underlying = self.underlying - other.underlying; - } else { - underlying = other.underlying - self.underlying; - non_negative = true; - } - } else { - // same sign - underlying = self.underlying + other.underlying; - } - Self { - underlying: underlying, - non_negative: non_negative, - } - } -} - -impl core::ops::Subtract for IFP128 { - /// Subtract a IFP128 from a IFP128. Panics of overflow. - fn subtract(self, other: Self) -> Self { - self + other.sign_reverse() - } -} - -impl core::ops::Multiply for IFP128 { - /// Multiply a IFP128 with a IFP128. Panics of overflow. - fn multiply(self, other: Self) -> Self { - let non_negative = if (self.non_negative - && !self.non_negative) - || (!self.non_negative - && self.non_negative) - { - false - } else { - true - }; - Self { - underlying: self.underlying * other.underlying, - non_negative: non_negative, - } - } -} - -impl core::ops::Divide for IFP128 { - /// Divide a IFP128 by a IFP128. Panics if divisor is zero. - fn divide(self, divisor: Self) -> Self { - let non_negative = if (self.non_negative - && !self.non_negative) - || (!self.non_negative - && self.non_negative) - { - false - } else { - true - }; - Self { - underlying: self.underlying / divisor.underlying, - non_negative: non_negative, - } - } -} - -impl IFP128 { - /// Creates IFP128 that corresponds to a unsigned integer. - /// - /// # Arguments - /// - /// * `uint`: [u64] - The unsigned number to become the underlying value for the `IFP128`. - /// - /// # Returns - /// - /// * [IFP128] - The newly created `IFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp128::IFP128, ufp64::UFP64}; - /// - /// fn foo() { - /// let ifp128 = IFP128::from_uint(1); - /// assert(ifp128.underlying() == UFP64::from_uint(1)); - /// } - /// ``` - pub fn from_uint(uint: u64) -> Self { - Self::from(UFP64::from_uint(uint)) - } -} - -impl IFP128 { - /// Takes the reciprocal (inverse) of a number, `1/x`. - /// - /// # Arguments - /// - /// * `number`: [IFP128] - The value to create the reciprocal from. - /// - /// # Returns - /// - /// * [IFP128] - The newly created `IFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp128::IFP128, ufp64::UFP64}; - /// - /// fn foo() { - /// let ifp128 = IFP128::from_uint(128); - /// let recip = IFP128::recip(ifp128); - /// assert(recip.underlying() == UFP64::recip(UFP64::from(128))); - /// } - /// ``` - pub fn recip(number: IFP128) -> Self { - Self { - underlying: UFP64::recip(number.underlying), - non_negative: number.non_negative, - } - } - - /// Returns the integer part of `self`. - /// - /// # Additional Information - /// - /// This means that non-integer numbers are always truncated towards zero. - /// - /// # Returns - /// - /// * [IFP128] - The newly created `IFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp128::IFP128, ufp64::UFP64}; - /// - /// fn foo() { - /// let ifp128 = IFP128::from_uint(128); - /// let trunc = ifp128.trunc(); - /// assert(trunc.underlying() == UFP64::from(128).trunc()); - /// } - /// ``` - pub fn trunc(self) -> Self { - Self { - underlying: self.underlying.trunc(), - non_negative: self.non_negative, - } - } -} - -impl IFP128 { - /// Returns the largest integer less than or equal to `self`. - /// - /// # Returns - /// - /// * [IFP128] - The newly created `IFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp128::IFP128, ufp64::UFP64}; - /// - /// fn foo() { - /// let ifp128 = IFP128::from_uint(128); - /// let floor = ifp128.floor(); - /// assert(floor.underlying == UFP64::from(128).floor()); - /// } - /// ``` - pub fn floor(self) -> Self { - if self.non_negative { - self.trunc() - } else { - let trunc = self.underlying.trunc(); - if trunc != UFP64::zero() { - self.trunc() - Self::from(UFP64::from(1)) - } else { - self.trunc() - } - } - } - - /// Returns the fractional part of `self`. - /// - /// # Returns - /// - /// * [IFP128] - the newly created `IFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp128::IFP128, ufp64::UFP64}; - /// - /// fn foo() { - /// let ifp128 = IFP128::from_uint(128); - /// let fract = ifp128.fract(); - /// assert(fract.underlying() == UFP64::from(128).fract()); - /// } - /// ``` - pub fn fract(self) -> Self { - Self { - underlying: self.underlying.fract(), - non_negative: self.non_negative, - } - } -} - -impl IFP128 { - /// Returns the smallest integer greater than or equal to `self`. - /// - /// # Returns - /// - /// * [IFP128] - The newly created `IF128` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp128::IFP128, ufp64::UFP64}; - /// - /// fn foo() { - /// let ifp128 = IFP128::from_uint(128); - /// let ceil = ifp128.ceil(); - /// assert(ceil.underlying = UFP64::from(128).ceil()); - /// } - /// ``` - pub fn ceil(self) -> Self { - let mut underlying = self.underlying; - let mut non_negative = self.non_negative; - - if self.non_negative { - underlying = self.underlying.ceil(); - } else { - let ceil = self.underlying.ceil(); - if ceil != self.underlying { - underlying = ceil + UFP64::from(1); - if ceil == UFP64::from(1) { - non_negative = true; - } - } else { - underlying = ceil; - } - } - Self { - underlying: underlying, - non_negative: self.non_negative, - } - } -} - -impl IFP128 { - /// Returns the nearest integer to `self`. Round half-way cases away from zero. - /// - /// # Returns - /// - /// * [IFP128] - The newly created `IFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp128::IFP128, ufp64::UFP64}; - /// - /// fn foo() { - /// let ifp128 = IFP128::from_uint(128); - /// let round = ifp128.round(); - /// assert(round.underlying() == UFP64::from(128).round()); - /// } - /// ``` - pub fn round(self) -> Self { - let mut underlying = self.underlying; - - if self.non_negative { - underlying = self.underlying.round(); - } else { - let floor = self.underlying.floor(); - let ceil = self.underlying.ceil(); - let diff_self_floor = self.underlying - floor; - let diff_ceil_self = ceil - self.underlying; - underlying = if diff_self_floor > diff_ceil_self { - floor - } else { - ceil - }; - } - Self { - underlying: underlying, - non_negative: self.non_negative, - } - } -} - -impl Exponent for IFP128 { - /// Exponent function. e ^ x - fn exp(exponent: Self) -> Self { - let one = IFP128::from_uint(1); - - // Coefficients in the Taylor series up to the seventh power - let p2 = IFP128::from(UFP64::from(2147483648)); // p2 == 1 / 2! - let p3 = IFP128::from(UFP64::from(715827882)); // p3 == 1 / 3! - let p4 = IFP128::from(UFP64::from(178956970)); // p4 == 1 / 4! - let p5 = IFP128::from(UFP64::from(35791394)); // p5 == 1 / 5! - let p6 = IFP128::from(UFP64::from(5965232)); // p6 == 1 / 6! - let p7 = IFP128::from(UFP64::from(852176)); // p7 == 1 / 7! - // Common technique to counter losing significant numbers in usual approximation - // Taylor series approximation of exponentiation function minus 1. The subtraction is done to deal with accuracy issues - let res_minus_1 = exponent + exponent * exponent * (p2 + exponent * (p3 + exponent * (p4 + exponent * (p5 + exponent * (p6 + exponent * p7))))); - let res = res_minus_1 + one; - res - } -} - -impl Power for IFP128 { - /// Power function. x ^ exponent - fn pow(self, exponent: u32) -> Self { - let ufp64_exponent = UFP64::from(exponent.as_u64()); - let non_negative = if !self.non_negative { - // roots of negative numbers are complex numbers which we lack for now - assert(ufp64_exponent.floor() == ufp64_exponent); - - let div_2 = ufp64_exponent / UFP64::from(2); - div_2.floor() == div_2 - } else { - true - }; - let mut underlying = self.underlying.pow(exponent); - Self { - underlying: underlying, - non_negative: non_negative, - } - } -} diff --git a/libs/src/fixed_point/ifp256.sw b/libs/src/fixed_point/ifp256.sw deleted file mode 100644 index b68c005c..00000000 --- a/libs/src/fixed_point/ifp256.sw +++ /dev/null @@ -1,570 +0,0 @@ -library; -// A wrapper library around the type for mathematical functions operating with signed 256-bit fixed point numbers. -use std::math::{Exponent, Power, Root}; -use ::fixed_point::ufp128::UFP128; - -/// The 256-bit signed fixed point number type. -/// -/// # Additional Information -/// -/// Represented by an underlying `UFP128` number and a boolean. -pub struct IFP256 { - /// The underlying value representing the `IFP256` type. - underlying: UFP128, - /// The underlying boolean representing a negative value for the `IFP256` type. - non_negative: bool, -} - -impl From for IFP256 { - /// Creates IFP256 from UFP128. Note that IFP256::from(1) is 1 / 2^128 and not 1. - fn from(value: UFP128) -> Self { - Self { - underlying: value, - non_negative: true, - } - } -} - -impl IFP256 { - /// The size of this type in bits. - /// - /// # Returns - /// - /// [u64] - The defined size of the `IFP256` type. - /// - /// # Examples - /// - /// ``sway - /// use sway_libs::fixed_point::ifp256::IFP256; - /// - /// fn foo() { - /// let bits = IFP256::bits(); - /// assert(bits == 136); - /// } - /// ``` - pub fn bits() -> u64 { - 136 - } - - /// The largest value that can be represented by this type. - /// - /// # Returns - /// - /// * [IFP256] - The newly created `IFP256` struct. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp256::IFP256, ufp128::UFP128} - /// - /// fn foo() { - /// let ifp256 = IFP256::max(); - /// assert(ifp256.underlying() == UFP128::max()); - /// } - /// ``` - pub fn max() -> Self { - Self::from(UFP128::max()) - } - - /// The smallest value that can be represented by this type. - /// - /// # Returns - /// - /// * [IFP256] - The newly created `IFP256` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp256::IFP256, ufp128::UFP128} - /// - /// fn foo() { - /// let ifp256 = IFP256::min(); - /// assert(ifp256.underlying() == UFP128::min()); - /// } - /// ``` - pub fn min() -> Self { - Self { - underlying: UFP128::min(), - non_negative: false, - } - } - - /// The zero value of this type. - /// - /// # Returns - /// - /// * [IFP256] - The newly created `IFP256` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp256::IFP256, ufp128::UFP128} - /// - /// fn foo() { - /// let ifp256 = IFP256::zero(); - /// assert(ifp256.underlying() == UFP128::zero()); - /// } - /// ``` - pub fn zero() -> Self { - Self::from(UFP128::zero()) - } - - /// Inverts the sign for this type. - /// - /// # Returns - /// - /// * [IFP256] - The newly created `IFP256` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::ifp256::IFP256; - /// - /// fn foo() { - /// let ifp256 = IFP256::zero(); - /// assert(ifp256.non_negative()); - /// let reverse = ifp256.sign_inverse(); - /// assert(!reverse.non_negative()); - /// } - /// ``` - pub fn sign_reverse(self) -> Self { - Self { - underlying: self.underlying, - non_negative: !self.non_negative, - } - } - - /// Returns whether a `IFP256` is set to zero. - /// - /// # Returns - /// - /// * [bool] -> True if the `IFP256` is zero, otherwise false. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::ifp256::IFP256; - /// - /// fn foo() { - /// let ifp256 = IFP256::zero(); - /// assert(ifp256.is_zero()); - /// } - /// ``` - pub fn is_zero(self) -> bool { - self.underlying == UFP128::zero() - } - - /// Returns the underlying `UFP128` representing the `IFP256`. - /// - /// # Returns - /// - /// * [UFP128] - The `UFP128` representing the `IFP256`. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp256::IFP256, ufp128::UFP128}; - /// - /// fn foo() { - /// let ifp256 = IFP256::zero(); - /// assert(ifp256.underlying() == UFP128::zero()); - /// } - /// ``` - pub fn underlying(self) -> UFP128 { - self.underlying - } - - /// Returns the underlying bool representing the postive or negative state of the IFP256. - /// - /// # Returns - /// - /// * [bool] - The `bool` representing whether the `IFP256` is non-negative or not. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::ifp256::IFP256; - /// - /// fn foo() { - /// let ifp256 = IFP256::zero(); - /// assert(ifp256.non_negative() == false); - /// } - /// ``` - pub fn non_negative(self) -> bool { - self.non_negative - } -} - -impl core::ops::Eq for IFP256 { - fn eq(self, other: Self) -> bool { - self.underlying == other.underlying - && (self.underlying == Self::zero() - .underlying - || self.non_negative == other.non_negative) - } -} - -impl core::ops::Ord for IFP256 { - fn gt(self, other: Self) -> bool { - if self.non_negative && !other.non_negative { - true - } else if !self.non_negative && other.non_negative { - false - } else if self.non_negative && other.non_negative { - self.underlying > other.underlying - } else { - self.underlying < other.underlying - } - } - - fn lt(self, other: Self) -> bool { - if self.non_negative && !other.non_negative { - false - } else if !self.non_negative && other.non_negative { - true - } else if self.non_negative && other.non_negative { - self.underlying < other.underlying - } else { - self.underlying > other.underlying - } - } -} - -impl core::ops::Add for IFP256 { - /// Add a IFP256 to a IFP256. Panics on overflow. - fn add(self, other: Self) -> Self { - let mut underlying = self.underlying; - let mut non_negative = self.non_negative; - if self.non_negative && !other.non_negative { - if self.underlying > other.underlying { - underlying = self.underlying - other.underlying; - } else { - underlying = other.underlying - self.underlying; - non_negative = false; - } - } else if !self.non_negative && other.non_negative { - if self.underlying > other.underlying { - underlying = self.underlying - other.underlying; - } else { - underlying = other.underlying - self.underlying; - non_negative = true; - } - } else { - // same sign - underlying = self.underlying + other.underlying; - } - Self { - underlying: underlying, - non_negative: non_negative, - } - } -} - -impl core::ops::Subtract for IFP256 { - /// Subtract a IFP256 from a IFP256. Panics of overflow. - fn subtract(self, other: Self) -> Self { - self + other.sign_reverse() - } -} - -impl core::ops::Multiply for IFP256 { - /// Multiply a IFP256 with a IFP256. Panics of overflow. - fn multiply(self, other: Self) -> Self { - let non_negative = if (self.non_negative - && !self.non_negative) - || (!self.non_negative - && self.non_negative) - { - false - } else { - true - }; - Self { - underlying: self.underlying * other.underlying, - non_negative: non_negative, - } - } -} - -impl core::ops::Divide for IFP256 { - /// Divide a IFP256 by a IFP256. Panics if divisor is zero. - fn divide(self, divisor: Self) -> Self { - let non_negative = if (self.non_negative - && !self.non_negative) - || (!self.non_negative - && self.non_negative) - { - false - } else { - true - }; - Self { - underlying: self.underlying / divisor.underlying, - non_negative: non_negative, - } - } -} - -impl IFP256 { - /// Creates IFP256 that corresponds to a unsigned integer. - /// - /// # Arguments - /// - /// * `uint`: [u64] - The unsigned number to become the underlying value for the `IFP256`. - /// - /// # Returns - /// - /// * [IFP256] - The newly created `IFP256` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp256::IFP256, ufp128::UFP128} - /// - /// fn foo() { - /// let ifp256 = IFP256::from_uint(1); - /// assert(ifp256.underlying() == UFP128::from_uint(1)); - /// } - /// ``` - pub fn from_uint(uint: u64) -> Self { - Self::from(UFP128::from_uint(uint)) - } -} - -impl IFP256 { - /// Takes the reciprocal (inverse) of a number, `1/x`. - /// - /// # Arguments - /// - /// * `number`: [IFP126] - The value to create the reciprocal from. - /// - /// # Returns - /// - /// * [IFP256] - The newly created `IFP256` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp256::IFP256, ufp128::UFP128} - /// - /// fn foo() { - /// let ifp256 = IFP256::from_uint(128); - /// let recip = IFP256::recip(ifp256); - /// assert(recip.underlying() == UFP128::recip(UFP128::from(128))); - /// } - /// ``` - pub fn recip(number: IFP256) -> Self { - Self { - underlying: UFP128::recip(number.underlying), - non_negative: number.non_negative, - } - } - - /// Returns the integer part of `self`. - /// - /// # Additional Information - /// - /// This means that non-integer numbers are always truncated towards zero. - /// - /// # Returns - /// - /// * [IFP256] - The newly created `IFP256` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp256::IFP256, ufp128::UFP128} - /// - /// fn foo() { - /// let ifp256 = IFP256::from_uint(128); - /// let trunc = ifp256.trunc(); - /// assert(trunc.underlying() == UFP128::from(128).trunc()); - /// } - /// ``` - pub fn trunc(self) -> Self { - Self { - underlying: self.underlying.trunc(), - non_negative: self.non_negative, - } - } -} - -impl IFP256 { - /// Returns the largest integer less than or equal to `self`. - /// - /// # Returns - /// - /// * [IFP256] - The newly created `IFP256` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp256::IFP256, ufp128::UFP128} - /// - /// fn foo() { - /// let ifp256 = IFP256::from_uint(128); - /// let floor = ifp256.floor(); - /// assert(floor.underlying() == UFP128::from(128).floor()); - /// } - /// ``` - pub fn floor(self) -> Self { - if self.non_negative { - self.trunc() - } else { - let trunc = self.underlying.trunc(); - if trunc != UFP128::zero() { - self.trunc() - Self::from(UFP128::from((1, 0))) - } else { - self.trunc() - } - } - } - - /// Returns the fractional part of `self`. - /// - /// # Returns - /// - /// * [IFP256] - the newly created `IFP256` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp256::IFP256, ufp128::UFP128} - /// - /// fn foo() { - /// let ifp256 = IFP256::from_uint(128); - /// let fract = ifp256.fract(); - /// assert(fract.underlying() == UFP128::from(128).fract()); - /// } - /// ``` - pub fn fract(self) -> Self { - Self { - underlying: self.underlying.fract(), - non_negative: self.non_negative, - } - } -} - -impl IFP256 { - /// Returns the smallest integer greater than or equal to `self`. - /// - /// # Returns - /// - /// * [IFP256] - The newly created `IFP256` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp256::IFP256, ufp128::UFP128} - /// - /// fn foo() { - /// let ifp256 = IFP256::from_uint(128); - /// let ceil = ifp256.ceil(); - /// assert(ceil.underlying() = UFP128::from(128).ceil().underlying()); - /// } - /// ``` - pub fn ceil(self) -> Self { - let mut underlying = self.underlying; - let mut non_negative = self.non_negative; - - if self.non_negative { - underlying = self.underlying.ceil(); - } else { - let ceil = self.underlying.ceil(); - if ceil != self.underlying { - underlying = ceil + UFP128::from((1, 0)); - if ceil == UFP128::from((1, 0)) { - non_negative = true; - } - } else { - underlying = ceil; - } - } - Self { - underlying: underlying, - non_negative: self.non_negative, - } - } -} - -impl IFP256 { - /// Returns the nearest integer to `self`. Round half-way cases away from zero. - /// - /// # Returns - /// - /// * [IFP256] - The newly created `IFP256` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp256::IFP256, ufp128::UFP128} - /// - /// fn foo() { - /// let ifp256 = IFP256::from_uint(128); - /// let round = ifp256.round(); - /// assert(round.underlying() == UFP128::from(128).round().underlying()); - /// } - /// ``` - pub fn round(self) -> Self { - let mut underlying = self.underlying; - - if self.non_negative { - underlying = self.underlying.round(); - } else { - let floor = self.underlying.floor(); - let ceil = self.underlying.ceil(); - let diff_self_floor = self.underlying - floor; - let diff_ceil_self = ceil - self.underlying; - underlying = if diff_self_floor > diff_ceil_self { - floor - } else { - ceil - }; - } - Self { - underlying: underlying, - non_negative: self.non_negative, - } - } -} - -impl Exponent for IFP256 { - /// Exponent function. e ^ x - fn exp(exponent: Self) -> Self { - let one = IFP256::from_uint(1); - - // Coefficients in the Taylor series up to the seventh power - let p2 = IFP256::from(UFP128::from((0, 2147483648))); // p2 == 1 / 2! - let p3 = IFP256::from(UFP128::from((0, 715827882))); // p3 == 1 / 3! - let p4 = IFP256::from(UFP128::from((0, 178956970))); // p4 == 1 / 4! - let p5 = IFP256::from(UFP128::from((0, 35791394))); // p5 == 1 / 5! - let p6 = IFP256::from(UFP128::from((0, 5965232))); // p6 == 1 / 6! - let p7 = IFP256::from(UFP128::from((0, 852176))); // p7 == 1 / 7! - // Common technique to counter losing significant numbers in usual approximation - // Taylor series approximation of exponentiation function minus 1. The subtraction is done to deal with accuracy issues - let res_minus_1 = exponent + exponent * exponent * (p2 + exponent * (p3 + exponent * (p4 + exponent * (p5 + exponent * (p6 + exponent * p7))))); - let res = res_minus_1 + one; - res - } -} - -impl Power for IFP256 { - /// Power function. x ^ exponent - fn pow(self, exponent: u32) -> Self { - let ufp128_exponent = UFP128::from((0, exponent.as_u64())); - let non_negative = if !self.non_negative { - // roots of negative numbers are complex numbers which we lack for now - assert(ufp128_exponent.floor() == ufp128_exponent); - - let div_2 = ufp128_exponent / UFP128::from((2, 0)); - div_2.floor() == div_2 - } else { - true - }; - let mut underlying = self.underlying.pow(exponent); - Self { - underlying: underlying, - non_negative: non_negative, - } - } -} diff --git a/libs/src/fixed_point/ifp64.sw b/libs/src/fixed_point/ifp64.sw deleted file mode 100644 index 63d03b97..00000000 --- a/libs/src/fixed_point/ifp64.sw +++ /dev/null @@ -1,570 +0,0 @@ -library; -// A wrapper library around the u32 type for mathematical functions operating with signed 64-bit fixed point numbers. -use std::math::*; -use ::fixed_point::ufp32::UFP32; - -/// The 64-bit signed fixed point number type. -/// -/// # Additional Information -/// -/// Represented by an underlying `UFP32` number and a boolean. -pub struct IFP64 { - /// The underlying value representing the `IFP64` type. - underlying: UFP32, - /// The underlying boolean representing a negative value for the `IFP64` type. - non_negative: bool, -} - -impl From for IFP64 { - /// Creates IFP64 from UFP32. Note that IFP64::from(1) is 1 / 2^32 and not 1. - fn from(value: UFP32) -> Self { - Self { - underlying: value, - non_negative: true, - } - } -} - -impl IFP64 { - /// The size of this type in bits. - /// - /// # Returns - /// - /// [u64] - The defined size of the `IFP64` type. - /// - /// # Examples - /// - /// ``sway - /// use sway_libs::fixed_point::ifp64::IFP64; - /// - /// fn foo() { - /// let bits = IFP64::bits(); - /// assert(bits == 64); - /// } - /// ``` - pub fn bits() -> u64 { - 64 - } - - /// The largest value that can be represented by this type. - /// - /// # Returns - /// - /// * [IFP64] - The newly created `IFP64` struct. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp64::IFP64, ufp32::UFP32}; - /// - /// fn foo() { - /// let ifp64 = IFP64::max(); - /// assert(ifp64.underlying() == UFP32::max()); - /// } - /// ``` - pub fn max() -> Self { - Self::from(UFP32::max()) - } - - /// The smallest value that can be represented by this type. - /// - /// # Returns - /// - /// * [IFP64] - The newly created `IFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp64::IFP64, ufp32::UFP32}; - /// - /// fn foo() { - /// let ifp64 = IFP64::min(); - /// assert(ifp64.underlying() == UFP32::min()); - /// } - /// ``` - pub fn min() -> Self { - Self { - underlying: UFP32::min(), - non_negative: false, - } - } - - /// The zero value of this type. - /// - /// # Returns - /// - /// * [IFP64] - The newly created `IFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp64::IFP64, ufp32::UFP32}; - /// - /// fn foo() { - /// let ifp64 = IFP64::zero(); - /// assert(ifp64.underlying() == UFP32::zero()); - /// } - /// ``` - pub fn zero() -> Self { - Self::from(UFP32::zero()) - } - - /// Returns whether a `IFP64` is set to zero. - /// - /// # Returns - /// - /// * [bool] -> True if the `IFP64` is zero, otherwise false. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::ifp64::IFP64; - /// - /// fn foo() { - /// let ifp64 = IFP64::zero(); - /// assert(ifp64.is_zero()); - /// } - /// ``` - pub fn is_zero(self) -> bool { - self.underlying == UFP32::zero() - } - - /// Inverts the sign for this type. - /// - /// # Returns - /// - /// * [IFP64] - The newly created `IFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::ifp64::IFP64; - /// - /// fn foo() { - /// let ifp64 = IFP64::zero(); - /// assert(ifp64.non_negative()); - /// let reverse = ifp64.sign_inverse(); - /// assert(!reverse.non_negative()); - /// } - /// ``` - fn sign_reverse(self) -> Self { - Self { - underlying: self.underlying, - non_negative: !self.non_negative, - } - } - - /// Returns the underlying `UFP32` representing the `IFP64`. - /// - /// # Returns - /// - /// * [UFP32] - The `UFP32` representing the `IFP64`. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp64::IFP64, ufp32::UFP32}; - /// - /// fn foo() { - /// let ifp64 = IFP64::zero(); - /// assert(ifp64.underlying() == UFP32::zero()); - /// } - /// ``` - pub fn underlying(self) -> UFP32 { - self.underlying - } - - /// Returns the underlying bool representing the postive or negative state of the IFP64. - /// - /// # Returns - /// - /// * [bool] - The `bool` representing whether the `IFP64` is non-negative or not. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::ifp64::IFP64; - /// - /// fn foo() { - /// let ifp64 = IFP64::zero(); - /// assert(ifp64.non_negative() == false); - /// } - /// ``` - pub fn non_negative(self) -> bool { - self.non_negative - } -} - -impl core::ops::Eq for IFP64 { - fn eq(self, other: Self) -> bool { - self.underlying == other.underlying - && (self.underlying == Self::zero() - .underlying - || self.non_negative == other.non_negative) - } -} - -impl core::ops::Ord for IFP64 { - fn gt(self, other: Self) -> bool { - if self.non_negative && !other.non_negative { - true - } else if !self.non_negative && other.non_negative { - false - } else if self.non_negative && other.non_negative { - self.underlying > other.underlying - } else { - self.underlying < other.underlying - } - } - - fn lt(self, other: Self) -> bool { - if self.non_negative && !other.non_negative { - false - } else if !self.non_negative && other.non_negative { - true - } else if self.non_negative && other.non_negative { - self.underlying < other.underlying - } else { - self.underlying > other.underlying - } - } -} - -impl core::ops::Add for IFP64 { - /// Add a IFP64 to a IFP64. Panics on overflow. - fn add(self, other: Self) -> Self { - let mut underlying = self.underlying; - let mut non_negative = self.non_negative; - if self.non_negative && !other.non_negative { - if self.underlying > other.underlying { - underlying = self.underlying - other.underlying; - } else { - underlying = other.underlying - self.underlying; - non_negative = false; - } - } else if !self.non_negative && other.non_negative { - if self.underlying > other.underlying { - underlying = self.underlying - other.underlying; - } else { - underlying = other.underlying - self.underlying; - non_negative = true; - } - } else { - // same sign - underlying = self.underlying + other.underlying; - } - Self { - underlying: underlying, - non_negative: non_negative, - } - } -} - -impl core::ops::Subtract for IFP64 { - /// Subtract a IFP64 from a IFP64. Panics of overflow. - fn subtract(self, other: Self) -> Self { - self + other.sign_reverse() - } -} - -impl core::ops::Multiply for IFP64 { - /// Multiply a IFP64 with a IFP64. Panics of overflow. - fn multiply(self, other: Self) -> Self { - let non_negative = if (self.non_negative - && !self.non_negative) - || (!self.non_negative - && self.non_negative) - { - false - } else { - true - }; - Self { - underlying: self.underlying * other.underlying, - non_negative: non_negative, - } - } -} - -impl core::ops::Divide for IFP64 { - /// Divide a IFP64 by a IFP64. Panics if divisor is zero. - fn divide(self, divisor: Self) -> Self { - let non_negative = if (self.non_negative - && !self.non_negative) - || (!self.non_negative - && self.non_negative) - { - false - } else { - true - }; - Self { - underlying: self.underlying / divisor.underlying, - non_negative: non_negative, - } - } -} - -impl IFP64 { - /// Creates IFP64 that corresponds to a unsigned integer. - /// - /// # Arguments - /// - /// * `uint`: [u32] - The unsigned number to become the underlying value for the `IFP64`. - /// - /// # Returns - /// - /// * [IFP64] - The newly created `IFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp64::IFP64, ufp32::UFP32}; - /// - /// fn foo() { - /// let ifp64 = IFP64::from_uint(1u32); - /// assert(ifp64.underlying() == UFP32::from_uint(1u32)); - /// } - /// ``` - pub fn from_uint(uint: u32) -> Self { - Self::from(UFP32::from_uint(uint)) - } -} - -impl IFP64 { - /// Takes the reciprocal (inverse) of a number, `1/x`. - /// - /// # Arguments - /// - /// * `number`: [IFP64] - The value to create the reciprocal from. - /// - /// # Returns - /// - /// * [IFP64] - The newly created `IFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp64::IFP64, ufp32::UFP32}; - /// - /// fn foo() { - /// let ifp64 = IFP64::from_uint(128u32); - /// let recip = IFP64::recip(ifp64); - /// assert(recip.underlying() == UFP32::recip(UFP32::from(128u32))); - /// } - /// ``` - pub fn recip(number: IFP64) -> Self { - Self { - underlying: UFP32::recip(number.underlying), - non_negative: number.non_negative, - } - } - - /// Returns the integer part of `self`. - /// - /// # Additional Information - /// - /// This means that non-integer numbers are always truncated towards zero. - /// - /// # Returns - /// - /// * [IFP64] - The newly created `IFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp64:IFP64, ufp32::UFP32}; - /// - /// fn foo() { - /// let ifp64 = IFP64::from_uint(128u32); - /// let trunc = ifp64.trunc(); - /// assert(trunc.underlying() == UFP32::from(128u32).trunc()); - /// } - /// ``` - pub fn trunc(self) -> Self { - Self { - underlying: self.underlying.trunc(), - non_negative: self.non_negative, - } - } -} - -impl IFP64 { - /// Returns the largest integer less than or equal to `self`. - /// - /// # Returns - /// - /// * [IFP64] - The newly created `IFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp64::IFP64, ufp32::UFP32}; - /// - /// fn foo() { - /// let ifp64 = IFP64::from_uint(128u32); - /// let floor = ifp64.floor(); - /// assert(floor.underlying() == UFP32::from(128u32).trunc().underlying()); - /// } - /// ``` - pub fn floor(self) -> Self { - if self.non_negative { - self.trunc() - } else { - let trunc = self.underlying.trunc(); - if trunc != UFP32::zero() { - self.trunc() - Self::from(UFP32::from(1u32)) - } else { - self.trunc() - } - } - } - - /// Returns the fractional part of `self`. - /// - /// # Returns - /// - /// * [IFP64] - the newly created `IFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp64::IFP64, ufp32::UFP32}; - /// - /// fn foo() { - /// let ifp64 = IFP64::from_uint(128u32); - /// let fract = ifp64.fract(); - /// assert(fract.underlying() == UFP32::from(128u32).fract()); - /// } - /// ``` - pub fn fract(self) -> Self { - Self { - underlying: self.underlying.fract(), - non_negative: self.non_negative, - } - } -} - -impl IFP64 { - /// Returns the smallest integer greater than or equal to `self`. - /// - /// # Returns - /// - /// * [IFP64] - The newly created `IFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp64::IFP64, ufp32::UFP32}; - /// - /// fn foo() { - /// let ifp64 = IFP64::from_uint(128u32); - /// let ceil = ifp64.ceil(); - /// assert(ceil.underlying() = UFP32::from(128u32).ceil()); - /// } - /// ``` - pub fn ceil(self) -> Self { - let mut underlying = self.underlying; - let mut non_negative = self.non_negative; - - if self.non_negative { - underlying = self.underlying.ceil(); - } else { - let ceil = self.underlying.ceil(); - if ceil != self.underlying { - underlying = ceil + UFP32::from(1u32); - if ceil == UFP32::from(1u32) { - non_negative = true; - } - } else { - underlying = ceil; - } - } - Self { - underlying: underlying, - non_negative: self.non_negative, - } - } -} - -impl IFP64 { - /// Returns the nearest integer to `self`. Round half-way cases away from zero. - /// - /// # Returns - /// - /// * [IFP64] - The newly created `IFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::{ifp64::IFP64, ufp32::UFP32}; - /// - /// fn foo() { - /// let ifp64 = IFP64::from_uint(128_u32); - /// let round = ifp64.round(); - /// assert(round.underlying() == UFP32::from(128u32).round()); - /// } - /// ``` - pub fn round(self) -> Self { - let mut underlying = self.underlying; - - if self.non_negative { - underlying = self.underlying.round(); - } else { - let floor = self.underlying.floor(); - let ceil = self.underlying.ceil(); - let diff_self_floor = self.underlying - floor; - let diff_ceil_self = ceil - self.underlying; - underlying = if diff_self_floor > diff_ceil_self { - floor - } else { - ceil - }; - } - Self { - underlying: underlying, - non_negative: self.non_negative, - } - } -} - -impl Exponent for IFP64 { - /// Exponent function. e ^ x - fn exp(exponent: Self) -> Self { - let one = IFP64::from_uint(1u32); - - // Coefficients in the Taylor series up to the seventh power - let p2 = IFP64::from(UFP32::from(32768u32)); // p2 == 1 / 2! - let p3 = IFP64::from(UFP32::from(10922u32)); // p3 == 1 / 3! - let p4 = IFP64::from(UFP32::from(2730u32)); // p4 == 1 / 4! - let p5 = IFP64::from(UFP32::from(546u32)); // p5 == 1 / 5! - let p6 = IFP64::from(UFP32::from(91u32)); // p6 == 1 / 6! - let p7 = IFP64::from(UFP32::from(13u32)); // p7 == 1 / 7! - // Common technique to counter losing significant numbers in usual approximation - // Taylor series approximation of exponentiation function minus 1. The subtraction is done to deal with accuracy issues - let res_minus_1 = exponent + exponent * exponent * (p2 + exponent * (p3 + exponent * (p4 + exponent * (p5 + exponent * (p6 + exponent * p7))))); - let res = res_minus_1 + one; - res - } -} - -impl Power for IFP64 { - /// Power function. x ^ exponent - fn pow(self, exponent: u32) -> Self { - let ufp32_exponent = UFP32::from(exponent); - let non_negative = if !self.non_negative { - // roots of negative numbers are complex numbers which we lack for now - assert(ufp32_exponent.floor() == ufp32_exponent); - - let div_2 = ufp32_exponent / UFP32::from(2u32); - div_2.floor() == div_2 - } else { - true - }; - let mut underlying = self.underlying.pow(exponent); - Self { - underlying: underlying, - non_negative: non_negative, - } - } -} diff --git a/libs/src/fixed_point/ufp128.sw b/libs/src/fixed_point/ufp128.sw deleted file mode 100644 index 09e60f40..00000000 --- a/libs/src/fixed_point/ufp128.sw +++ /dev/null @@ -1,483 +0,0 @@ -library; -// A wrapper around U128 type for a library for Sway for mathematical functions operating with unsigned 64.64-bit fixed point numbers. -use std::{math::{Exponent, Power, Root}, u128::U128}; - -/// The 128-bit unsigned fixed point number type. -/// -/// # Additional Information -/// -/// Represented by an underlying `U128` number. -pub struct UFP128 { - /// The underlying value representing the `UFP128` type. - underlying: U128, -} - -impl From<(u64, u64)> for UFP128 { - fn from(int_fract_tuple: (u64, u64)) -> Self { - Self { - underlying: U128::from(int_fract_tuple), - } - } -} - -impl From for UFP128 { - fn from(u128: U128) -> Self { - Self { - underlying: u128, - } - } -} - -impl UFP128 { - /// The zero value of this type. - /// - /// # Returns - /// - /// * [UFP128] - The newly created `UFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp128::UFP128; - /// - /// fn foo() { - /// let ufp128 = UFP128::zero(); - /// assert(ufp128.underlying() == U128::from((0, 0))); - /// } - /// ``` - pub fn zero() -> Self { - Self { - underlying: U128::from((0, 0)), - } - } - - /// The smallest value that can be represented by this type. - /// - /// # Returns - /// - /// * [UFP128] - The newly created `UFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp128::UFP128; - /// use std::u128::U128; - /// - /// fn foo() { - /// let ufp128 = UFP128::min(); - /// assert(ufp128.underlying() == U128::min()); - /// } - /// ``` - pub fn min() -> Self { - Self { - underlying: U128::min(), - } - } - - /// The largest value that can be represented by this type. - /// - /// # Returns - /// - /// * [UFP128] - The newly created `UFP128` struct. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp128::UFP128; - /// use std::u128::U128; - /// - /// fn foo() { - /// let ufp128 = UFP128::max(); - /// assert(ufp128.underlying() == U128::max()); - /// } - /// ``` - pub fn max() -> Self { - Self { - underlying: U128::max(), - } - } - - /// The size of this type in bits. - /// - /// # Returns - /// - /// [u64] - The defined size of the `UFP128` type. - /// - /// # Examples - /// - /// ``sway - /// use libraries::fixed_point::ufp128::UFP128; - /// - /// fn foo() { - /// let bits = UFP128::bits(); - /// assert(bits == 128); - /// } - /// ``` - pub fn bits() -> u64 { - 128 - } - - /// Returns whether a `UFP128` is set to zero. - /// - /// # Returns - /// - /// * [bool] -> True if the `UFP128` is zero, otherwise false. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::ufp128::UFP128; - /// - /// fn foo() { - /// let ufp128 = UFP128::zero(); - /// assert(ufp128.is_zero()); - /// } - /// ``` - pub fn is_zero(self) -> bool { - self.underlying == U128::zero() - } - - /// Returns the underlying `U128` representing the `UFP128`. - /// - /// # Returns - /// - /// * [U128] - The `U128` representing the `UFP128`. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::ufp64::UFP64; - /// - /// fn foo() { - /// let ufp128 = UFP128::zero(); - /// assert(ufp128.underlying() == U128::zero()); - /// } - /// ``` - pub fn underlying(self) -> U128 { - self.underlying - } -} - -impl UFP128 { - /// Creates UFP128 that corresponds to a unsigned integer. - /// - /// # Arguments - /// - /// * `uint`: [u64] - The unsigned number to become the underlying value for the `UFP128`. - /// - /// # Returns - /// - /// * [UFP128] - The newly created `UFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp128::UFP128; - /// use std::u128::U128; - /// - /// fn foo() { - /// let ufp128 = UFP128::from_uint(1); - /// assert(ufp128.underlying() == U128::from((1, 0)); - /// } - /// ``` - pub fn from_uint(uint: u64) -> Self { - Self { - underlying: U128::from((uint, 0)), - } - } -} - -impl core::ops::Eq for UFP128 { - fn eq(self, other: Self) -> bool { - self.underlying == other.underlying - } -} - -impl core::ops::Ord for UFP128 { - fn gt(self, other: Self) -> bool { - self.underlying > other.underlying - } - - fn lt(self, other: Self) -> bool { - self.underlying < other.underlying - } -} - -impl core::ops::Add for UFP128 { - /// Add a UFP128 to a UFP128. Panics on overflow. - fn add(self, other: Self) -> Self { - UFP128 { - underlying: self.underlying + other.underlying, - } - } -} - -impl core::ops::Subtract for UFP128 { - /// Subtract a UFP128 from a UFP128. Panics of overflow. - fn subtract(self, other: Self) -> Self { - // If trying to subtract a larger number, panic. - assert(!(self.underlying < other.underlying)); - - UFP128 { - underlying: self.underlying - other.underlying, - } - } -} - -impl core::ops::Multiply for UFP128 { - /// Multiply a UFP128 with a UFP128. Panics on overflow. - fn multiply(self, other: Self) -> Self { - let self_u64 = (0, 0, self.underlying.upper(), self.underlying.lower()); - let other_u64 = (0, 0, other.underlying.upper(), other.underlying.lower()); - let self_u256 = asm(r1: self_u64) { - r1: u256 - }; - let other_u256 = asm(r1: other_u64) { - r1: u256 - }; - - let self_multiply_other = self_u256 * other_u256; - let res_u256 = self_multiply_other >> 64; - - let (a, b, c, d) = asm(r1: res_u256) { - r1: (u64, u64, u64, u64) - }; - if a != 0 || b != 0 { - // panic on overflow - revert(0); - } - Self::from((c, d)) - } -} - -impl core::ops::Divide for UFP128 { - /// Divide a UFP128 by a UFP128. Panics if divisor is zero. - fn divide(self, divisor: Self) -> Self { - let zero = UFP128::zero(); - - assert(divisor != zero); - - // Conversion to u256 done to ensure no overflow happen - // and maximal precision is avaliable - // as it makes possible to multiply by the denominator in - // all cases - let self_u64 = (0, 0, self.underlying.upper(), self.underlying.lower()); - let divisor_u64 = (0, 0, divisor.underlying.upper(), divisor.underlying.lower()); - let self_u256 = asm(r1: self_u64) { - r1: u256 - }; - let divisor_u256 = asm(r1: divisor_u64) { - r1: u256 - }; - - // Multiply by denominator to ensure accuracy - let res_u256 = (self_u256 << 64) / divisor_u256; - let (a, b, c, d) = asm(r1: res_u256) { - r1: (u64, u64, u64, u64) - }; - - if a != 0 || b != 0 { - // panic on overflow - revert(0); - } - Self::from((c, d)) - } -} - -impl UFP128 { - /// Takes the reciprocal (inverse) of a number, `1/x`. - /// - /// # Arguments - /// - /// * `number`: [UFP128] - The value to create the reciprocal from. - /// - /// # Returns - /// - /// * [UFP128] - The newly created `UFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp128::UFP128; - /// - /// fn foo() { - /// let ufp64 = UFP128::from_uint(128); - /// let recip = UFP64::recip(ufp64); - /// assert(recip.underlying() == U128::from((33554432, 0)); - /// } - /// ``` - pub fn recip(number: UFP128) -> Self { - let one = UFP128::from((1, 0)); - - one / number - } - - /// Returns the largest integer less than or equal to `self`. - /// - /// # Returns - /// - /// * [UFP128] - The newly created `UFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp128::UFP128; - /// - /// fn foo() { - /// let ufp128 = UFP128::from_uint(128); - /// let floor = ufp128.floor(); - /// assert(floor.underlying() == U128::from((0,0))); - /// } - /// ``` - pub fn floor(self) -> Self { - Self::from((self.underlying.upper(), 0)) - } - - /// Returns the smallest integer greater than or equal to `self`. - /// - /// # Returns - /// - /// * [UFP64] - The newly created `UFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp128::UFP128; - /// - /// fn foo() { - /// let ufp128 = UFP128::from_uint(128); - /// let ceil = ufp128.ceil(); - /// assert(ceil.underlying() = U128::from((4294967296, 0))); - /// } - /// ``` - pub fn ceil(self) -> Self { - let val = self.underlying; - if val.lower() == 0 { - return Self::from((val.upper(), 0)); - } else { - return Self::from((val.upper() + 1, 0)); - } - } -} - -impl UFP128 { - /// Returns the nearest integer to `self`. Round half-way cases away from zero. - /// - /// # Returns - /// - /// * [UFP128] - The newly created `UFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp128::UFP128; - /// - /// fn foo() { - /// let ufp128 = UFP128::from_uint(128); - /// let round = ufp128.round(); - /// assert(round.underlying() == U128::from(0,0))); - /// } - /// ``` - pub fn round(self) -> Self { - let floor = self.floor(); - let ceil = self.ceil(); - let diff_self_floor = self - floor; - let diff_ceil_self = ceil - self; - if diff_self_floor < diff_ceil_self { - return floor; - } else { - return ceil; - } - } - - /// Returns the integer part of `self`. - /// - /// # Additional Information - /// - /// This means that non-integer numbers are always truncated towards zero. - /// - /// # Returns - /// - /// * [UFP128] - The newly created `UFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp128::UFP128; - /// - /// fn foo() { - /// let ufp128 = UFP128::from_uint(128); - /// let trunc = ufp128.trunc(); - /// assert(trunc.underlying() == U128::from((0,0))); - /// } - /// ``` - pub fn trunc(self) -> Self { - Self::from((self.underlying.upper(), 0)) - } - - /// Returns the fractional part of `self`. - /// - /// # Returns - /// - /// * [UFP128] - the newly created `UFP128` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp128::UFP128; - /// - /// fn foo() { - /// let ufp128 = UFP128::from_uint(128); - /// let fract = ufp128.fract(); - /// assert(fract.underlying() == U128::from((0, 0))); - /// } - /// ``` - pub fn fract(self) -> Self { - Self::from((0, self.underlying.lower())) - } -} - -impl Root for UFP128 { - fn sqrt(self) -> Self { - let numerator_root = self.underlying.sqrt(); - let numerator = numerator_root * U128::from((0, 2 << 32)); - Self::from((numerator.upper(), numerator.lower())) - } -} - -impl Power for UFP128 { - fn pow(self, exponent: u32) -> Self { - let nominator_pow = self.underlying.pow(exponent); - let u128_2 = U128::from((0, 2)); - let two_pow_64_n_minus_1 = u128_2.pow((64u32 * (exponent - 1u32))); - let nominator = nominator_pow / two_pow_64_n_minus_1; - Self::from((nominator.upper(), nominator.lower())) - } -} - -// TODO: uncomment and change accordingly, when signed integers will be added -// impl Logarithm for UFP128 { -// fn log(self, base: Self) -> Self { -// let nominator_log = self.underlying.log(base); -// let res = (nominator_log - U128::from(0, 64 * 2.log(base))) * U128::from(1, 0); -// UFP128 { -// underlying: res -// } -// } -// } -impl Exponent for UFP128 { - fn exp(exponent: Self) -> Self { - let one = UFP128::from((1, 0)); - let p2 = one / UFP128::from((2, 0)); - let p3 = one / UFP128::from((6, 0)); - let p4 = one / UFP128::from((24, 0)); - let p5 = one / UFP128::from((120, 0)); - let p6 = one / UFP128::from((720, 0)); - let p7 = one / UFP128::from((5040, 0)); - - // common technique to counter losing sugnifucant numbers in usual approximation - let _res_minus_1 = exponent + exponent * exponent * (p2 + exponent * (p3 + exponent * (p4 + exponent * (p5 + exponent * (p6 + exponent * p7))))); - let res = one; - res - } -} diff --git a/libs/src/fixed_point/ufp32.sw b/libs/src/fixed_point/ufp32.sw deleted file mode 100644 index 6394be92..00000000 --- a/libs/src/fixed_point/ufp32.sw +++ /dev/null @@ -1,507 +0,0 @@ -library; -// A wrapper library around the u32 type for mathematical functions operating with unsigned 32-bit fixed point numbers. -use std::math::*; - -/// The 32-bit unsigned fixed point number type. -/// -/// # Additional Information -/// -/// Represented by an underlying `u32` number. -pub struct UFP32 { - /// The underlying value representing the `UFP32` type. - underlying: u32, -} - -impl From for UFP32 { - /// Creates UFP32 from u32. Note that UFP32::from(1) is 1 / 2^32 and not 1. - fn from(underlying: u32) -> Self { - Self { underlying } - } -} - -impl UFP32 { - /// The size of this type in bits. - /// - /// # Returns - /// - /// [u64] - The defined size of the `UFP32` type. - /// - /// # Examples - /// - /// ``sway - /// use libraries::fixed_point::ufp32::UFP32; - /// - /// fn foo() { - /// let bits = UFP32::bits(); - /// assert(bits == 32); - /// } - /// ``` - pub fn bits() -> u64 { - 32 - } - - /// Convenience function to know the denominator. - /// - /// # Returns - /// - /// * [u32] - The value of the denominator for the `UFP32` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp32::UFP32; - /// - /// fn foo() { - /// let denominator = UFP32::denominator(); - /// assert(denominator == 65536u32); - /// } - /// ``` - pub fn denominator() -> u32 { - 1u32 << 16 - } - - /// The largest value that can be represented by this type. - /// - /// # Returns - /// - /// * [UFP32] - The newly created `UFP32` struct. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp32::UFP32; - /// - /// fn foo() { - /// let ufp32 = UFP32::max(); - /// assert(ufp32.underlying() == u32::max()); - /// } - /// ``` - pub fn max() -> Self { - Self { - underlying: u32::max(), - } - } - - /// The smallest value that can be represented by this type. - /// - /// # Returns - /// - /// * [UFP32] - The newly created `UFP32` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp32::UFP32; - /// - /// fn foo() { - /// let ufp32 = UFP32::min(); - /// assert(ufp32.underlying() == u32::min()); - /// } - /// ``` - pub fn min() -> Self { - Self { - underlying: u32::min(), - } - } - - /// The zero value of this type. - /// - /// # Returns - /// - /// * [UFP32] - The newly created `UFP32` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp32::UFP32; - /// - /// fn foo() { - /// let ufp32 = UFP32::zero(); - /// assert(ufp32.underlying() == 0u32); - /// } - /// ``` - pub fn zero() -> Self { - Self { - underlying: 0u32, - } - } - - /// Returns whether a `UFP32` is set to zero. - /// - /// # Returns - /// - /// * [bool] -> True if the `UFP32` is zero, otherwise false. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::ufp32::UFP32; - /// - /// fn foo() { - /// let ufp32 = UFP32::zero(); - /// assert(ufp32.is_zero()); - /// } - /// ``` - pub fn is_zero(self) -> bool { - self.underlying == 0u32 - } - - /// Returns the underlying `u32` representing the `UFP32`. - /// - /// # Returns - /// - /// * [u32] - The `u32` representing the `UFP32`. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::ufp32::UFP32; - /// - /// fn foo() { - /// let ufp32 = UFP32::zero(); - /// assert(ufp32.underlying() == 0u32); - /// } - /// ``` - pub fn underlying(self) -> u32 { - self.underlying - } -} - -impl core::ops::Eq for UFP32 { - fn eq(self, other: Self) -> bool { - self.underlying == other.underlying - } -} - -impl core::ops::Ord for UFP32 { - fn gt(self, other: Self) -> bool { - self.underlying > other.underlying - } - - fn lt(self, other: Self) -> bool { - self.underlying < other.underlying - } -} - -impl core::ops::Add for UFP32 { - /// Add a UFP32 to a UFP32. Panics on overflow. - fn add(self, other: Self) -> Self { - Self { - underlying: self.underlying + other.underlying, - } - } -} - -impl core::ops::Subtract for UFP32 { - /// Subtract a UFP32 from a UFP32. Panics of overflow. - fn subtract(self, other: Self) -> Self { - // If trying to subtract a larger number, panic. - assert(self.underlying >= other.underlying); - - Self { - underlying: self.underlying - other.underlying, - } - } -} - -impl core::ops::Multiply for UFP32 { - /// Multiply a UFP32 with a UFP32. Panics of overflow. - fn multiply(self, other: Self) -> Self { - let self_u64: u64 = self.underlying.as_u64(); - let other_u64: u64 = other.underlying.as_u64(); - - let self_multiply_other = self_u64 * other_u64; - let res_u64 = self_multiply_other >> 16; - if res_u64 > u32::max().as_u64() { - // panic on overflow - revert(0); - } - - Self { - underlying: asm(ptr: res_u64) { - ptr: u32 - }, - } - } -} - -impl core::ops::Divide for UFP32 { - /// Divide a UFP32 by a UFP32. Panics if divisor is zero. - fn divide(self, divisor: Self) -> Self { - let zero = UFP32::zero(); - assert(divisor != zero); - - let denominator: u64 = Self::denominator().as_u64(); - // Conversion to U64 done to ensure no overflow happen - // and maximal precision is avaliable - // as it makes possible to multiply by the denominator in - // all cases - let self_u64: u64 = self.underlying.as_u64(); - let divisor_u64: u64 = divisor.underlying.as_u64(); - - // Multiply by denominator to ensure accuracy - let res_u64 = self_u64 * denominator / divisor_u64; - - if res_u64 > u32::max().as_u64() { - // panic on overflow - revert(0); - } - Self { - underlying: asm(ptr: res_u64) { - ptr: u32 - }, - } - } -} - -impl UFP32 { - /// Creates UFP32 that corresponds to a unsigned integer. - /// - /// # Arguments - /// - /// * `uint`: [u32] - The unsigned number to become the underlying value for the `UFP32`. - /// - /// # Returns - /// - /// * [UFP32] - The newly created `UFP32` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp32::UFP32; - /// - /// fn foo() { - /// let ufp32 = UFP32::from_uint(1u32); - /// assert(ufp32.underlying() == 65536u32); - /// } - /// ``` - pub fn from_uint(uint: u32) -> Self { - Self { - underlying: Self::denominator() * uint, - } - } -} - -impl UFP32 { - /// Takes the reciprocal (inverse) of a number, `1/x`. - /// - /// # Arguments - /// - /// * `number`: [UFP32] - The value to create the reciprocal from. - /// - /// # Returns - /// - /// * [UFP32] - The newly created `UFP32` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp32::UFP32; - /// - /// fn foo() { - /// let ufp32 = UFP32::from_uint(128u32); - /// let recip = UFP32::recip(ufp32); - /// assert(recip.underlying() == 512u32); - /// } - /// ``` - pub fn recip(number: UFP32) -> Self { - let one = UFP32::from_uint(1u32); - - let res = one / number; - res - } - - /// Returns the integer part of `self`. - /// - /// # Additional Information - /// - /// This means that non-integer numbers are always truncated towards zero. - /// - /// # Returns - /// - /// * [UFP32] - The newly created `UFP32` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp32::UFP32; - /// - /// fn foo() { - /// let ufp32 = UFP32::from_uint(128u32); - /// let trunc = ufp32.trunc(); - /// assert(trunc.underlying() == 0); - /// } - /// ``` - pub fn trunc(self) -> Self { - Self { - // first move to the right (divide by the denominator) - // to get rid of fractional part, than move to the - // left (multiply by the denominator), to ensure - // fixed-point structure - underlying: (self.underlying >> 16) << 16, - } - } -} - -impl UFP32 { - /// Returns the largest integer less than or equal to `self`. - /// - /// # Returns - /// - /// * [UFP32] - The newly created `UFP32` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp32::UFP32; - /// - /// fn foo() { - /// let ufp32 = UFP32::from_uint(128u32); - /// let floor = ufp32.floor(); - /// assert(floor.underlying() == 0); - /// } - /// ``` - pub fn floor(self) -> Self { - return self.trunc(); - } - - /// Returns the fractional part of `self`. - /// - /// # Returns - /// - /// * [UFP32] - the newly created `UFP32` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp32::UFP32; - /// - /// fn foo() { - /// let ufp32 = UFP32::from_uint(128u32); - /// let fract = ufp32.fract(); - /// assert(fract.underlying() == 0); - /// } - /// ``` - pub fn fract(self) -> Self { - Self { - // first move to the left (multiply by the denominator) - // to get rid of integer part, than move to the - // right (divide by the denominator), to ensure - // fixed-point structure - underlying: ((self.underlying << 16) - u32::max() - 1u32) >> 16, - } - } -} - -impl UFP32 { - /// Returns the smallest integer greater than or equal to `self`. - /// - /// # Returns - /// - /// * [UFP32] - The newly created `UFP32` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp32::UFP32; - /// - /// fn foo() { - /// let ufp32 = UFP32::from_uint(128u32); - /// let ceil = ufp32.ceil(); - /// assert(ceil.underlying() = 65536u32); - /// } - /// ``` - pub fn ceil(self) -> Self { - if self.fract().underlying != 0u32 { - let res = self.trunc() + UFP32::from_uint(1u32); - return res; - } - return self; - } -} - -impl UFP32 { - /// Returns the nearest integer to `self`. Round half-way cases away from zero. - /// - /// # Returns - /// - /// * [UFP32] - The newly created `UFP32` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp32::UFP32; - /// - /// fn foo() { - /// let ufp32 = UFP32::from_uint(128_u32); - /// let round = ufp32.round(); - /// assert(round.underlying() == 0); - /// } - /// ``` - pub fn round(self) -> Self { - let floor = self.floor(); - let ceil = self.ceil(); - let diff_self_floor = self - floor; - let diff_ceil_self = ceil - self; - - // Check if we are closer to the floor or to the ceiling - if diff_self_floor < diff_ceil_self { - return floor; - } else { - return ceil; - } - } -} - -impl Root for UFP32 { - /// Sqaure root for UFP32 - fn sqrt(self) -> Self { - let nominator_root = self.underlying.sqrt(); - // Need to multiply over 2 ^ 16, as the square root of the denominator - // is also taken and we need to ensure that the denominator is constant - let nominator = nominator_root << 16; - Self { - underlying: nominator, - } - } -} - -impl Exponent for UFP32 { - /// Exponent function. e ^ x - fn exp(exponent: Self) -> Self { - let one = UFP32::from_uint(1u32); - - // Coefficients in the Taylor series up to the seventh power - let p2 = UFP32::from(2147483648u32); // p2 == 1 / 2! - let p3 = UFP32::from(715827882u32); // p3 == 1 / 3! - let p4 = UFP32::from(178956970u32); // p4 == 1 / 4! - let p5 = UFP32::from(35791394u32); // p5 == 1 / 5! - let p6 = UFP32::from(5965232u32); // p6 == 1 / 6! - let p7 = UFP32::from(852176u32); // p7 == 1 / 7! - // Common technique to counter losing significant numbers in usual approximation - // Taylor series approximation of exponentiation function minus 1. The subtraction is done to deal with accuracy issues - let res_minus_1 = exponent + exponent * exponent * (p2 + exponent * (p3 + exponent * (p4 + exponent * (p5 + exponent * (p6 + exponent * p7))))); - let res = res_minus_1 + one; - res - } -} - -impl Power for UFP32 { - /// Power function. x ^ exponent - fn pow(self, exponent: u32) -> Self { - let nominator_pow = self.underlying.pow(exponent); - // As we need to ensure the fixed point structure - // which means that the denominator is always 2 ^ 16 - // we need to divide the nominator by 2 ^ (16 * exponent - 1) - // - 1 is the formula is due to denominator need to stay 2 ^ 16 - let nominator = nominator_pow >> 16 * (exponent - 1u32).as_u64(); - - if nominator > u32::max() { - // panic on overflow - revert(0); - } - Self { - underlying: nominator, - } - } -} diff --git a/libs/src/fixed_point/ufp64.sw b/libs/src/fixed_point/ufp64.sw deleted file mode 100644 index 825cd1a5..00000000 --- a/libs/src/fixed_point/ufp64.sw +++ /dev/null @@ -1,502 +0,0 @@ -library; -// A wrapper library around the u64 type for mathematical functions operating with unsigned 64-bit fixed point numbers. -use std::{math::{Exponent, Power, Root}, u128::U128}; - -/// The 64-bit unsigned fixed point number type. -/// -/// # Additional Information -/// -/// Represented by an underlying `u64` number. -pub struct UFP64 { - /// The underlying value representing the `UFP64` type. - underlying: u64, -} - -impl From for UFP64 { - /// Creates UFP64 from u64. Note that UFP64::from(1) is 1 / 2^32 and not 1. - fn from(underlying: u64) -> Self { - Self { underlying } - } -} - -impl UFP64 { - /// The size of this type in bits. - /// - /// # Returns - /// - /// [u64] - The defined size of the `UFP64` type. - /// - /// # Examples - /// - /// ``sway - /// use libraries::fixed_point::ufp64::UFP64; - /// - /// fn foo() { - /// let bits = UFP64::bits(); - /// assert(bits == 64); - /// } - /// ``` - pub fn bits() -> u64 { - 64 - } - - /// Convenience function to know the denominator. - /// - /// # Returns - /// - /// * [u64] - The value of the denominator for the `UFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp64::UFP64; - /// - /// fn foo() { - /// let denominator = UFP64::denominator(); - /// assert(denominator == 4294967296); - /// } - /// ``` - pub fn denominator() -> u64 { - 1 << 32 - } - - /// The largest value that can be represented by this type. - /// - /// # Returns - /// - /// * [UFP64] - The newly created `UFP64` struct. - /// - /// # Examples - /// - /// ```sway - /// use v::UFP64; - /// - /// fn foo() { - /// let ufp64 = UFP64::max(); - /// assert(ufp64.underlying() == u64::max()); - /// } - /// ``` - pub fn max() -> Self { - Self { - underlying: u64::max(), - } - } - - /// The smallest value that can be represented by this type. - /// - /// # Returns - /// - /// * [UFP64] - The newly created `UFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp64::UFP64; - /// - /// fn foo() { - /// let ufp64 = UFP64::min(); - /// assert(ufp64.underlying() == u64::min()); - /// } - /// ``` - pub fn min() -> Self { - Self { - underlying: u64::min(), - } - } - - /// The zero value of this type. - /// - /// # Returns - /// - /// * [UFP64] - The newly created `UFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp64::UFP64; - /// - /// fn foo() { - /// let ufp64 = UFP64::zero(); - /// assert(ufp64.underlying() == 0); - /// } - /// ``` - pub fn zero() -> Self { - Self { underlying: 0 } - } - - /// Returns whether a `UFP64` is set to zero. - /// - /// # Returns - /// - /// * [bool] -> True if the `UFP64` is zero, otherwise false. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::ufp64::UFP64; - /// - /// fn foo() { - /// let ufp64 = UFP64::zero(); - /// assert(ufp64.is_zero()); - /// } - /// ``` - pub fn is_zero(self) -> bool { - self.underlying == 0 - } - - /// Returns the underlying `u64` representing the `UFP64`. - /// - /// # Returns - /// - /// * [u64] - The `u64` representing the `UFP64`. - /// - /// # Examples - /// - /// ```sway - /// use sway_libs::fixed_point::ufp64::UFP64; - /// - /// fn foo() { - /// let ufp64 = UFP64::zero(); - /// assert(ufp64.underlying() == 0); - /// } - /// ``` - pub fn underlying(self) -> u64 { - self.underlying - } -} - -impl core::ops::Eq for UFP64 { - fn eq(self, other: Self) -> bool { - self.underlying == other.underlying - } -} - -impl core::ops::Ord for UFP64 { - fn gt(self, other: Self) -> bool { - self.underlying > other.underlying - } - - fn lt(self, other: Self) -> bool { - self.underlying < other.underlying - } -} - -impl core::ops::Add for UFP64 { - /// Add a UFP64 to a UFP64. Panics on overflow. - fn add(self, other: Self) -> Self { - Self { - underlying: self.underlying + other.underlying, - } - } -} - -impl core::ops::Subtract for UFP64 { - /// Subtract a UFP64 from a UFP64. Panics of overflow. - fn subtract(self, other: Self) -> Self { - // If trying to subtract a larger number, panic. - assert(self.underlying >= other.underlying); - - Self { - underlying: self.underlying - other.underlying, - } - } -} - -impl core::ops::Multiply for UFP64 { - /// Multiply a UFP64 with a UFP64. Panics of overflow. - fn multiply(self, other: Self) -> Self { - let self_u128 = U128::from((0, self.underlying)); - let other_u128 = U128::from((0, other.underlying)); - - let self_multiply_other = self_u128 * other_u128; - let res_u128 = self_multiply_other >> 32; - if res_u128.upper() != 0 { - // panic on overflow - revert(0); - } - - Self { - underlying: res_u128.lower(), - } - } -} - -impl core::ops::Divide for UFP64 { - /// Divide a UFP64 by a UFP64. Panics if divisor is zero. - fn divide(self, divisor: Self) -> Self { - let zero = UFP64::zero(); - assert(divisor != zero); - - let denominator = U128::from((0, Self::denominator())); - // Conversion to U128 done to ensure no overflow happen - // and maximal precision is avaliable - // as it makes possible to multiply by the denominator in - // all cases - let self_u128 = U128::from((0, self.underlying)); - let divisor_u128 = U128::from((0, divisor.underlying)); - - // Multiply by denominator to ensure accuracy - let res_u128 = self_u128 * denominator / divisor_u128; - - if res_u128.upper() != 0 { - // panic on overflow - revert(0); - } - Self { - underlying: res_u128.lower(), - } - } -} - -impl UFP64 { - /// Creates UFP64 that corresponds to a unsigned integer. - /// - /// # Arguments - /// - /// * `uint`: [u64] - The unsigned number to become the underlying value for the `UFP64`. - /// - /// # Returns - /// - /// * [UFP64] - The newly created `UFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp64::UFP64; - /// - /// fn foo() { - /// let ufp64 = UFP64::from_uint(1); - /// assert(ufp64.underlying() == 4294967296); - /// } - /// ``` - pub fn from_uint(uint: u64) -> Self { - Self { - underlying: Self::denominator() * uint, - } - } -} - -impl UFP64 { - /// Takes the reciprocal (inverse) of a number, `1/x`. - /// - /// # Arguments - /// - /// * `number`: [UFP64] - The value to create the reciprocal from. - /// - /// # Returns - /// - /// * [UFP64] - The newly created `UFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp64::UFP64; - /// - /// fn foo() { - /// let ufp64 = UFP64::from_uint(128); - /// let recip = UFP64::recip(ufp64); - /// assert(recip.underlying() == 33554432); - /// } - /// ``` - pub fn recip(number: UFP64) -> Self { - let one = UFP64::from_uint(1); - - let res = one / number; - res - } - - /// Returns the integer part of `self`. - /// - /// # Additional Information - /// - /// This means that non-integer numbers are always truncated towards zero. - /// - /// # Returns - /// - /// * [UFP64] - The newly created `UFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp64::UFP64; - /// - /// fn foo() { - /// let ufp64 = UFP64::from_uint(128); - /// let trunc = ufp64.trunc(); - /// assert(trunc.underlying() == 0); - /// } - /// ``` - pub fn trunc(self) -> Self { - Self { - // first move to the right (divide by the denominator) - // to get rid of fractional part, than move to the - // left (multiply by the denominator), to ensure - // fixed-point structure - underlying: (self.underlying >> 32) << 32, - } - } -} - -impl UFP64 { - /// Returns the largest integer less than or equal to `self`. - /// - /// # Returns - /// - /// * [UFP64] - The newly created `UFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp64::UFP64; - /// - /// fn foo() { - /// let ufp64 = UFP64::from_uint(128); - /// let floor = ufp64.floor(); - /// assert(floor.underlying() == 0); - /// } - /// ``` - pub fn floor(self) -> Self { - return self.trunc(); - } - - /// Returns the fractional part of `self`. - /// - /// # Returns - /// - /// * [UFP64] - the newly created `UFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp64::UFP64; - /// - /// fn foo() { - /// let ufp64 = UFP64::from_uint(128); - /// let fract = ufp64.fract(); - /// assert(fract.underlying() == 0); - /// } - /// ``` - pub fn fract(self) -> Self { - Self { - // first move to the left (multiply by the denominator) - // to get rid of integer part, than move to the - // right (divide by the denominator), to ensure - // fixed-point structure - underlying: (self.underlying << 32) >> 32, - } - } -} - -impl UFP64 { - /// Returns the smallest integer greater than or equal to `self`. - /// - /// # Returns - /// - /// * [UFP64] - The newly created `UFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp64::UFP64; - /// - /// fn foo() { - /// let ufp64 = UFP64::from_uint(128); - /// let ceil = ufp64.ceil(); - /// assert(ceil.underlying() = 4294967296); - /// } - /// ``` - pub fn ceil(self) -> Self { - if self.fract().underlying != 0 { - let res = self.trunc() + UFP64::from_uint(1); - return res; - } - return self; - } -} - -impl UFP64 { - /// Returns the nearest integer to `self`. Round half-way cases away from zero. - /// - /// # Returns - /// - /// * [UFP64] - The newly created `UFP64` type. - /// - /// # Examples - /// - /// ```sway - /// use libraries::fixed_point::ufp64::UFP64; - /// - /// fn foo() { - /// let ufp64 = UFP64::from_uint(128); - /// let round = ufp64.round(); - /// assert(round.underlying() == 0); - /// } - /// ``` - pub fn round(self) -> Self { - let floor = self.floor(); - let ceil = self.ceil(); - let diff_self_floor = self - floor; - let diff_ceil_self = ceil - self; - - // Check if we are closer to the floor or to the ceiling - if diff_self_floor < diff_ceil_self { - return floor; - } else { - return ceil; - } - } -} - -impl Root for UFP64 { - /// Sqaure root for UFP64 - fn sqrt(self) -> Self { - let nominator_root = self.underlying.sqrt(); - // Need to multiply over 2 ^ 16, as the square root of the denominator - // is also taken and we need to ensure that the denominator is constant - let nominator = nominator_root << 16; - Self { - underlying: nominator, - } - } -} - -impl Exponent for UFP64 { - /// Exponent function. e ^ x - fn exp(exponent: Self) -> Self { - let one = UFP64::from_uint(1); - - // Coefficients in the Taylor series up to the seventh power - let p2 = UFP64::from(2147483648); // p2 == 1 / 2! - let p3 = UFP64::from(715827882); // p3 == 1 / 3! - let p4 = UFP64::from(178956970); // p4 == 1 / 4! - let p5 = UFP64::from(35791394); // p5 == 1 / 5! - let p6 = UFP64::from(5965232); // p6 == 1 / 6! - let p7 = UFP64::from(852176); // p7 == 1 / 7! - // Common technique to counter losing significant numbers in usual approximation - // Taylor series approximation of exponentiation function minus 1. The subtraction is done to deal with accuracy issues - let res_minus_1 = exponent + exponent * exponent * (p2 + exponent * (p3 + exponent * (p4 + exponent * (p5 + exponent * (p6 + exponent * p7))))); - let res = res_minus_1 + one; - res - } -} - -impl Power for UFP64 { - /// Power function. x ^ exponent - fn pow(self, exponent: u32) -> Self { - let demoninator_power = UFP64::denominator(); - let nominator_pow = U128::from((0, self.underlying)).pow(exponent); - // As we need to ensure the fixed point structure - // which means that the denominator is always 2 ^ 32 - // we need to delete the nominator by 2 ^ (32 * exponent - 1) - // - 1 is the formula is due to denominator need to stay 2 ^ 32 - let nominator = nominator_pow >> demoninator_power * (exponent.as_u64() - 1); - - if nominator.upper() != 0 { - // panic on overflow - revert(0); - } - Self { - underlying: nominator.lower(), - } - } -} diff --git a/libs/src/lib.sw b/libs/src/lib.sw index 16e32281..0996585b 100644 --- a/libs/src/lib.sw +++ b/libs/src/lib.sw @@ -2,7 +2,6 @@ library; pub mod asset; pub mod bytecode; -pub mod fixed_point; pub mod merkle; pub mod ownership; pub mod admin; diff --git a/tests/Forc.lock b/tests/Forc.lock index 893e5942..010d053f 100644 --- a/tests/Forc.lock +++ b/tests/Forc.lock @@ -120,78 +120,6 @@ dependencies = [ "sway_libs", ] -[[package]] -name = "ifp128_div_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ifp128_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ifp256_div_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ifp256_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ifp64_div_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ifp64_exp_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ifp64_mul_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ifp64_pow_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ifp64_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - [[package]] name = "merkle_proof_test" source = "member" @@ -303,118 +231,6 @@ dependencies = [ "std", ] -[[package]] -name = "ufp128_div_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ufp128_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ufp32_div_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ufp32_exp_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ufp32_mul_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ufp32_pow_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ufp32_root_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ufp32_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ufp64_div_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ufp64_exp_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ufp64_mul_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ufp64_pow_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ufp64_root_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - -[[package]] -name = "ufp64_test" -source = "member" -dependencies = [ - "std", - "sway_libs", -] - [[package]] name = "upgradability_test" source = "member" diff --git a/tests/Forc.toml b/tests/Forc.toml index a683239a..0f4249e4 100644 --- a/tests/Forc.toml +++ b/tests/Forc.toml @@ -5,29 +5,6 @@ members = [ "./src/bytecode/test_artifacts/simple_contract", "./src/bytecode/test_artifacts/complex_contract", "./src/bytecode/test_contract", - "./src/fixed_point/ufp32_div_test", - "./src/fixed_point/ufp32_exp_test", - "./src/fixed_point/ufp32_mul_test", - "./src/fixed_point/ufp32_pow_test", - "./src/fixed_point/ufp32_root_test", - "./src/fixed_point/ufp32_test", - "./src/fixed_point/ufp64_div_test", - "./src/fixed_point/ufp64_exp_test", - "./src/fixed_point/ufp64_mul_test", - "./src/fixed_point/ufp64_pow_test", - "./src/fixed_point/ufp64_root_test", - "./src/fixed_point/ufp64_test", - "./src/fixed_point/ufp128_div_test", - "./src/fixed_point/ufp128_test", - "./src/fixed_point/ifp64_div_test", - "./src/fixed_point/ifp64_exp_test", - "./src/fixed_point/ifp64_mul_test", - "./src/fixed_point/ifp64_pow_test", - "./src/fixed_point/ifp64_test", - "./src/fixed_point/ifp128_div_test", - "./src/fixed_point/ifp128_test", - "./src/fixed_point/ifp256_div_test", - "./src/fixed_point/ifp256_test", "./src/merkle_proof", "./src/native_asset", "./src/pausable", diff --git a/tests/src/fixed_point/ifp128_div_test/.gitignore b/tests/src/fixed_point/ifp128_div_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ifp128_div_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ifp128_div_test/Forc.toml b/tests/src/fixed_point/ifp128_div_test/Forc.toml deleted file mode 100644 index 0dcc3274..00000000 --- a/tests/src/fixed_point/ifp128_div_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ifp128_div_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ifp128_div_test/mod.rs b/tests/src/fixed_point/ifp128_div_test/mod.rs deleted file mode 100644 index 14f00389..00000000 --- a/tests/src/fixed_point/ifp128_div_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ifp128_div_test/src/main.sw b/tests/src/fixed_point/ifp128_div_test/src/main.sw deleted file mode 100644 index cd535388..00000000 --- a/tests/src/fixed_point/ifp128_div_test/src/main.sw +++ /dev/null @@ -1,24 +0,0 @@ -script; - -use sway_libs::fixed_point::{ifp128::IFP128, ufp64::UFP64}; - -fn main() -> bool { - let zero = IFP128::from(UFP64::from_uint(0)); - let mut up = IFP128::from(UFP64::from_uint(1)); - let mut down = IFP128::from(UFP64::from_uint(2)); - let mut res = up / down; - assert(res == IFP128::from(UFP64::from(2147483648))); - - up = IFP128::from(UFP64::from_uint(4)); - down = IFP128::from(UFP64::from_uint(2)); - res = up / down; - assert(res == IFP128::from(UFP64::from_uint(2))); - - up = IFP128::from(UFP64::from_uint(9)); - down = IFP128::from(UFP64::from_uint(4)); - res = up / down; - - assert(res == IFP128::from(UFP64::from(9663676416))); - - true -} diff --git a/tests/src/fixed_point/ifp128_div_test/tests/mod.rs b/tests/src/fixed_point/ifp128_div_test/tests/mod.rs deleted file mode 100644 index a3911d22..00000000 --- a/tests/src/fixed_point/ifp128_div_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestIfp128Div", - abi = "src/fixed_point/ifp128_div_test/out/release/ifp128_div_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ifp128_div_test_script() { - let path_to_bin = "src/fixed_point/ifp128_div_test/out/release/ifp128_div_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestIfp128Div::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ifp128_test/.gitignore b/tests/src/fixed_point/ifp128_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ifp128_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ifp128_test/Forc.toml b/tests/src/fixed_point/ifp128_test/Forc.toml deleted file mode 100644 index 441e3273..00000000 --- a/tests/src/fixed_point/ifp128_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ifp128_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ifp128_test/mod.rs b/tests/src/fixed_point/ifp128_test/mod.rs deleted file mode 100644 index 14f00389..00000000 --- a/tests/src/fixed_point/ifp128_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ifp128_test/src/main.sw b/tests/src/fixed_point/ifp128_test/src/main.sw deleted file mode 100644 index 9e42c152..00000000 --- a/tests/src/fixed_point/ifp128_test/src/main.sw +++ /dev/null @@ -1,130 +0,0 @@ -script; - -use sway_libs::fixed_point::{ifp128::IFP128, ufp64::UFP64}; - -fn main() -> bool { - // arithmetic - let one = IFP128::from(UFP64::from_uint(1)); - let two = IFP128::from(UFP64::from_uint(2)); - let mut res = two + one; - assert(IFP128::from(UFP64::from_uint(3)) == res); - - let ifp_128_10 = IFP128::from(UFP64::from_uint(10)); - res = ifp_128_10 + two; - assert(IFP128::from(UFP64::from_uint(12)) == res); - - let ifp_128_48 = IFP128::from(UFP64::from_uint(48)); - let six = IFP128::from(UFP64::from_uint(6)); - res = ifp_128_48 - six; - assert(IFP128::from(UFP64::from_uint(42)) == res); - - let ifp_128_169 = IFP128::from(UFP64::from_uint(169)); - let ifp_128_13 = IFP128::from(UFP64::from_uint(13)); - res = ifp_128_169 - ifp_128_13; - assert(IFP128::from(UFP64::from_uint(156)) == res); - - // recip - let mut value = IFP128::from(UFP64::from_uint(7)); - res = IFP128::recip(value); - assert(IFP128::from(UFP64::from(613566756)) == res); - - // trunc - value = IFP128::from(UFP64::from_uint(7)); - res = value.trunc(); - assert(IFP128::from(UFP64::from(30064771072)) == res); - - // floor - value = IFP128::from(UFP64::from_uint(1) + UFP64::from(3)); - res = value.floor(); - assert(IFP128::from_uint(1) == res); - - // fract - value = IFP128::from(UFP64::from_uint(1) + UFP64::from(3)); - res = value.fract(); - assert(IFP128::from(UFP64::from(3)) == res); - - value = IFP128::from_uint(1); - res = value.fract(); - assert(IFP128::from_uint(0) == res); - - // ceil - value = IFP128::from(UFP64::from_uint(1) + UFP64::from(3)); - res = value.ceil(); - assert(IFP128::from_uint(2) == res); - - value = IFP128::from_uint(1); - res = value.ceil(); - assert(IFP128::from_uint(1) == res); - - // round - value = IFP128::from(UFP64::from_uint(1) + UFP64::from(3)); - res = value.round(); - assert(IFP128::from_uint(1) == res); - - value = IFP128::from(UFP64::from_uint(1) + UFP64::from((1 << 32) + 1)); - res = value.round(); - assert(IFP128::from_uint(2) == res); - - // Ord tests - let num = IFP128::min(); - let num2 = IFP128::min(); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); - - let num = IFP128::min(); - let num2 = IFP128::from_uint(42_u64); - - assert(num < num2); - assert(num2 > num); - - let num = IFP128::min(); - let num2 = IFP128::max(); - - assert(num < num2); - assert(num2 > num); - - let num = IFP128::from_uint(42_u64); - let num2 = IFP128::min(); - - assert(num > num2); - assert(num2 < num); - - let num = IFP128::from_uint(42_u64); - let num2 = IFP128::from_uint(42_u64); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); - - let num = IFP128::from_uint(42_u64); - let num2 = IFP128::max(); - - assert(num < num2); - assert(num2 > num); - - let num = IFP128::max(); - let num2 = IFP128::min(); - - assert(num > num2); - assert(num2 < num); - - let num = IFP128::max(); - let num2 = IFP128::from_uint(42_u64); - - assert(num > num2); - assert(num2 < num); - - let num = IFP128::max(); - let num2 = IFP128::max(); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); - - true -} diff --git a/tests/src/fixed_point/ifp128_test/tests/mod.rs b/tests/src/fixed_point/ifp128_test/tests/mod.rs deleted file mode 100644 index 42093a08..00000000 --- a/tests/src/fixed_point/ifp128_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestIfp128", - abi = "src/fixed_point/ifp128_test/out/release/ifp128_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ifp128_test_script() { - let path_to_bin = "src/fixed_point/ifp128_test/out/release/ifp128_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestIfp128::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ifp256_div_test/.gitignore b/tests/src/fixed_point/ifp256_div_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ifp256_div_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ifp256_div_test/Forc.toml b/tests/src/fixed_point/ifp256_div_test/Forc.toml deleted file mode 100644 index 09c679a7..00000000 --- a/tests/src/fixed_point/ifp256_div_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ifp256_div_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ifp256_div_test/mod.rs b/tests/src/fixed_point/ifp256_div_test/mod.rs deleted file mode 100644 index 14f00389..00000000 --- a/tests/src/fixed_point/ifp256_div_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ifp256_div_test/src/main.sw b/tests/src/fixed_point/ifp256_div_test/src/main.sw deleted file mode 100644 index 64b0947c..00000000 --- a/tests/src/fixed_point/ifp256_div_test/src/main.sw +++ /dev/null @@ -1,25 +0,0 @@ -script; - -use sway_libs::fixed_point::{ifp256::IFP256, ufp128::UFP128}; - -fn main() -> bool { - let zero = IFP256::from(UFP128::from((0, 0))); - let mut up = IFP256::from(UFP128::from((1, 0))); - let mut down = IFP256::from(UFP128::from((2, 0))); - let mut res = up / down; - assert(res == IFP256::from(UFP128::from((0, 9223372036854775808)))); - - up = IFP256::from(UFP128::from((4, 0))); - down = IFP256::from(UFP128::from((2, 0))); - res = up / down; - - assert(res == IFP256::from(UFP128::from((2, 0)))); - - up = IFP256::from(UFP128::from((9, 0))); - down = IFP256::from(UFP128::from((4, 0))); - res = up / down; - - assert(res == IFP256::from(UFP128::from((2, 4611686018427387904)))); - - true -} diff --git a/tests/src/fixed_point/ifp256_div_test/tests/mod.rs b/tests/src/fixed_point/ifp256_div_test/tests/mod.rs deleted file mode 100644 index 6b28d113..00000000 --- a/tests/src/fixed_point/ifp256_div_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestIfp256Div", - abi = "src/fixed_point/ifp256_div_test/out/release/ifp256_div_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ifp256_div_test_script() { - let path_to_bin = "src/fixed_point/ifp256_div_test/out/release/ifp256_div_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestIfp256Div::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ifp256_test/.gitignore b/tests/src/fixed_point/ifp256_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ifp256_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ifp256_test/Forc.toml b/tests/src/fixed_point/ifp256_test/Forc.toml deleted file mode 100644 index f41a4ec7..00000000 --- a/tests/src/fixed_point/ifp256_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ifp256_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ifp256_test/mod.rs b/tests/src/fixed_point/ifp256_test/mod.rs deleted file mode 100644 index 14f00389..00000000 --- a/tests/src/fixed_point/ifp256_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ifp256_test/src/main.sw b/tests/src/fixed_point/ifp256_test/src/main.sw deleted file mode 100644 index ef329aaa..00000000 --- a/tests/src/fixed_point/ifp256_test/src/main.sw +++ /dev/null @@ -1,130 +0,0 @@ -script; - -use sway_libs::fixed_point::{ifp256::IFP256, ufp128::UFP128}; - -fn main() -> bool { - // arithmetic - let one = IFP256::from(UFP128::from((1, 0))); - let two = IFP256::from(UFP128::from((2, 0))); - let mut res = two + one; - assert(IFP256::from(UFP128::from((3, 0))) == res); - - let ifp_256_10 = IFP256::from(UFP128::from((10, 0))); - res = ifp_256_10 + two; - assert(IFP256::from(UFP128::from((12, 0))) == res); - - let ifp_256_48 = IFP256::from(UFP128::from((48, 0))); - let six = IFP256::from(UFP128::from((6, 0))); - res = ifp_256_48 - six; - assert(IFP256::from(UFP128::from((42, 0))) == res); - - let ifp_256_169 = IFP256::from(UFP128::from((169, 0))); - let ifp_256_13 = IFP256::from(UFP128::from((13, 0))); - res = ifp_256_169 - ifp_256_13; - assert(IFP256::from(UFP128::from((156, 0))) == res); - - // recip - let mut value = IFP256::from(UFP128::from((1, 3))); - res = IFP256::recip(value); - assert(IFP256::from(UFP128::from((0, 18446744073709551613))) == res); - - // trunc - let mut value = IFP256::from(UFP128::from((1, 3))); - res = value.trunc(); - assert(IFP256::from_uint(1) == res); - - // floor - value = IFP256::from(UFP128::from((1, 3))); - res = value.floor(); - assert(IFP256::from_uint(1) == res); - - // fract - value = IFP256::from(UFP128::from((1, 3))); - res = value.fract(); - assert(IFP256::from(UFP128::from((0, 3))) == res); - - value = IFP256::from_uint(1); - res = value.fract(); - assert(IFP256::from_uint(0) == res); - - // ceil - value = IFP256::from(UFP128::from((1, 3))); - res = value.ceil(); - assert(IFP256::from_uint(2) == res); - - value = IFP256::from_uint(1); - res = value.ceil(); - assert(IFP256::from_uint(1) == res); - - // round - value = IFP256::from(UFP128::from((1, 3))); - res = value.round(); - assert(IFP256::from_uint(1) == res); - - value = IFP256::from(UFP128::from((1, (1 << 63) + 1))); - res = value.round(); - assert(IFP256::from_uint(2) == res); - - // Ord tests - let num = IFP256::min(); - let num2 = IFP256::min(); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); - - let num = IFP256::min(); - let num2 = IFP256::from_uint(42_u64); - - assert(num < num2); - assert(num2 > num); - - let num = IFP256::min(); - let num2 = IFP256::max(); - - assert(num < num2); - assert(num2 > num); - - let num = IFP256::from_uint(42_u64); - let num2 = IFP256::min(); - - assert(num > num2); - assert(num2 < num); - - let num = IFP256::from_uint(42_u64); - let num2 = IFP256::from_uint(42_u64); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); - - let num = IFP256::from_uint(42_u64); - let num2 = IFP256::max(); - - assert(num < num2); - assert(num2 > num); - - let num = IFP256::max(); - let num2 = IFP256::min(); - - assert(num > num2); - assert(num2 < num); - - let num = IFP256::max(); - let num2 = IFP256::from_uint(42_u64); - - assert(num > num2); - assert(num2 < num); - - let num = IFP256::max(); - let num2 = IFP256::max(); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); - - true -} diff --git a/tests/src/fixed_point/ifp256_test/tests/mod.rs b/tests/src/fixed_point/ifp256_test/tests/mod.rs deleted file mode 100644 index 04ff9192..00000000 --- a/tests/src/fixed_point/ifp256_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestIfp256", - abi = "src/fixed_point/ifp256_test/out/release/ifp256_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ifp256_test_script() { - let path_to_bin = "src/fixed_point/ifp256_test/out/release/ifp256_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestIfp256::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ifp64_div_test/.gitignore b/tests/src/fixed_point/ifp64_div_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ifp64_div_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ifp64_div_test/Forc.toml b/tests/src/fixed_point/ifp64_div_test/Forc.toml deleted file mode 100644 index b10e1576..00000000 --- a/tests/src/fixed_point/ifp64_div_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ifp64_div_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ifp64_div_test/mod.rs b/tests/src/fixed_point/ifp64_div_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ifp64_div_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ifp64_div_test/src/main.sw b/tests/src/fixed_point/ifp64_div_test/src/main.sw deleted file mode 100644 index 6b46288d..00000000 --- a/tests/src/fixed_point/ifp64_div_test/src/main.sw +++ /dev/null @@ -1,32 +0,0 @@ -script; - -use sway_libs::fixed_point::ifp64::IFP64; -use std::assert::assert; - -fn main() -> bool { - let one = IFP64::from_uint(1u32); - let two = IFP64::from_uint(2u32); - let mut res = two / one; - assert(two == res); - - let ufp_64_10 = IFP64::from_uint(10u32); - res = ufp_64_10 / two; - assert(IFP64::from_uint(5u32) == res); - - let ufp_64_48 = IFP64::from_uint(48u32); - let six = IFP64::from_uint(6u32); - res = ufp_64_48 / six; - assert(IFP64::from_uint(8u32) == res); - - let ufp_64_169 = IFP64::from_uint(169u32); - let ufp_64_13 = IFP64::from_uint(13u32); - res = ufp_64_169 / ufp_64_13; - assert(IFP64::from_uint(13u32) == res); - - let ufp_64_35 = IFP64::from_uint(35u32); - let ufp_64_5 = IFP64::from_uint(5u32); - res = ufp_64_35 / ufp_64_5; - assert(IFP64::from_uint(7u32) == res); - - true -} diff --git a/tests/src/fixed_point/ifp64_div_test/tests/mod.rs b/tests/src/fixed_point/ifp64_div_test/tests/mod.rs deleted file mode 100644 index 0e0c41d8..00000000 --- a/tests/src/fixed_point/ifp64_div_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestIfp64Div", - abi = "src/fixed_point/ifp64_div_test/out/release/ifp64_div_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ifp64_div_test_script() { - let path_to_bin = "src/fixed_point/ifp64_div_test/out/release/ifp64_div_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestIfp64Div::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ifp64_exp_test/.gitignore b/tests/src/fixed_point/ifp64_exp_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ifp64_exp_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ifp64_exp_test/Forc.toml b/tests/src/fixed_point/ifp64_exp_test/Forc.toml deleted file mode 100644 index 975e3e45..00000000 --- a/tests/src/fixed_point/ifp64_exp_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ifp64_exp_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ifp64_exp_test/mod.rs b/tests/src/fixed_point/ifp64_exp_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ifp64_exp_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ifp64_exp_test/src/main.sw b/tests/src/fixed_point/ifp64_exp_test/src/main.sw deleted file mode 100644 index a45bdd95..00000000 --- a/tests/src/fixed_point/ifp64_exp_test/src/main.sw +++ /dev/null @@ -1,28 +0,0 @@ -script; - -use sway_libs::fixed_point::ifp64::IFP64; -use std::assert::assert; - -fn main() -> bool { - let one = IFP64::from_uint(1u32); - let mut res = IFP64::exp(one); - assert(res.underlying().underlying() == 178142u32); - - let two = IFP64::from_uint(2u32); - res = IFP64::exp(two); - assert(res.underlying().underlying() == 483696u32); - - let four = IFP64::from_uint(4u32); - res = IFP64::exp(four); - assert(res.underlying().underlying() == 3394688u32); - - let seven = IFP64::from_uint(7u32); - res = IFP64::exp(seven); - assert(res.underlying().underlying() == 43019636u32); - - let ten = IFP64::from_uint(10u32); - res = IFP64::exp(ten); - assert(res.underlying().underlying() == 317819696u32); - - true -} diff --git a/tests/src/fixed_point/ifp64_exp_test/tests/mod.rs b/tests/src/fixed_point/ifp64_exp_test/tests/mod.rs deleted file mode 100644 index 05e749f2..00000000 --- a/tests/src/fixed_point/ifp64_exp_test/tests/mod.rs +++ /dev/null @@ -1,21 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestIfp64Exp", - abi = "src/fixed_point/ifp64_exp_test/out/release/ifp64_exp_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ifp64_exp_test_script() { - let path_to_bin = "src/fixed_point/ifp64_exp_test/out/release/ifp64_exp_test.bin"; - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestIfp64Exp::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ifp64_mul_test/.gitignore b/tests/src/fixed_point/ifp64_mul_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ifp64_mul_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ifp64_mul_test/Forc.toml b/tests/src/fixed_point/ifp64_mul_test/Forc.toml deleted file mode 100644 index 33d65845..00000000 --- a/tests/src/fixed_point/ifp64_mul_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ifp64_mul_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ifp64_mul_test/mod.rs b/tests/src/fixed_point/ifp64_mul_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ifp64_mul_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ifp64_mul_test/src/main.sw b/tests/src/fixed_point/ifp64_mul_test/src/main.sw deleted file mode 100644 index 1bbebf27..00000000 --- a/tests/src/fixed_point/ifp64_mul_test/src/main.sw +++ /dev/null @@ -1,33 +0,0 @@ -script; - -use sway_libs::fixed_point::ifp64::IFP64; -use std::assert::assert; - -fn main() -> bool { - let one = IFP64::from_uint(1u32); - let two = IFP64::from_uint(2u32); - let mut res = one * two; - assert(two == res); - - let ufp_64_10 = IFP64::from_uint(10u32); - let ufp_64_20 = IFP64::from_uint(4u32); - res = ufp_64_10 * ufp_64_20; - assert(IFP64::from_uint(40u32) == res); - - let ufp_64_11 = IFP64::from_uint(11u32); - let ufp_64_12 = IFP64::from_uint(12u32); - res = ufp_64_11 * ufp_64_12; - assert(IFP64::from_uint(132u32) == res); - - let ufp_64_150 = IFP64::from_uint(150u32); - let ufp_64_8 = IFP64::from_uint(8u32); - res = ufp_64_150 * ufp_64_8; - assert(IFP64::from_uint(1200u32) == res); - - let ufp_64_7 = IFP64::from_uint(7u32); - let ufp_64_5 = IFP64::from_uint(5u32); - res = ufp_64_7 * ufp_64_5; - assert(IFP64::from_uint(35u32) == res); - - true -} diff --git a/tests/src/fixed_point/ifp64_mul_test/tests/mod.rs b/tests/src/fixed_point/ifp64_mul_test/tests/mod.rs deleted file mode 100644 index 25194a39..00000000 --- a/tests/src/fixed_point/ifp64_mul_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestIfp64Mul", - abi = "src/fixed_point/ifp64_mul_test/out/release/ifp64_mul_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ifp64_mul_test_script() { - let path_to_bin = "src/fixed_point/ifp64_mul_test/out/release/ifp64_mul_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestIfp64Mul::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ifp64_pow_test/.gitignore b/tests/src/fixed_point/ifp64_pow_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ifp64_pow_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ifp64_pow_test/Forc.toml b/tests/src/fixed_point/ifp64_pow_test/Forc.toml deleted file mode 100644 index 7a2f0351..00000000 --- a/tests/src/fixed_point/ifp64_pow_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ifp64_pow_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ifp64_pow_test/mod.rs b/tests/src/fixed_point/ifp64_pow_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ifp64_pow_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ifp64_pow_test/src/main.sw b/tests/src/fixed_point/ifp64_pow_test/src/main.sw deleted file mode 100644 index 2dc5e038..00000000 --- a/tests/src/fixed_point/ifp64_pow_test/src/main.sw +++ /dev/null @@ -1,28 +0,0 @@ -script; - -use sway_libs::fixed_point::ifp64::IFP64; -use std::assert::assert; - -fn main() -> bool { - let one = IFP64::from_uint(1u32); - let mut res = one.pow(1u32); - assert(one == res); - - let two = IFP64::from_uint(2u32); - res = two.pow(3u32); - assert(IFP64::from_uint(8u32) == res); - - let ufp_64_11 = IFP64::from_uint(11u32); - res = ufp_64_11.pow(2u32); - assert(IFP64::from_uint(121u32) == res); - - let five = IFP64::from_uint(5u32); - res = five.pow(3u32); - assert(IFP64::from_uint(125u32) == res); - - let seven = IFP64::from_uint(7u32); - res = seven.pow(2u32); - assert(IFP64::from_uint(49u32) == res); - - true -} diff --git a/tests/src/fixed_point/ifp64_pow_test/tests/mod.rs b/tests/src/fixed_point/ifp64_pow_test/tests/mod.rs deleted file mode 100644 index 5850d02b..00000000 --- a/tests/src/fixed_point/ifp64_pow_test/tests/mod.rs +++ /dev/null @@ -1,21 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestIfp64Pow", - abi = "src/fixed_point/ifp64_pow_test/out/release/ifp64_pow_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ifp64_pow_test_script() { - let path_to_bin = "src/fixed_point/ifp64_pow_test/out/release/ifp64_pow_test.bin"; - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestIfp64Pow::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ifp64_test/.gitignore b/tests/src/fixed_point/ifp64_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ifp64_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ifp64_test/Forc.toml b/tests/src/fixed_point/ifp64_test/Forc.toml deleted file mode 100644 index b73e1bd4..00000000 --- a/tests/src/fixed_point/ifp64_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ifp64_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ifp64_test/mod.rs b/tests/src/fixed_point/ifp64_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ifp64_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ifp64_test/src/main.sw b/tests/src/fixed_point/ifp64_test/src/main.sw deleted file mode 100644 index 4e4b1744..00000000 --- a/tests/src/fixed_point/ifp64_test/src/main.sw +++ /dev/null @@ -1,145 +0,0 @@ -script; - -use sway_libs::fixed_point::{ifp64::IFP64, ufp32::UFP32}; -use std::assert::assert; - -fn main() -> bool { - // arithmetic - let one = IFP64::from_uint(1u32); - let two = IFP64::from_uint(2u32); - let mut res = two + one; - assert(IFP64::from_uint(3u32) == res); - - let ifp_64_10 = IFP64::from_uint(10u32); - res = ifp_64_10 + two; - assert(IFP64::from_uint(12u32) == res); - - let ufp_64_48 = IFP64::from_uint(48u32); - let six = IFP64::from_uint(6u32); - res = ufp_64_48 - six; - assert(IFP64::from_uint(42u32) == res); - - let ufp_64_169 = IFP64::from_uint(169u32); - let ufp_64_13 = IFP64::from_uint(13u32); - res = ufp_64_169 - ufp_64_13; - assert(IFP64::from_uint(156u32) == res); - - // recip - let mut u_value = UFP32::from(1u32 << 16 + 3); - let mut value = IFP64::from(u_value); - - res = IFP64::recip(value); - assert(IFP64::from(UFP32::from(8192u32)) == res); - - // trunc - u_value = UFP32::from((1u32 << 16) + 3u32); - value = IFP64::from(u_value); - - res = value.trunc(); - assert(IFP64::from_uint(1u32) == res); - - // floor - u_value = UFP32::from((1u32 << 16) + 3u32); - value = IFP64::from(u_value); - - res = value.floor(); - assert(IFP64::from_uint(1u32) == res); - - // fract - u_value = UFP32::from((1u32 << 16) + 3u32); - value = IFP64::from(u_value); - - res = value.fract(); - assert(IFP64::from(UFP32::from(3u32)) == res); - - value = IFP64::from_uint(1u32); - res = value.fract(); - assert(IFP64::from_uint(0u32) == res); - - // ceil - u_value = UFP32::from((1u32 << 16) + 3u32); - value = IFP64::from(u_value); - - res = value.ceil(); - assert(IFP64::from_uint(2u32) == res); - - value = IFP64::from_uint(1u32); - res = value.ceil(); - assert(IFP64::from_uint(1u32) == res); - - // round - u_value = UFP32::from((1u32 << 16) + 3u32); - value = IFP64::from(u_value); - - res = value.round(); - assert(IFP64::from_uint(1u32) == res); - - u_value = UFP32::from((1u32 << 16) + (1u32 << 15) + 1u32); - value = IFP64::from(u_value); - - res = value.round(); - assert(IFP64::from_uint(2u32) == res); - - // Ord tests - let num = IFP64::min(); - let num2 = IFP64::min(); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); - - let num = IFP64::min(); - let num2 = IFP64::from_uint(42_u32); - - assert(num < num2); - assert(num2 > num); - - let num = IFP64::min(); - let num2 = IFP64::max(); - - assert(num < num2); - assert(num2 > num); - - let num = IFP64::from_uint(42_u32); - let num2 = IFP64::min(); - - assert(num > num2); - assert(num2 < num); - - let num = IFP64::from_uint(42_u32); - let num2 = IFP64::from_uint(42_u32); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); - - let num = IFP64::from_uint(42_u32); - let num2 = IFP64::max(); - - assert(num < num2); - assert(num2 > num); - - let num = IFP64::max(); - let num2 = IFP64::min(); - - assert(num > num2); - assert(num2 < num); - - let num = IFP64::max(); - let num2 = IFP64::from_uint(42_u32); - - assert(num > num2); - assert(num2 < num); - - let num = IFP64::max(); - let num2 = IFP64::max(); - - assert(!(num > num2)); - assert(!(num < num2)); - assert(!(num2 < num)); - assert(!(num2 > num)); - - true -} diff --git a/tests/src/fixed_point/ifp64_test/tests/mod.rs b/tests/src/fixed_point/ifp64_test/tests/mod.rs deleted file mode 100644 index 74fa67de..00000000 --- a/tests/src/fixed_point/ifp64_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestIfp64", - abi = "src/fixed_point/ifp64_test/out/release/ifp64_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ifp64_test_script() { - let path_to_bin = "src/fixed_point/ifp64_test/out/release/ifp64_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestIfp64::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/mod.rs b/tests/src/fixed_point/mod.rs deleted file mode 100644 index 9c7bb6fb..00000000 --- a/tests/src/fixed_point/mod.rs +++ /dev/null @@ -1,23 +0,0 @@ -mod ifp128_div_test; -mod ifp128_test; -mod ifp256_div_test; -mod ifp256_test; -mod ifp64_div_test; -mod ifp64_exp_test; -mod ifp64_mul_test; -mod ifp64_pow_test; -mod ifp64_test; -mod ufp128_div_test; -mod ufp128_test; -mod ufp32_div_test; -mod ufp32_exp_test; -mod ufp32_mul_test; -mod ufp32_pow_test; -mod ufp32_root_test; -mod ufp32_test; -mod ufp64_div_test; -mod ufp64_exp_test; -mod ufp64_mul_test; -mod ufp64_pow_test; -mod ufp64_root_test; -mod ufp64_test; diff --git a/tests/src/fixed_point/ufp128_div_test/.gitignore b/tests/src/fixed_point/ufp128_div_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ufp128_div_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ufp128_div_test/Forc.toml b/tests/src/fixed_point/ufp128_div_test/Forc.toml deleted file mode 100644 index 33856bae..00000000 --- a/tests/src/fixed_point/ufp128_div_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ufp128_div_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ufp128_div_test/mod.rs b/tests/src/fixed_point/ufp128_div_test/mod.rs deleted file mode 100644 index 14f00389..00000000 --- a/tests/src/fixed_point/ufp128_div_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ufp128_div_test/src/main.sw b/tests/src/fixed_point/ufp128_div_test/src/main.sw deleted file mode 100644 index fb179ad2..00000000 --- a/tests/src/fixed_point/ufp128_div_test/src/main.sw +++ /dev/null @@ -1,25 +0,0 @@ -script; - -use sway_libs::fixed_point::ufp128::UFP128; - -fn main() -> bool { - let zero = UFP128::from((0, 0)); - let mut up = UFP128::from((1, 0)); - let mut down = UFP128::from((2, 0)); - let mut res = up / down; - assert(res == UFP128::from((0, 9223372036854775808))); - - up = UFP128::from((4, 0)); - down = UFP128::from((2, 0)); - res = up / down; - - assert(res == UFP128::from((2, 0))); - - up = UFP128::from((9, 0)); - down = UFP128::from((4, 0)); - res = up / down; - - assert(res == UFP128::from((2, 4611686018427387904))); - - true -} diff --git a/tests/src/fixed_point/ufp128_div_test/tests/mod.rs b/tests/src/fixed_point/ufp128_div_test/tests/mod.rs deleted file mode 100644 index aa195110..00000000 --- a/tests/src/fixed_point/ufp128_div_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestUfp128Div", - abi = "src/fixed_point/ufp128_div_test/out/release/ufp128_div_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ufp128_div_test_script() { - let path_to_bin = "src/fixed_point/ufp128_div_test/out/release/ufp128_div_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestUfp128Div::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ufp128_test/.gitignore b/tests/src/fixed_point/ufp128_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ufp128_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ufp128_test/Forc.toml b/tests/src/fixed_point/ufp128_test/Forc.toml deleted file mode 100644 index ad1ecd32..00000000 --- a/tests/src/fixed_point/ufp128_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ufp128_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ufp128_test/mod.rs b/tests/src/fixed_point/ufp128_test/mod.rs deleted file mode 100644 index 14f00389..00000000 --- a/tests/src/fixed_point/ufp128_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ufp128_test/src/main.sw b/tests/src/fixed_point/ufp128_test/src/main.sw deleted file mode 100644 index e135160d..00000000 --- a/tests/src/fixed_point/ufp128_test/src/main.sw +++ /dev/null @@ -1,70 +0,0 @@ -script; - -use sway_libs::fixed_point::ufp128::UFP128; -use std::u128::U128; - -fn main() -> bool { - // arithmetic - let one = UFP128::from((1, 0)); - let two = UFP128::from((2, 0)); - let mut res = two + one; - assert(UFP128::from((3, 0)) == res); - - let ufp_128_10 = UFP128::from((10, 0)); - res = ufp_128_10 + two; - assert(UFP128::from((12, 0)) == res); - - let ufp_128_48 = UFP128::from((48, 0)); - let six = UFP128::from((6, 0)); - res = ufp_128_48 - six; - assert(UFP128::from((42, 0)) == res); - - let ufp_128_169 = UFP128::from((169, 0)); - let ufp_128_13 = UFP128::from((13, 0)); - res = ufp_128_169 - ufp_128_13; - assert(UFP128::from((156, 0)) == res); - - // recip - let mut value = UFP128::from(U128::from((1, 3))); - res = UFP128::recip(value); - assert(UFP128::from(U128::from((0, 18446744073709551613))) == res); - - // trunc - let mut value = UFP128::from(U128::from((1, 3))); - res = value.trunc(); - assert(UFP128::from_uint(1) == res); - - // floor - value = UFP128::from(U128::from((1, 3))); - res = value.floor(); - assert(UFP128::from_uint(1) == res); - - // fract - value = UFP128::from(U128::from((1, 3))); - res = value.fract(); - assert(UFP128::from(U128::from((0, 3))) == res); - - value = UFP128::from_uint(1); - res = value.fract(); - assert(UFP128::from_uint(0) == res); - - // ceil - value = UFP128::from(U128::from((1, 3))); - res = value.ceil(); - assert(UFP128::from_uint(2) == res); - - value = UFP128::from_uint(1); - res = value.ceil(); - assert(UFP128::from_uint(1) == res); - - // round - value = UFP128::from(U128::from((1, 3))); - res = value.round(); - assert(UFP128::from_uint(1) == res); - - value = UFP128::from(U128::from((1, (1 << 63) + 1))); - res = value.round(); - assert(UFP128::from_uint(2) == res); - - true -} diff --git a/tests/src/fixed_point/ufp128_test/tests/mod.rs b/tests/src/fixed_point/ufp128_test/tests/mod.rs deleted file mode 100644 index a26fe8de..00000000 --- a/tests/src/fixed_point/ufp128_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestUfp128", - abi = "src/fixed_point/ufp128_test/out/release/ufp128_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ufp128_test_script() { - let path_to_bin = "src/fixed_point/ufp128_test/out/release/ufp128_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestUfp128::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ufp32_div_test/.gitignore b/tests/src/fixed_point/ufp32_div_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ufp32_div_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ufp32_div_test/Forc.toml b/tests/src/fixed_point/ufp32_div_test/Forc.toml deleted file mode 100644 index 687bbe67..00000000 --- a/tests/src/fixed_point/ufp32_div_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ufp32_div_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ufp32_div_test/mod.rs b/tests/src/fixed_point/ufp32_div_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ufp32_div_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ufp32_div_test/src/main.sw b/tests/src/fixed_point/ufp32_div_test/src/main.sw deleted file mode 100644 index 4eb03b99..00000000 --- a/tests/src/fixed_point/ufp32_div_test/src/main.sw +++ /dev/null @@ -1,32 +0,0 @@ -script; - -use sway_libs::fixed_point::ufp32::UFP32; -use std::assert::assert; - -fn main() -> bool { - let one = UFP32::from_uint(1); - let two = UFP32::from_uint(2); - let mut res = two / one; - assert(two == res); - - let ufp_64_10 = UFP32::from_uint(10); - res = ufp_64_10 / two; - assert(UFP32::from_uint(5) == res); - - let ufp_64_48 = UFP32::from_uint(48); - let six = UFP32::from_uint(6); - res = ufp_64_48 / six; - assert(UFP32::from_uint(8) == res); - - let ufp_64_169 = UFP32::from_uint(169); - let ufp_64_13 = UFP32::from_uint(13); - res = ufp_64_169 / ufp_64_13; - assert(UFP32::from_uint(13) == res); - - let ufp_64_35 = UFP32::from_uint(35); - let ufp_64_5 = UFP32::from_uint(5); - res = ufp_64_35 / ufp_64_5; - assert(UFP32::from_uint(7) == res); - - true -} diff --git a/tests/src/fixed_point/ufp32_div_test/tests/mod.rs b/tests/src/fixed_point/ufp32_div_test/tests/mod.rs deleted file mode 100644 index 250302fd..00000000 --- a/tests/src/fixed_point/ufp32_div_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestUfp32Div", - abi = "src/fixed_point/ufp32_div_test/out/release/ufp32_div_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ufp32_div_test_script() { - let path_to_bin = "src/fixed_point/ufp32_div_test/out/release/ufp32_div_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestUfp32Div::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ufp32_exp_test/.gitignore b/tests/src/fixed_point/ufp32_exp_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ufp32_exp_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ufp32_exp_test/Forc.toml b/tests/src/fixed_point/ufp32_exp_test/Forc.toml deleted file mode 100644 index a5f46a99..00000000 --- a/tests/src/fixed_point/ufp32_exp_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ufp32_exp_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ufp32_exp_test/mod.rs b/tests/src/fixed_point/ufp32_exp_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ufp32_exp_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ufp32_exp_test/src/main.sw b/tests/src/fixed_point/ufp32_exp_test/src/main.sw deleted file mode 100644 index 56a6533d..00000000 --- a/tests/src/fixed_point/ufp32_exp_test/src/main.sw +++ /dev/null @@ -1,28 +0,0 @@ -script; - -use sway_libs::fixed_point::ufp32::UFP32; -use std::assert::assert; - -fn main() -> bool { - let one = UFP32::from_uint(1); - let mut res = UFP32::exp(one); - assert(res.underlying() == 11674811894); - - let two = UFP32::from_uint(2); - res = UFP32::exp(two); - assert(res.underlying() == 31700949040); - - let four = UFP32::from_uint(4); - res = UFP32::exp(four); - assert(res.underlying() == 222506572928); - - let seven = UFP32::from_uint(7); - res = UFP32::exp(seven); - assert(res.underlying() == 2819944203710); - - let ten = UFP32::from_uint(10); - res = UFP32::exp(ten); - assert(res.underlying() == 20833521987056); - - true -} diff --git a/tests/src/fixed_point/ufp32_exp_test/tests/mod.rs b/tests/src/fixed_point/ufp32_exp_test/tests/mod.rs deleted file mode 100644 index df10cd35..00000000 --- a/tests/src/fixed_point/ufp32_exp_test/tests/mod.rs +++ /dev/null @@ -1,21 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestUfp32Exp", - abi = "src/fixed_point/ufp32_exp_test/out/release/ufp32_exp_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ufp32_exp_test_script() { - let path_to_bin = "src/fixed_point/ufp32_exp_test/out/release/ufp32_exp_test.bin"; - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestUfp32Exp::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ufp32_mul_test/.gitignore b/tests/src/fixed_point/ufp32_mul_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ufp32_mul_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ufp32_mul_test/Forc.toml b/tests/src/fixed_point/ufp32_mul_test/Forc.toml deleted file mode 100644 index a111aa10..00000000 --- a/tests/src/fixed_point/ufp32_mul_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ufp32_mul_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ufp32_mul_test/mod.rs b/tests/src/fixed_point/ufp32_mul_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ufp32_mul_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ufp32_mul_test/src/main.sw b/tests/src/fixed_point/ufp32_mul_test/src/main.sw deleted file mode 100644 index cf8ba8cd..00000000 --- a/tests/src/fixed_point/ufp32_mul_test/src/main.sw +++ /dev/null @@ -1,33 +0,0 @@ -script; - -use sway_libs::fixed_point::ufp32::UFP32; -use std::assert::assert; - -fn main() -> bool { - let one = UFP32::from_uint(1); - let two = UFP32::from_uint(2); - let mut res = one * two; - assert(two == res); - - let ufp_64_10 = UFP32::from_uint(10); - let ufp_64_20 = UFP32::from_uint(4); - res = ufp_64_10 * ufp_64_20; - assert(UFP32::from_uint(40) == res); - - let ufp_64_11 = UFP32::from_uint(11); - let ufp_64_12 = UFP32::from_uint(12); - res = ufp_64_11 * ufp_64_12; - assert(UFP32::from_uint(132) == res); - - let ufp_64_150 = UFP32::from_uint(150); - let ufp_64_8 = UFP32::from_uint(8); - res = ufp_64_150 * ufp_64_8; - assert(UFP32::from_uint(1200) == res); - - let ufp_64_7 = UFP32::from_uint(7); - let ufp_64_5 = UFP32::from_uint(5); - res = ufp_64_7 * ufp_64_5; - assert(UFP32::from_uint(35) == res); - - true -} diff --git a/tests/src/fixed_point/ufp32_mul_test/tests/mod.rs b/tests/src/fixed_point/ufp32_mul_test/tests/mod.rs deleted file mode 100644 index f5872c77..00000000 --- a/tests/src/fixed_point/ufp32_mul_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestUfp32Mul", - abi = "src/fixed_point/ufp32_mul_test/out/release/ufp32_mul_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ufp32_mul_test_script() { - let path_to_bin = "src/fixed_point/ufp32_mul_test/out/release/ufp32_mul_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestUfp32Mul::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ufp32_pow_test/.gitignore b/tests/src/fixed_point/ufp32_pow_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ufp32_pow_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ufp32_pow_test/Forc.toml b/tests/src/fixed_point/ufp32_pow_test/Forc.toml deleted file mode 100644 index 34d68507..00000000 --- a/tests/src/fixed_point/ufp32_pow_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ufp32_pow_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ufp32_pow_test/mod.rs b/tests/src/fixed_point/ufp32_pow_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ufp32_pow_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ufp32_pow_test/src/main.sw b/tests/src/fixed_point/ufp32_pow_test/src/main.sw deleted file mode 100644 index 9369d55e..00000000 --- a/tests/src/fixed_point/ufp32_pow_test/src/main.sw +++ /dev/null @@ -1,28 +0,0 @@ -script; - -use sway_libs::fixed_point::ufp32::UFP32; -use std::assert::assert; - -fn main() -> bool { - let one = UFP32::from_uint(1); - let mut res = one.pow(1u32); - assert(one == res); - - let two = UFP32::from_uint(2); - res = two.pow(3u32); - assert(UFP32::from_uint(8) == res); - - let ufp_64_11 = UFP32::from_uint(11); - res = ufp_64_11.pow(2u32); - assert(UFP32::from_uint(121) == res); - - let five = UFP32::from_uint(5); - res = five.pow(3u32); - assert(UFP32::from_uint(125) == res); - - let seven = UFP32::from_uint(7); - res = seven.pow(2u32); - assert(UFP32::from_uint(49) == res); - - true -} diff --git a/tests/src/fixed_point/ufp32_pow_test/tests/mod.rs b/tests/src/fixed_point/ufp32_pow_test/tests/mod.rs deleted file mode 100644 index f3c41a94..00000000 --- a/tests/src/fixed_point/ufp32_pow_test/tests/mod.rs +++ /dev/null @@ -1,21 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestUfp32Pow", - abi = "src/fixed_point/ufp32_pow_test/out/release/ufp32_pow_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ufp32_pow_test_script() { - let path_to_bin = "src/fixed_point/ufp32_pow_test/out/release/ufp32_pow_test.bin"; - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestUfp32Pow::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ufp32_root_test/.gitignore b/tests/src/fixed_point/ufp32_root_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ufp32_root_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ufp32_root_test/Forc.toml b/tests/src/fixed_point/ufp32_root_test/Forc.toml deleted file mode 100644 index 0e95d661..00000000 --- a/tests/src/fixed_point/ufp32_root_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ufp32_root_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ufp32_root_test/mod.rs b/tests/src/fixed_point/ufp32_root_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ufp32_root_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ufp32_root_test/src/main.sw b/tests/src/fixed_point/ufp32_root_test/src/main.sw deleted file mode 100644 index cb3f87a8..00000000 --- a/tests/src/fixed_point/ufp32_root_test/src/main.sw +++ /dev/null @@ -1,28 +0,0 @@ -script; - -use sway_libs::fixed_point::ufp32::UFP32; -use std::assert::assert; - -fn main() -> bool { - let one = UFP32::from_uint(1); - let mut res = UFP32::sqrt(one); - assert(one == res); - - let ufp32_100 = UFP32::from_uint(100); - res = UFP32::sqrt(ufp32_100); - assert(UFP32::from_uint(10) == res); - - let ufp32_121 = UFP32::from_uint(121); - res = UFP32::sqrt(ufp32_121); - assert(UFP32::from_uint(11) == res); - - let ufp32_169 = UFP32::from_uint(169); - res = UFP32::sqrt(ufp32_169); - assert(UFP32::from_uint(13) == res); - - let ufp32_49 = UFP32::from_uint(49); - res = UFP32::sqrt(ufp32_49); - assert(UFP32::from_uint(7) == res); - - true -} diff --git a/tests/src/fixed_point/ufp32_root_test/tests/mod.rs b/tests/src/fixed_point/ufp32_root_test/tests/mod.rs deleted file mode 100644 index bad3073e..00000000 --- a/tests/src/fixed_point/ufp32_root_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestUfp32Root", - abi = "src/fixed_point/ufp32_root_test/out/release/ufp32_root_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ufp32_root_test_script() { - let path_to_bin = "src/fixed_point/ufp32_root_test/out/release/ufp32_root_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestUfp32Root::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ufp32_test/.gitignore b/tests/src/fixed_point/ufp32_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ufp32_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ufp32_test/Forc.toml b/tests/src/fixed_point/ufp32_test/Forc.toml deleted file mode 100644 index 0e3a2fdd..00000000 --- a/tests/src/fixed_point/ufp32_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ufp32_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ufp32_test/mod.rs b/tests/src/fixed_point/ufp32_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ufp32_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ufp32_test/src/main.sw b/tests/src/fixed_point/ufp32_test/src/main.sw deleted file mode 100644 index 4c6d3cf2..00000000 --- a/tests/src/fixed_point/ufp32_test/src/main.sw +++ /dev/null @@ -1,70 +0,0 @@ -script; - -use sway_libs::fixed_point::ufp32::UFP32; -use std::assert::assert; - -fn main() -> bool { - // arithmetic - let one = UFP32::from_uint(1); - let two = UFP32::from_uint(2); - let mut res = two + one; - assert(UFP32::from_uint(3) == res); - - let ufp_32_10 = UFP32::from_uint(10); - res = ufp_32_10 + two; - assert(UFP32::from_uint(12) == res); - - let ufp_32_48 = UFP32::from_uint(48); - let six = UFP32::from_uint(6); - res = ufp_32_48 - six; - assert(UFP32::from_uint(42) == res); - - let ufp_32_169 = UFP32::from_uint(169); - let ufp_32_13 = UFP32::from_uint(13); - res = ufp_32_169 - ufp_32_13; - assert(UFP32::from_uint(156) == res); - - // recip - let mut value = UFP32::from(3u32); - res = UFP32::recip(value); - assert(UFP32::from(536870912) == res); - - // trunc - value = UFP32::from(3u32); - res = value.trunc(); - assert(UFP32::from_uint(1) == res); - - // floor - value = UFP32::from(3u32); - res = value.floor(); - assert(UFP32::from_uint(1) == res); - - // fract - value = UFP32::from(3u32); - res = value.fract(); - assert(UFP32::from(3) == res); - - value = UFP32::from_uint(1); - res = value.fract(); - assert(UFP32::from_uint(0) == res); - - // ceil - value = UFP32::from(3u32); - res = value.ceil(); - assert(UFP32::from_uint(2) == res); - - value = UFP32::from_uint(1); - res = value.ceil(); - assert(UFP32::from_uint(1) == res); - - // round - value = UFP32::from(3u32); - res = value.round(); - assert(UFP32::from_uint(1) == res); - - value = UFP32::from(2147483649u32); - res = value.round(); - assert(UFP32::from_uint(2) == res); - - true -} diff --git a/tests/src/fixed_point/ufp32_test/tests/mod.rs b/tests/src/fixed_point/ufp32_test/tests/mod.rs deleted file mode 100644 index 732647c1..00000000 --- a/tests/src/fixed_point/ufp32_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestUfp32", - abi = "src/fixed_point/ufp32_test/out/release/ufp32_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ufp32_test_script() { - let path_to_bin = "src/fixed_point/ufp32_test/out/release/ufp32_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestUfp32::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ufp64_div_test/.gitignore b/tests/src/fixed_point/ufp64_div_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ufp64_div_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ufp64_div_test/Forc.toml b/tests/src/fixed_point/ufp64_div_test/Forc.toml deleted file mode 100644 index cc199bab..00000000 --- a/tests/src/fixed_point/ufp64_div_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ufp64_div_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ufp64_div_test/mod.rs b/tests/src/fixed_point/ufp64_div_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ufp64_div_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ufp64_div_test/src/main.sw b/tests/src/fixed_point/ufp64_div_test/src/main.sw deleted file mode 100644 index 7c9d4d27..00000000 --- a/tests/src/fixed_point/ufp64_div_test/src/main.sw +++ /dev/null @@ -1,32 +0,0 @@ -script; - -use sway_libs::fixed_point::ufp64::UFP64; -use std::assert::assert; - -fn main() -> bool { - let one = UFP64::from_uint(1); - let two = UFP64::from_uint(2); - let mut res = two / one; - assert(two == res); - - let ufp_64_10 = UFP64::from_uint(10); - res = ufp_64_10 / two; - assert(UFP64::from_uint(5) == res); - - let ufp_64_48 = UFP64::from_uint(48); - let six = UFP64::from_uint(6); - res = ufp_64_48 / six; - assert(UFP64::from_uint(8) == res); - - let ufp_64_169 = UFP64::from_uint(169); - let ufp_64_13 = UFP64::from_uint(13); - res = ufp_64_169 / ufp_64_13; - assert(UFP64::from_uint(13) == res); - - let ufp_64_35 = UFP64::from_uint(35); - let ufp_64_5 = UFP64::from_uint(5); - res = ufp_64_35 / ufp_64_5; - assert(UFP64::from_uint(7) == res); - - true -} diff --git a/tests/src/fixed_point/ufp64_div_test/tests/mod.rs b/tests/src/fixed_point/ufp64_div_test/tests/mod.rs deleted file mode 100644 index 48bfff19..00000000 --- a/tests/src/fixed_point/ufp64_div_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestUfp64Div", - abi = "src/fixed_point/ufp64_div_test/out/release/ufp64_div_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ufp64_div_test_script() { - let path_to_bin = "src/fixed_point/ufp64_div_test/out/release/ufp64_div_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestUfp64Div::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ufp64_exp_test/.gitignore b/tests/src/fixed_point/ufp64_exp_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ufp64_exp_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ufp64_exp_test/Forc.toml b/tests/src/fixed_point/ufp64_exp_test/Forc.toml deleted file mode 100644 index 7c087ce8..00000000 --- a/tests/src/fixed_point/ufp64_exp_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ufp64_exp_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ufp64_exp_test/mod.rs b/tests/src/fixed_point/ufp64_exp_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ufp64_exp_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ufp64_exp_test/src/main.sw b/tests/src/fixed_point/ufp64_exp_test/src/main.sw deleted file mode 100644 index 62936f00..00000000 --- a/tests/src/fixed_point/ufp64_exp_test/src/main.sw +++ /dev/null @@ -1,28 +0,0 @@ -script; - -use sway_libs::fixed_point::ufp64::UFP64; -use std::assert::assert; - -fn main() -> bool { - let one = UFP64::from_uint(1); - let mut res = UFP64::exp(one); - assert(res.underlying() == 11674811894); - - let two = UFP64::from_uint(2); - res = UFP64::exp(two); - assert(res.underlying() == 31700949040); - - let four = UFP64::from_uint(4); - res = UFP64::exp(four); - assert(res.underlying() == 222506572928); - - let seven = UFP64::from_uint(7); - res = UFP64::exp(seven); - assert(res.underlying() == 2819944203710); - - let ten = UFP64::from_uint(10); - res = UFP64::exp(ten); - assert(res.underlying() == 20833521987056); - - true -} diff --git a/tests/src/fixed_point/ufp64_exp_test/tests/mod.rs b/tests/src/fixed_point/ufp64_exp_test/tests/mod.rs deleted file mode 100644 index d25b952c..00000000 --- a/tests/src/fixed_point/ufp64_exp_test/tests/mod.rs +++ /dev/null @@ -1,21 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestUfp64Exp", - abi = "src/fixed_point/ufp64_exp_test/out/release/ufp64_exp_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ufp64_exp_test_script() { - let path_to_bin = "src/fixed_point/ufp64_exp_test/out/release/ufp64_exp_test.bin"; - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestUfp64Exp::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ufp64_mul_test/.gitignore b/tests/src/fixed_point/ufp64_mul_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ufp64_mul_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ufp64_mul_test/Forc.toml b/tests/src/fixed_point/ufp64_mul_test/Forc.toml deleted file mode 100644 index feb01298..00000000 --- a/tests/src/fixed_point/ufp64_mul_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ufp64_mul_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ufp64_mul_test/mod.rs b/tests/src/fixed_point/ufp64_mul_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ufp64_mul_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ufp64_mul_test/src/main.sw b/tests/src/fixed_point/ufp64_mul_test/src/main.sw deleted file mode 100644 index 391cc3c6..00000000 --- a/tests/src/fixed_point/ufp64_mul_test/src/main.sw +++ /dev/null @@ -1,33 +0,0 @@ -script; - -use sway_libs::fixed_point::ufp64::UFP64; -use std::assert::assert; - -fn main() -> bool { - let one = UFP64::from_uint(1); - let two = UFP64::from_uint(2); - let mut res = one * two; - assert(two == res); - - let ufp_64_10 = UFP64::from_uint(10); - let ufp_64_20 = UFP64::from_uint(4); - res = ufp_64_10 * ufp_64_20; - assert(UFP64::from_uint(40) == res); - - let ufp_64_11 = UFP64::from_uint(11); - let ufp_64_12 = UFP64::from_uint(12); - res = ufp_64_11 * ufp_64_12; - assert(UFP64::from_uint(132) == res); - - let ufp_64_150 = UFP64::from_uint(150); - let ufp_64_8 = UFP64::from_uint(8); - res = ufp_64_150 * ufp_64_8; - assert(UFP64::from_uint(1200) == res); - - let ufp_64_7 = UFP64::from_uint(7); - let ufp_64_5 = UFP64::from_uint(5); - res = ufp_64_7 * ufp_64_5; - assert(UFP64::from_uint(35) == res); - - true -} diff --git a/tests/src/fixed_point/ufp64_mul_test/tests/mod.rs b/tests/src/fixed_point/ufp64_mul_test/tests/mod.rs deleted file mode 100644 index 8f386670..00000000 --- a/tests/src/fixed_point/ufp64_mul_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestUfp64Mul", - abi = "src/fixed_point/ufp64_mul_test/out/release/ufp64_mul_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ufp64_mul_test_script() { - let path_to_bin = "src/fixed_point/ufp64_mul_test/out/release/ufp64_mul_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestUfp64Mul::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ufp64_pow_test/.gitignore b/tests/src/fixed_point/ufp64_pow_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ufp64_pow_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ufp64_pow_test/Forc.toml b/tests/src/fixed_point/ufp64_pow_test/Forc.toml deleted file mode 100644 index ff7a780c..00000000 --- a/tests/src/fixed_point/ufp64_pow_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ufp64_pow_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ufp64_pow_test/mod.rs b/tests/src/fixed_point/ufp64_pow_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ufp64_pow_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ufp64_pow_test/src/main.sw b/tests/src/fixed_point/ufp64_pow_test/src/main.sw deleted file mode 100644 index 99199dd6..00000000 --- a/tests/src/fixed_point/ufp64_pow_test/src/main.sw +++ /dev/null @@ -1,28 +0,0 @@ -script; - -use sway_libs::fixed_point::ufp64::UFP64; -use std::assert::assert; - -fn main() -> bool { - let one = UFP64::from_uint(1); - let mut res = one.pow(1u32); - assert(one == res); - - let two = UFP64::from_uint(2); - res = two.pow(3u32); - assert(UFP64::from_uint(8) == res); - - let ufp_64_11 = UFP64::from_uint(11); - res = ufp_64_11.pow(2u32); - assert(UFP64::from_uint(121) == res); - - let five = UFP64::from_uint(5); - res = five.pow(3u32); - assert(UFP64::from_uint(125) == res); - - let seven = UFP64::from_uint(7); - res = seven.pow(2u32); - assert(UFP64::from_uint(49) == res); - - true -} diff --git a/tests/src/fixed_point/ufp64_pow_test/tests/mod.rs b/tests/src/fixed_point/ufp64_pow_test/tests/mod.rs deleted file mode 100644 index 14b79985..00000000 --- a/tests/src/fixed_point/ufp64_pow_test/tests/mod.rs +++ /dev/null @@ -1,21 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestUfp64Pow", - abi = "src/fixed_point/ufp64_pow_test/out/release/ufp64_pow_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ufp64_pow_test_script() { - let path_to_bin = "src/fixed_point/ufp64_pow_test/out/release/ufp64_pow_test.bin"; - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestUfp64Pow::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ufp64_root_test/.gitignore b/tests/src/fixed_point/ufp64_root_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ufp64_root_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ufp64_root_test/Forc.toml b/tests/src/fixed_point/ufp64_root_test/Forc.toml deleted file mode 100644 index 0357327c..00000000 --- a/tests/src/fixed_point/ufp64_root_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ufp64_root_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ufp64_root_test/mod.rs b/tests/src/fixed_point/ufp64_root_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ufp64_root_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ufp64_root_test/src/main.sw b/tests/src/fixed_point/ufp64_root_test/src/main.sw deleted file mode 100644 index e1694e17..00000000 --- a/tests/src/fixed_point/ufp64_root_test/src/main.sw +++ /dev/null @@ -1,28 +0,0 @@ -script; - -use sway_libs::fixed_point::ufp64::UFP64; -use std::assert::assert; - -fn main() -> bool { - let one = UFP64::from_uint(1); - let mut res = UFP64::sqrt(one); - assert(one == res); - - let ufp64_100 = UFP64::from_uint(100); - res = UFP64::sqrt(ufp64_100); - assert(UFP64::from_uint(10) == res); - - let ufp64_121 = UFP64::from_uint(121); - res = UFP64::sqrt(ufp64_121); - assert(UFP64::from_uint(11) == res); - - let ufp64_169 = UFP64::from_uint(169); - res = UFP64::sqrt(ufp64_169); - assert(UFP64::from_uint(13) == res); - - let ufp64_49 = UFP64::from_uint(49); - res = UFP64::sqrt(ufp64_49); - assert(UFP64::from_uint(7) == res); - - true -} diff --git a/tests/src/fixed_point/ufp64_root_test/tests/mod.rs b/tests/src/fixed_point/ufp64_root_test/tests/mod.rs deleted file mode 100644 index 5df07ee0..00000000 --- a/tests/src/fixed_point/ufp64_root_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestUfp64Root", - abi = "src/fixed_point/ufp64_root_test/out/release/ufp64_root_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ufp64_root_test_script() { - let path_to_bin = "src/fixed_point/ufp64_root_test/out/release/ufp64_root_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestUfp64Root::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/fixed_point/ufp64_test/.gitignore b/tests/src/fixed_point/ufp64_test/.gitignore deleted file mode 100644 index 77d3844f..00000000 --- a/tests/src/fixed_point/ufp64_test/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -out -target diff --git a/tests/src/fixed_point/ufp64_test/Forc.toml b/tests/src/fixed_point/ufp64_test/Forc.toml deleted file mode 100644 index 7a08c5ea..00000000 --- a/tests/src/fixed_point/ufp64_test/Forc.toml +++ /dev/null @@ -1,8 +0,0 @@ -[project] -authors = ["Fuel Labs "] -entry = "main.sw" -license = "Apache-2.0" -name = "ufp64_test" - -[dependencies] -sway_libs = { path = "../../../../libs" } diff --git a/tests/src/fixed_point/ufp64_test/mod.rs b/tests/src/fixed_point/ufp64_test/mod.rs deleted file mode 100644 index dc39c4cc..00000000 --- a/tests/src/fixed_point/ufp64_test/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod tests; diff --git a/tests/src/fixed_point/ufp64_test/src/main.sw b/tests/src/fixed_point/ufp64_test/src/main.sw deleted file mode 100644 index c76d2ed8..00000000 --- a/tests/src/fixed_point/ufp64_test/src/main.sw +++ /dev/null @@ -1,70 +0,0 @@ -script; - -use sway_libs::fixed_point::ufp64::UFP64; -use std::assert::assert; - -fn main() -> bool { - // arithmetic - let one = UFP64::from_uint(1); - let two = UFP64::from_uint(2); - let mut res = two + one; - assert(UFP64::from_uint(3) == res); - - let ufp_64_10 = UFP64::from_uint(10); - res = ufp_64_10 + two; - assert(UFP64::from_uint(12) == res); - - let ufp_64_48 = UFP64::from_uint(48); - let six = UFP64::from_uint(6); - res = ufp_64_48 - six; - assert(UFP64::from_uint(42) == res); - - let ufp_64_169 = UFP64::from_uint(169); - let ufp_64_13 = UFP64::from_uint(13); - res = ufp_64_169 - ufp_64_13; - assert(UFP64::from_uint(156) == res); - - // recip - let mut value = UFP64::from(1 << 32 + 3); - res = UFP64::recip(value); - assert(UFP64::from(536870912) == res); - - // trunc - value = UFP64::from((1 << 32) + 3); - res = value.trunc(); - assert(UFP64::from_uint(1) == res); - - // floor - value = UFP64::from((1 << 32) + 3); - res = value.floor(); - assert(UFP64::from_uint(1) == res); - - // fract - value = UFP64::from((1 << 32) + 3); - res = value.fract(); - assert(UFP64::from(3) == res); - - value = UFP64::from_uint(1); - res = value.fract(); - assert(UFP64::from_uint(0) == res); - - // ceil - value = UFP64::from((1 << 32) + 3); - res = value.ceil(); - assert(UFP64::from_uint(2) == res); - - value = UFP64::from_uint(1); - res = value.ceil(); - assert(UFP64::from_uint(1) == res); - - // round - value = UFP64::from((1 << 32) + 3); - res = value.round(); - assert(UFP64::from_uint(1) == res); - - value = UFP64::from((1 << 32) + (1 << 31) + 1); - res = value.round(); - assert(UFP64::from_uint(2) == res); - - true -} diff --git a/tests/src/fixed_point/ufp64_test/tests/mod.rs b/tests/src/fixed_point/ufp64_test/tests/mod.rs deleted file mode 100644 index 570a535c..00000000 --- a/tests/src/fixed_point/ufp64_test/tests/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -use fuels::prelude::{abigen, launch_provider_and_get_wallet}; - -abigen!(Script( - name = "TestUfp64", - abi = "src/fixed_point/ufp64_test/out/release/ufp64_test-abi.json" -),); - -mod success { - - use super::*; - - #[tokio::test] - async fn runs_ufp64_test_script() { - let path_to_bin = "src/fixed_point/ufp64_test/out/release/ufp64_test.bin"; - - let wallet = launch_provider_and_get_wallet().await.unwrap(); - - let instance = TestUfp64::new(wallet, path_to_bin); - - let _result = instance.main().call().await; - } -} diff --git a/tests/src/harness.rs b/tests/src/harness.rs index 937a20a2..7ae34127 100644 --- a/tests/src/harness.rs +++ b/tests/src/harness.rs @@ -1,7 +1,6 @@ // Add test modules here: mod admin; mod bytecode; -mod fixed_point; mod merkle_proof; mod native_asset; mod ownership;