@@ -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+ }
0 commit comments