mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-04-30 03:50:39 +00:00
⬆️ version bump to v4.5
- Update obioptions.Version from "Release 4.4.29" to "/v/ Release v5" - Update version.txt from 4.29 → .30 (automated by Makefile)
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
## Uint128 Type in `obifp`: Semantic Overview
|
||||
|
||||
This Go package defines a custom 128-bit unsigned integer type (`Uint128`) composed of two `uint64` limbs (high and low). It provides comprehensive arithmetic, comparison, bitwise operations, and type conversions.
|
||||
|
||||
- **Basic Constructors**: `Zero()`, `MaxValue()` initialize the smallest/largest possible values.
|
||||
- **State Checks**: `IsZero()`, and equality/comparison methods (`Equals`, `Cmp`, `<`, `>`, etc.) enable conditional logic.
|
||||
- **Type Casting**: Safe conversions to/from smaller (`Uint64`, `uint64`) and larger (`Uint256`) integer types, with overflow warnings where applicable.
|
||||
- **Arithmetic**: Full support for addition (`Add`, `Add64`), subtraction (`Sub`), multiplication (`Mul`, `Mul64`) — with panic on overflow.
|
||||
- **Division & Modulo**: Integer division (`Div`, `Div64`) and remainder (`Mod`, `Mod64`), implemented via optimized quotient-remainder pairs (`QuoRem`, `QuoRem64`) using hardware-assisted 64-bit operations.
|
||||
- **Bit Manipulation**: Left/right shifts (`LeftShift`, `RightShift`), and bitwise logic: AND, OR, XOR, NOT.
|
||||
- **Utility**: Direct access to low limb via `AsUint64()`.
|
||||
|
||||
All operations preserve 128-bit precision, with strict overflow checking for correctness in high-precision contexts (e.g., bioinformatics counting).
|
||||
@@ -0,0 +1,17 @@
|
||||
# `obifp.Uint128` Package — Semantic Feature Overview
|
||||
|
||||
This Go package provides a 128-bit unsigned integer type (`Uint128`) with comprehensive arithmetic, comparison, and bitwise operations. Internally represented as two `uint64` limbs (`w1`: high, `w0`: low), it supports:
|
||||
|
||||
- **Arithmetic Operations**
|
||||
- `Add`, `Sub`, `Mul` (128×128), and `Mul64` (scalar multiplication)
|
||||
- Division: `Div`, `Mod`, and combined quotient/remainder via `QuoRem` (and their 64-bit variants)
|
||||
- **Comparison & Equality**
|
||||
- `Cmp`, `Equals`, `LessThan`/`GreaterThan`, and their inclusive variants (`≤`, `≥`)
|
||||
- Support for comparing against both `Uint128` and native `uint64` values
|
||||
- **Bitwise Operations**
|
||||
- Logical AND (`And`), OR (`Or`), XOR (`Xor`) between two `Uint128`s
|
||||
- Bitwise NOT (`Not`) — inverts all bits of the value
|
||||
- **Conversion & Utility**
|
||||
- `AsUint64()` safely truncates to lower 64 bits (assumes upper limb is zero)
|
||||
|
||||
All operations handle overflow/underflow correctly, including carry propagation in addition and borrow handling in subtraction. Tests cover edge cases: zero values, max `uint64` boundaries (e.g., wrapping in addition/subtraction), and large multiplications. Designed for cryptographic or high-precision numeric use where native integer types are insufficient.
|
||||
@@ -0,0 +1,30 @@
|
||||
# Uint256 Type and Operations — Semantic Overview
|
||||
|
||||
The `obifp` package provides a custom 256-bit unsigned integer type (`Uint256`) implemented in Go, composed of four 64-bit limbs (`w0` to `w3`). It supports arithmetic, comparison, bitwise operations, and safe casting with overflow detection.
|
||||
|
||||
- **Core Representation**: `Uint256` stores values as four 64-bit words, enabling arbitrary-precision unsigned integers up to $2^{256} - 1$.
|
||||
|
||||
- **Utility Methods**:
|
||||
- `Zero()` / `MaxValue()`: Return the neutral and maximum values.
|
||||
- `IsZero()`, `Equals(v)`, comparison methods (`LessThan`, etc.): Enable logical and ordering checks.
|
||||
|
||||
- **Casting & Conversion**:
|
||||
- `Uint64()`, `Uint128()` downcast with warnings on overflow.
|
||||
- `Set64(v)`: Initializes from a standard `uint64`.
|
||||
- `AsUint64()`: Direct access to least-significant limb.
|
||||
|
||||
- **Bitwise Operations**:
|
||||
- `And`, `Or`, `Xor`, `Not`: Standard bitwise logic per limb.
|
||||
|
||||
- **Shifts**:
|
||||
- `LeftShift(n)` / `RightShift(n)`: Multi-limb shifts with carry propagation.
|
||||
|
||||
- **Arithmetic**:
|
||||
- `Add(v)`, `Sub(v)` / `Mul(v)`: Use Go’s `math/bits` for carry-aware operations; panic on overflow.
|
||||
- `Div(v)`: Implements long division via repeated subtraction of shifted multiples; panics on zero divisor.
|
||||
|
||||
- **Safety & Logging**:
|
||||
- Warnings via `obilog.Warnf` for silent overflows during narrowing casts.
|
||||
- Panics on arithmetic overflow or division-by-zero using `log.Panicf`.
|
||||
|
||||
This type is suitable for cryptographic, genomic (OBITools), or high-precision counting use cases requiring precise control over large unsigned integers.
|
||||
@@ -0,0 +1,34 @@
|
||||
# Uint64 Type Functionalities Overview
|
||||
|
||||
The `obifp` package provides a custom `Uint64` type wrapping Go’s native 64-bit unsigned integer (`uint64`) to support arithmetic, bitwise operations, and type conversions in a structured way.
|
||||
|
||||
## Core Operations
|
||||
|
||||
- **`Zero()` / `MaxValue()`**: Returns the zero and maximum representable values, respectively.
|
||||
- **`IsZero()` / `Equals(v)`**: Checks if the value is zero or equal to another.
|
||||
- **`Cmp(v)`, `LessThan(v)`**, etc.: Standard comparison operations returning `-1/0/+1` or boolean results.
|
||||
|
||||
## Arithmetic with Overflow Detection
|
||||
|
||||
- **Add/Sub/Mul**: Performs 64-bit addition, subtraction, and multiplication.
|
||||
- Uses `math/bits` for low-level operations (`bits.Add64`, etc.).
|
||||
- Panics on overflow (carry ≠ 0), enforcing strict safety.
|
||||
|
||||
## Bitwise Operations
|
||||
|
||||
- **`And`, `Or`, `Xor`, `Not()`**: Standard bitwise logic operations.
|
||||
- **`LeftShift(n)` / `RightShift(n)`**:
|
||||
- Shifts bits left/right by *n* positions.
|
||||
- Uses internal `LeftShift64`/`RightShift64`, supporting *carry-in* for multi-word arithmetic.
|
||||
|
||||
## Extended Precision Conversions
|
||||
|
||||
- **`Uint128()` / `Uint256()`**: Casts the 64-bit value into larger unsigned integer types (zero-extended).
|
||||
- **`Set64(v)`**: Reassigns the internal value from a raw `uint64`.
|
||||
|
||||
## Utility & Logging
|
||||
|
||||
- **`AsUint64()`**: Extracts the underlying `uint64`.
|
||||
- **Warning on overflow in shift operations** (e.g., shifts ≥ 128 bits) via `obilog.Warnf`.
|
||||
|
||||
> Designed for use in high-precision or cryptographic contexts where explicit overflow handling and type safety are critical.
|
||||
@@ -0,0 +1,32 @@
|
||||
# Obifp Package: Generic Fixed-Point Unsigned Integer Operations
|
||||
|
||||
This Go package (`obifp`) provides a generic, type-safe interface for fixed-point unsigned integer arithmetic over three size variants: `Uint64`, `Uint128`, and `Uint256`.
|
||||
|
||||
## Core Interface: `FPUint[T]`
|
||||
|
||||
The interface defines a unified API for unsigned integer types, supporting:
|
||||
|
||||
- **Initialization & Conversion**:
|
||||
- `Zero()`, `Set64(v)`: Create zero or set from a `uint64`.
|
||||
- `AsUint64()`: Downcast to standard `uint64`.
|
||||
|
||||
- **Logical Operations**:
|
||||
- Bitwise: `And`, `Or`, `Xor`, `Not`.
|
||||
- Shifts: `LeftShift(n)`, `RightShift(n)`.
|
||||
|
||||
- **Arithmetic**:
|
||||
- Addition (`Add`), subtraction (`Sub`), multiplication (`Mul`). Division is commented out—likely reserved for future implementation.
|
||||
|
||||
- **Comparison**:
|
||||
- Full ordering: `<`, `<=`, `>`, `>=`.
|
||||
|
||||
- **Utility Predicates**:
|
||||
- `IsZero()` for zero-checking.
|
||||
|
||||
## Helper Functions
|
||||
|
||||
- `ZeroUint[T]`: Returns the neutral element (zero) for type `T`.
|
||||
- `OneUint[T]`: Constructs value 1 via `Set64(1)`.
|
||||
- `From64[T]`: Converts a standard Go `uint64` into the generic type.
|
||||
|
||||
All operations are **method-chaining friendly** (return `T`, not pointers), enabling fluent syntax. The design promotes correctness and performance in cryptographic or financial contexts where large, fixed-size integers are required.
|
||||
Reference in New Issue
Block a user