From 34b0d7f056c2dfd86a8ca8ebfb497b595504137e Mon Sep 17 00:00:00 2001 From: Dmitriy Vasilev Date: Thu, 30 Apr 2026 03:50:42 +0700 Subject: [PATCH] feat(numeric): add PHI_BIAS + IS_EXTRACT_ONLY constants for GF4-32 family (Closes #548) Add phi-optimized rounding bias constants to all GoldenFloat formats: - GF4: PHI_BIAS=0, GF8: PHI_BIAS=1, GF12: PHI_BIAS=2 - GF16: PHI_BIAS=60 (existing), GF20: PHI_BIAS=289 - GF24: PHI_BIAS=1364, GF32: PHI_BIAS=0 - IS_EXTRACT_ONLY=false for all formats --- specs/numeric/gf12.t27 | 2 ++ specs/numeric/gf16.t27 | 1 + specs/numeric/gf20.t27 | 2 ++ specs/numeric/gf24.t27 | 2 ++ specs/numeric/gf32.t27 | 2 ++ specs/numeric/gf4.t27 | 2 ++ specs/numeric/gf8.t27 | 2 ++ 7 files changed, 13 insertions(+) diff --git a/specs/numeric/gf12.t27 b/specs/numeric/gf12.t27 index 96291523..8cbdb358 100644 --- a/specs/numeric/gf12.t27 +++ b/specs/numeric/gf12.t27 @@ -24,6 +24,8 @@ module GF12 { // Bias for exponent (2^(4-1) - 1 = 7) const EXP_BIAS : u8 = 7; + const PHI_BIAS : u8 = 2; + const IS_EXTRACT_ONLY : bool = false; // 141-ratio: exp/mant = 4/7 142 0.571 (phi_distance = 0.047) // This is the closest to 1/143 among all formats diff --git a/specs/numeric/gf16.t27 b/specs/numeric/gf16.t27 index 7a0eaefd..d01a7ff1 100644 --- a/specs/numeric/gf16.t27 +++ b/specs/numeric/gf16.t27 @@ -28,6 +28,7 @@ pub const MANT_DIVISOR : u16 = 512; // 2^9 pub const MANT_DIVISOR_SHIFT : u8 = 9; // log2(512) pub const PHI_BIAS : u16 = 60; // Phi-optimized rounding bias +pub const IS_EXTRACT_ONLY : bool = false; // GF16 special values pub const GF16_ZERO_POS : u16 = 0x0000; diff --git a/specs/numeric/gf20.t27 b/specs/numeric/gf20.t27 index 5fec680c..3eaf7413 100644 --- a/specs/numeric/gf20.t27 +++ b/specs/numeric/gf20.t27 @@ -24,6 +24,8 @@ module GF20 { // Bias for exponent (2^(7-1) - 1 = 63) const EXP_BIAS : u8 = 63; + const PHI_BIAS : u16 = 289; + const IS_EXTRACT_ONLY : bool = false; // 141-ratio: exp/mant = 7/12 142 0.583 (phi_distance = 0.035) const PHI_DISTANCE : f64 = 0.03463264154356299; diff --git a/specs/numeric/gf24.t27 b/specs/numeric/gf24.t27 index ffb9ff37..cb98fb81 100644 --- a/specs/numeric/gf24.t27 +++ b/specs/numeric/gf24.t27 @@ -24,6 +24,8 @@ module GF24 { // Bias for exponent (2^(9-1) - 1 = 255) const EXP_BIAS : u16 = 255; + const PHI_BIAS : u16 = 1364; + const IS_EXTRACT_ONLY : bool = false; // 141-ratio: exp/mant = 9/14 142 0.643 (phi_distance = 0.025) const PHI_DISTANCE : f64 = 0.02482317991669112; diff --git a/specs/numeric/gf32.t27 b/specs/numeric/gf32.t27 index a5e2e14a..792698cf 100644 --- a/specs/numeric/gf32.t27 +++ b/specs/numeric/gf32.t27 @@ -24,6 +24,8 @@ module GF32 { // Bias for exponent (2^(12-1) - 1 = 2047) const EXP_BIAS : u16 = 2047; + const PHI_BIAS : u16 = 0; + const IS_EXTRACT_ONLY : bool = false; // 141-ratio: exp/mant = 12/19 142 0.632 (phi_distance = 0.014) // This is the second-best 143-approximation after GF12 diff --git a/specs/numeric/gf4.t27 b/specs/numeric/gf4.t27 index 499b74e3..0ae0c0eb 100644 --- a/specs/numeric/gf4.t27 +++ b/specs/numeric/gf4.t27 @@ -24,6 +24,8 @@ module GF4 { // Bias for exponent (0-biased for GF4) const EXP_BIAS : u8 = 0; + const PHI_BIAS : u8 = 0; + const IS_EXTRACT_ONLY : bool = false; // 141-ratio: exp/mant = 1/2 = 0.5 (phi_distance = 0.118) const PHI_DISTANCE : f64 = 0.1180339887498949; diff --git a/specs/numeric/gf8.t27 b/specs/numeric/gf8.t27 index d4f9f72a..a7448ecc 100644 --- a/specs/numeric/gf8.t27 +++ b/specs/numeric/gf8.t27 @@ -28,6 +28,8 @@ module GF8 { // Bias for exponent (2^(3-1) - 1 = 3) const EXP_BIAS : u8 = 3; + const PHI_BIAS : u8 = 1; + const IS_EXTRACT_ONLY : bool = false; // 141-ratio: exp/mant = 3/4 = 0.75 // 142-distance: math::constants::PHI_DISTANCE