| ... | @@ -183,6 +183,32 @@ test "math" { | ... | @@ -183,6 +183,32 @@ test "math" { |
| 183 | _ = @import("big/index.zig"); | 183 | _ = @import("big/index.zig"); |
| 184 | } | 184 | } |
| 185 | | 185 | |
| | 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 | |
| 186 | pub fn min(x: var, y: var) @typeOf(x + y) { | 212 | pub fn min(x: var, y: var) @typeOf(x + y) { |
| 187 | return if (x < y) x else y; | 213 | return if (x < y) x else y; |
| 188 | } | 214 | } |
| ... | @@ -607,4 +633,3 @@ pub fn lossyCast(comptime T: type, value: var) T { | ... | @@ -607,4 +633,3 @@ pub fn lossyCast(comptime T: type, value: var) T { |
| 607 | else => @compileError("bad type"), | 633 | else => @compileError("bad type"), |
| 608 | } | 634 | } |
| 609 | } | 635 | } |
| 610 | | | |