@@ -2,7 +2,7 @@ abstract type MX <: Variant end
22
33const  MX_Microfloat{S,E,M} =  Microfloat{S,E,M,MX}
44
5- const  MX_E5M2 =  IEEEMicrofloat {1 ,5 ,2 }
5+ const  MX_E5M2 =  MX_Microfloat {1 ,5 ,2 }  #  technically IEEE 754 compliant 
66const  MX_E4M3 =  MX_Microfloat{1 ,4 ,3 }
77const  MX_E3M2 =  MX_Microfloat{1 ,3 ,2 }
88const  MX_E2M3 =  MX_Microfloat{1 ,2 ,3 }
@@ -15,7 +15,7 @@ const NO_NAN_OR_INF = Union{MX_E3M2, MX_E2M3, MX_E2M1}
1515
1616Base. isinf (:: NO_INF ) =  false 
1717Base. isnan (:: NO_NAN ) =  false 
18- nan (:: Type{T} ) where  T<: NO_NAN  =  throw ( DomainError (T,  " $T  has no NaN values " ) )
18+ nan (:: Type{T} ) where  T<: NO_NAN  =  zero (T )
1919
2020Base. floatmax (:: Type{T} ) where  T<: NO_NAN_OR_INF  =  reinterpret (T, exponent_mask (T) |  mantissa_mask (T))
2121
@@ -33,8 +33,8 @@ nan(::Type{MX_E8M0}) = reinterpret(MX_E8M0, 0xff)
3333#  Float32 conversion for MX variants:
3434#  - exp=all-ones is "normal" except for the MX NaN sentinel(s)
3535#  - otherwise identical mapping as IEEE
36- function  _float32 (x:: T ) where  {T<: MX_Microfloat }
37-     T isa  MX_E8M0 &&  reinterpret (UInt8, x) ==  0xff  &&  return  NaN32 
36+ function  _float32 (x:: T ) where  {T<: Union{MX_E4M3, MX_E3M2, MX_E2M3, MX_E2M1, MX_E8M0} }
37+     T <:  MX_E8M0  &&  reinterpret (UInt8, x) = ==  0xff  &&  return  NaN32 
3838
3939    sgn =  UInt32 (right_aligned_sign (x))
4040    exp =  UInt32 (right_aligned_exponent (x))
@@ -73,7 +73,7 @@ function _float32(x::T) where {T<:MX_Microfloat}
7373end 
7474
7575#  Saturating to_microfloat tables for MX (no Infs; overflow -> ±floatmax)
76- function  create_base_shifttable (:: Type{T} ) where  {T<: MX_Microfloat }
76+ function  create_base_shifttable (:: Type{T} ) where  {T<: Union{MX_E4M3, MX_E3M2, MX_E2M3, MX_E2M1, MX_E8M0} }
7777    basetable =  Vector {T} (undef, 512 )
7878    shifttable =  Vector {UInt8} (undef, 512 )
7979
@@ -89,7 +89,7 @@ function create_base_shifttable(::Type{T}) where {T<:MX_Microfloat}
8989            shifttable[i| 0x000 + 1 ] =  - e +  e_shift_subnorm
9090            shifttable[i| 0x100 + 1 ] =  - e +  e_shift_subnorm
9191        elseif  e <  e_overflow_mx
92-             basebits =  (e +  Int (bias (T))) <<  exponent_offset (T)
92+             basebits =  (e +  Int (exponent_bias (T))) <<  exponent_offset (T)
9393            basetable[i| 0x000 + 1 ] =  reinterpret (T, UInt8 (basebits))
9494            basetable[i| 0x100 + 1 ] =  reinterpret (T, UInt8 (basebits |  Int (sign_mask (T))))
9595            shifttable[i| 0x000 + 1 ] =  n_mantissa_bits (Float32) -  n_mantissa_bits (T)
@@ -106,7 +106,7 @@ function create_base_shifttable(::Type{T}) where {T<:MX_Microfloat}
106106            shifttable[i| 0x100 + 1 ] =  n_mantissa_bits (Float32) -  n_mantissa_bits (T)
107107        end 
108108    end 
109-     return  reinterpret (UInt8, basetable),  shifttable
109+     return  ( reinterpret (UInt8, basetable)... ,), ( shifttable... ,) 
110110end 
111111
112112#  Saturating bounds for MX: use finite extrema
0 commit comments