File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Top Open diff view settings Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Top Open diff view settings Original file line number Diff line number Diff line change @@ -183,6 +183,32 @@ test "math" {
183183 _ = @import ("big/index.zig" );
184184}
185185
186+ pub fn floatMantissaBits (comptime T : type ) comptime_int {
187+ assert (@typeId (T ) == builtin .TypeId .Float );
188+
189+ return switch (T .bit_count ) {
190+ 16 = > 10 ,
191+ 32 = > 23 ,
192+ 64 = > 52 ,
193+ 80 = > 64 ,
194+ 128 = > 112 ,
195+ else = > @compileError ("unknown floating point type " ++ @typeName (T )),
196+ };
197+ }
198+
199+ pub fn floatExponentBits (comptime T : type ) comptime_int {
200+ assert (@typeId (T ) == builtin .TypeId .Float );
201+
202+ return switch (T .bit_count ) {
203+ 16 = > 5 ,
204+ 32 = > 8 ,
205+ 64 = > 11 ,
206+ 80 = > 15 ,
207+ 128 = > 15 ,
208+ else = > @compileError ("unknown floating point type " ++ @typeName (T )),
209+ };
210+ }
211+
186212pub fn min (x : var , y : var ) @typeOf (x + y ) {
187213 return if (x < y ) x else y ;
188214}
@@ -607,4 +633,3 @@ pub fn lossyCast(comptime T: type, value: var) T {
607633 else = > @compileError ("bad type" ),
608634 }
609635}
610-
You can’t perform that action at this time.
0 commit comments