Skip to content

Commit 9e470b7

Browse files
authored
Merge pull request #123 from flyingrobots/echo/F32Scalar
Echo/f32 scalar Closes #114
2 parents bf6d289 + 59edc25 commit 9e470b7

File tree

6 files changed

+121
-1
lines changed

6 files changed

+121
-1
lines changed

crates/rmg-core/src/math/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::f32::consts::TAU;
88
mod mat4;
99
mod prng;
1010
mod quat;
11-
mod scalar;
11+
pub mod scalar;
1212
mod vec3;
1313

1414
#[doc(inline)]

crates/rmg-core/src/math/scalar.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,88 @@ pub trait Scalar:
8282
/// even) and ensure platform-stable results.
8383
fn to_f32(self) -> f32;
8484
}
85+
86+
/// Deterministic f32 value
87+
#[derive(Debug, Copy, Clone, PartialEq)]
88+
pub struct F32Scalar {
89+
/// The wrapped f32 value
90+
pub value: f32,
91+
}
92+
93+
impl F32Scalar {
94+
/// Nil value
95+
pub const ZERO: Self = Self::new(0.0);
96+
97+
/// Identity value
98+
pub const ONE: Self = Self::new(1.0);
99+
100+
/// Constructs a `F32Scalar` with the specified value `num`
101+
pub const fn new(num: f32) -> Self {
102+
Self { value: num }
103+
}
104+
}
105+
106+
impl Scalar for F32Scalar {
107+
fn zero() -> Self {
108+
Self::ZERO
109+
}
110+
111+
fn one() -> Self {
112+
Self::ONE
113+
}
114+
115+
fn sin(self) -> Self {
116+
Self::new(self.value.sin())
117+
}
118+
119+
fn cos(self) -> Self {
120+
Self::new(self.value.cos())
121+
}
122+
123+
fn sin_cos(self) -> (Self, Self) {
124+
(Self::new(self.value.sin()), Self::new(self.value.cos()))
125+
}
126+
127+
fn from_f32(value: f32) -> Self {
128+
Self::new(value)
129+
}
130+
131+
fn to_f32(self) -> f32 {
132+
self.value
133+
}
134+
}
135+
136+
impl Add for F32Scalar {
137+
type Output = Self;
138+
fn add(self, rhs: Self) -> Self {
139+
Self::new(self.value + rhs.value)
140+
}
141+
}
142+
143+
impl Sub for F32Scalar {
144+
type Output = Self;
145+
fn sub(self, rhs: Self) -> Self {
146+
Self::new(self.value - rhs.value)
147+
}
148+
}
149+
150+
impl Mul for F32Scalar {
151+
type Output = Self;
152+
fn mul(self, rhs: Self) -> Self {
153+
Self::new(self.value * rhs.value)
154+
}
155+
}
156+
157+
impl Div for F32Scalar {
158+
type Output = Self;
159+
fn div(self, rhs: Self) -> Self {
160+
Self::new(self.value / rhs.value)
161+
}
162+
}
163+
164+
impl Neg for F32Scalar {
165+
type Output = Self;
166+
fn neg(self) -> Self {
167+
Self::new(-self.value)
168+
}
169+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![allow(missing_docs)]
2+
use rmg_core::math::scalar::F32Scalar;
3+
use rmg_core::math::Scalar;
4+
5+
#[test]
6+
fn test_f32_basics() {
7+
// constants
8+
let zero = F32Scalar::ZERO;
9+
let one = F32Scalar::ONE;
10+
assert_eq!(zero.value, 0.0);
11+
assert_eq!(one.value, 1.0);
12+
13+
// basic math
14+
let a = F32Scalar::new(5.0);
15+
let b = F32Scalar::new(2.0);
16+
assert_eq!((a + b).value, 7.0);
17+
assert_eq!((a - b).value, 3.0);
18+
19+
assert_eq!((a * b).value, 10.0);
20+
assert_eq!((a / b).value, 2.5);
21+
22+
let angle = F32Scalar::new(std::f32::consts::PI);
23+
assert_eq!(angle.sin().value, angle.value.sin());
24+
assert_eq!(angle.cos().value, angle.value.cos());
25+
}

docs/decision-log.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
| Date | Context | Decision | Rationale | Consequence |
66
| ---- | ------- | -------- | --------- | ----------- |
7+
| 2025-11-29 | `F32Scalar` | Add `rmg-core::math::scalar::F32Scalar` type | Now we have it. |
78
| 2025-11-03 | Scalar foundation | Add `rmg-core::math::Scalar` trait (operator supertraits + sin/cos) | Arithmetic via `Add/Sub/Mul/Div/Neg` supertraits for ergonomic `+ - * /`; `sin/cos` methods declared; canonicalization/LUTs deferred | Unblocks F32Scalar and DFix64 implementations; math code can target a stable trait |
89
| 2025-10-23 | Repo reset | Adopt pnpm + TS skeleton | Monorepo scaffolding for Echo | Phase 0 tasks established |
910
| 2025-10-24 | Branch tree spec | Integrate roaring bitmaps and chunk epochs | Deterministic merges & diffs | Snapshot policy updated |

docs/echo-total.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ This is Codex’s working map for building Echo. Update it relentlessly—each s
260260

261261
## Today’s Intent
262262

263+
> 2025-11-29 – Finish off `F32Scalar` implementation
264+
265+
- Added `rmg-core::math::scalar::F32Scalar` type.
266+
263267
> 2025-11-03 — Issue #115: Scalar trait scaffold
264268
265269
- Added `rmg-core::math::scalar::Scalar` trait declaring deterministic scalar operations.
@@ -606,6 +610,7 @@ Remember: every entry here shrinks temporal drift between Codices. Leave breadcr
606610

607611
| Date | Context | Decision | Rationale | Consequence |
608612
| ---- | ------- | -------- | --------- | ----------- |
613+
| 2025-11-29 | `F32Scalar` | Add `rmg-core::math::scalar::F32Scalar` type | Now we have it. |
609614
| 2025-11-03 | Scalar foundation | Add `rmg-core::math::Scalar` trait (operator supertraits + sin/cos) | Arithmetic via `Add/Sub/Mul/Div/Neg` supertraits for ergonomic `+ - * /`; `sin/cos` methods declared; canonicalization/LUTs deferred | Unblocks F32Scalar and DFix64 implementations; math code can target a stable trait |
610615
| 2025-10-23 | Repo reset | Adopt pnpm + TS skeleton | Monorepo scaffolding for Echo | Phase 0 tasks established |
611616
| 2025-10-24 | Branch tree spec | Integrate roaring bitmaps and chunk epochs | Deterministic merges & diffs | Snapshot policy updated |

docs/execution-plan.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ This is Codex’s working map for building Echo. Update it relentlessly—each s
3333

3434
## Today’s Intent
3535

36+
> 2025-11-29 – Finish off `F32Scalar` implementation
37+
38+
- Added `rmg-core::math::scalar::F32Scalar` type.
39+
3640
> 2025-11-03 — Issue #115: Scalar trait scaffold
3741
3842
- Added `rmg-core::math::scalar::Scalar` trait declaring deterministic scalar operations.

0 commit comments

Comments
 (0)