You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We need to add support for BigNumber representation in Oktopus to handle large numbers accurately and efficiently. Rust's standard numeric types (e.g., u64, i64, f64) have size limitations that can lead to overflows or precision loss when dealing with large numerical values. To ensure reliable handling of these numbers, especially for financial, cryptographic, or scientific calculations, we will implement custom BigNumber logic.
Motivation
Oktopus needs to handle extremely large numbers, which are currently beyond the capabilities of Rust's built-in data types.
To prevent data loss due to precision or overflow, we need a robust system to represent and manipulate these numbers.
Many operations such as cryptography, large financial transactions, and blockchain calculations require support for arbitrary precision.
Key Requirements
Arbitrary Precision: The BigNumber should support arbitrary-length integers and optionally arbitrary precision floating-point numbers (depending on future requirements).
Mathematical Operations: The BigNumber type should support all standard mathematical operations (+, -, *, /, %, etc.) and comparisons (<, >, ==, etc.).
Serialization/Deserialization: The BigNumber type must be serializable and deserializable to common formats like JSON and binary, to ensure seamless integration with the rest of the Oktopus project.
Performance: Since BigNumber operations can be computationally expensive, we should aim for a performant implementation, utilizing algorithms such as Karatsuba or FFT multiplication for large numbers.
Error Handling: Edge cases like division by zero, underflow, overflow, etc., must be handled appropriately with meaningful error messages.
Suggested Approach
Type Definition: Define a new BigNumber struct or enum that represents arbitrarily large numbers. We can initially leverage libraries like num-bigint for the core implementation, or write it from scratch if performance or customization is a priority.
Example:
structBigNumber{int:Vec<u32>,// Integer digits stored in a vector for arbitrary precisionfrac:Vec<u32>,// Fraction digits stored in a vector for arbitrary precisionsign:bool,// Sign of the number (true for positive, false for negative)
}
Mathematical Operations
Implement the Add, Sub, Mul, Div, and Rem traits for BigNumber. This will allow it to integrate seamlessly with Rust's arithmetic operators.
Implement Serialize and Deserialize traits from the serde library to enable easy (de)serialization of BigNumbers.
Testing and Benchmarks
Write comprehensive unit tests to validate the correctness of the implementation, especially edge cases such as handling negative numbers, division by zero, and overflow scenarios. Additionally, benchmark the performance of operations on very large numbers.
Tasks
Design BigNumber struct with appropriate internal representation.
Implement serialization and deserialization with serde.
Write unit tests for different operations and edge cases.
Benchmark performance and optimize for large number operations.
Update project documentation to include the new BigNumber type.
Additional Context
The BigNumber implementation should be flexible enough to accommodate future expansion for cryptographic purposes if needed. Existing libraries such as num-bigint can be referenced for inspiration, but we may need custom logic for more control or performance improvements.
If anyone has suggestions or would like to help, feel free to comment on this issue or submit a PR.
Feature Request: Implement BigNumber Representation Logic
Issue Overview
We need to add support for BigNumber representation in Oktopus to handle large numbers accurately and efficiently. Rust's standard numeric types (e.g.,
u64
,i64
,f64
) have size limitations that can lead to overflows or precision loss when dealing with large numerical values. To ensure reliable handling of these numbers, especially for financial, cryptographic, or scientific calculations, we will implement custom BigNumber logic.Motivation
Key Requirements
+
,-
,*
,/
,%
, etc.) and comparisons (<
,>
,==
, etc.).Suggested Approach
Type Definition: Define a new
BigNumber
struct or enum that represents arbitrarily large numbers. We can initially leverage libraries like num-bigint for the core implementation, or write it from scratch if performance or customization is a priority.Example:
}
Mathematical Operations
Implement the
Add
,Sub
,Mul
,Div
, andRem
traits forBigNumber
. This will allow it to integrate seamlessly with Rust's arithmetic operators.Example:
Serialization
Implement
Serialize
andDeserialize
traits from theserde
library to enable easy (de)serialization ofBigNumber
s.Testing and Benchmarks
Write comprehensive unit tests to validate the correctness of the implementation, especially edge cases such as handling negative numbers, division by zero, and overflow scenarios. Additionally, benchmark the performance of operations on very large numbers.
Tasks
BigNumber
struct with appropriate internal representation.Add
,Sub
,Mul
,Div
,Rem
).PartialEq
,PartialOrd
, etc.).serde
.BigNumber
type.Additional Context
The
BigNumber
implementation should be flexible enough to accommodate future expansion for cryptographic purposes if needed. Existing libraries such asnum-bigint
can be referenced for inspiration, but we may need custom logic for more control or performance improvements.If anyone has suggestions or would like to help, feel free to comment on this issue or submit a PR.
References
The text was updated successfully, but these errors were encountered: