@@ -115,19 +115,76 @@ impl From<DynInteger> for DynValue<'_> {
115115}
116116
117117#[ derive( Copy , Clone , PartialEq ) ]
118- pub enum DynScalar {
119- Integer ( DynInteger ) ,
118+ pub enum DynFloat {
119+ #[ cfg( feature = "f16" ) ]
120+ Float16 ( :: half:: f16 ) ,
120121 Float32 ( f32 ) ,
121122 Float64 ( f64 ) ,
123+ }
124+
125+ impl DynFloat {
126+ pub ( self ) fn read ( buf : & [ u8 ] , size : FloatSize ) -> Self {
127+ match size {
128+ #[ cfg( feature = "f16" ) ]
129+ FloatSize :: U2 => Self :: Float16 ( read_raw ( buf) ) ,
130+ FloatSize :: U4 => Self :: Float32 ( read_raw ( buf) ) ,
131+ FloatSize :: U8 => Self :: Float64 ( read_raw ( buf) ) ,
132+ }
133+ }
134+ }
135+
136+ unsafe impl DynClone for DynFloat {
137+ fn dyn_clone ( & mut self , out : & mut [ u8 ] ) {
138+ match self {
139+ #[ cfg( feature = "f16" ) ]
140+ Self :: Float16 ( x) => write_raw ( out, * x) ,
141+ Self :: Float32 ( x) => write_raw ( out, * x) ,
142+ Self :: Float64 ( x) => write_raw ( out, * x) ,
143+ }
144+ }
145+ }
146+
147+ impl Debug for DynFloat {
148+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
149+ match * self {
150+ #[ cfg( feature = "f16" ) ]
151+ Self :: Float16 ( x) => Debug :: fmt ( & x, f) ,
152+ Self :: Float32 ( x) => Debug :: fmt ( & x, f) ,
153+ Self :: Float64 ( x) => Debug :: fmt ( & x, f) ,
154+ }
155+ }
156+ }
157+
158+ impl Display for DynFloat {
159+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
160+ Debug :: fmt ( self , f)
161+ }
162+ }
163+
164+ impl From < DynFloat > for DynScalar {
165+ fn from ( value : DynFloat ) -> Self {
166+ Self :: Float ( value)
167+ }
168+ }
169+
170+ impl From < DynFloat > for DynValue < ' _ > {
171+ fn from ( value : DynFloat ) -> Self {
172+ DynScalar :: Float ( value) . into ( )
173+ }
174+ }
175+
176+ #[ derive( Copy , Clone , PartialEq ) ]
177+ pub enum DynScalar {
178+ Integer ( DynInteger ) ,
179+ Float ( DynFloat ) ,
122180 Boolean ( bool ) ,
123181}
124182
125183unsafe impl DynClone for DynScalar {
126184 fn dyn_clone ( & mut self , out : & mut [ u8 ] ) {
127185 match self {
128186 Self :: Integer ( x) => x. dyn_clone ( out) ,
129- Self :: Float32 ( x) => write_raw ( out, * x) ,
130- Self :: Float64 ( x) => write_raw ( out, * x) ,
187+ Self :: Float ( x) => x. dyn_clone ( out) ,
131188 Self :: Boolean ( x) => write_raw ( out, * x) ,
132189 }
133190 }
@@ -137,8 +194,7 @@ impl Debug for DynScalar {
137194 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
138195 match self {
139196 Self :: Integer ( x) => Debug :: fmt ( & x, f) ,
140- Self :: Float32 ( x) => Debug :: fmt ( & x, f) ,
141- Self :: Float64 ( x) => Debug :: fmt ( & x, f) ,
197+ Self :: Float ( x) => Debug :: fmt ( & x, f) ,
142198 Self :: Boolean ( x) => Debug :: fmt ( & x, f) ,
143199 }
144200 }
@@ -637,8 +693,7 @@ impl<'a> DynValue<'a> {
637693
638694 match tp {
639695 Integer ( size) | Unsigned ( size) => DynInteger :: read ( buf, true , * size) . into ( ) ,
640- Float ( FloatSize :: U4 ) => DynScalar :: Float32 ( read_raw ( buf) ) . into ( ) ,
641- Float ( FloatSize :: U8 ) => DynScalar :: Float64 ( read_raw ( buf) ) . into ( ) ,
696+ Float ( size) => DynFloat :: read ( buf, * size) . into ( ) ,
642697 Boolean => DynScalar :: Boolean ( read_raw ( buf) ) . into ( ) ,
643698 Enum ( ref tp) => DynEnum :: new ( tp, DynInteger :: read ( buf, tp. signed , tp. size ) ) . into ( ) ,
644699 Compound ( ref tp) => DynCompound :: new ( tp, buf) . into ( ) ,
0 commit comments