| ... | ... | @@ -36,38 +36,44 @@ pub const sqrt2 = 1.414213562373095048801688724209698079; |
| 36 | 36 | /// 1/sqrt(2) |
| 37 | 37 | pub const sqrt1_2 = 0.707106781186547524400844362104849039; |
| 38 | 38 | |
| 39 | | pub const f128_true_min = @bitCast(f128, @as(u128, 0x00000000000000000000000000000001)); |
| 40 | | pub const f128_min = @bitCast(f128, @as(u128, 0x00010000000000000000000000000000)); |
| 41 | | pub const f128_max = @bitCast(f128, @as(u128, 0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF)); |
| 42 | | pub const f128_epsilon = @bitCast(f128, @as(u128, 0x3F8F0000000000000000000000000000)); |
| 43 | | pub const f128_toint = 1.0 / f128_epsilon; |
| 44 | | |
| 45 | | // float.h details |
| 46 | | pub const f80_true_min = make_f80(.{ .fraction = 1, .exp = 0 }); |
| 47 | | pub const f80_min = make_f80(.{ .fraction = 0x8000000000000000, .exp = 1 }); |
| 48 | | pub const f80_max = make_f80(.{ .fraction = 0xFFFFFFFFFFFFFFFF, .exp = 0x7FFE }); |
| 49 | | pub const f80_epsilon = make_f80(.{ .fraction = 0x8000000000000000, .exp = 0x3FC0 }); |
| 50 | | pub const f80_toint = 1.0 / f80_epsilon; |
| 51 | | |
| 52 | | pub const f64_true_min = 4.94065645841246544177e-324; |
| 53 | | pub const f64_min = 2.2250738585072014e-308; |
| 54 | | pub const f64_max = 1.79769313486231570815e+308; |
| 55 | | pub const f64_epsilon = 2.22044604925031308085e-16; |
| 56 | | pub const f64_toint = 1.0 / f64_epsilon; |
| 57 | | |
| 58 | | pub const f32_true_min = 1.40129846432481707092e-45; |
| 59 | | pub const f32_min = 1.17549435082228750797e-38; |
| 60 | | pub const f32_max = 3.40282346638528859812e+38; |
| 61 | | pub const f32_epsilon = 1.1920928955078125e-07; |
| 62 | | pub const f32_toint = 1.0 / f32_epsilon; |
| 63 | | |
| 64 | | pub const f16_true_min = 0.000000059604644775390625; // 2**-24 |
| 65 | | pub const f16_min = 0.00006103515625; // 2**-14 |
| 66 | | pub const f16_max = 65504; |
| 67 | | pub const f16_epsilon = 0.0009765625; // 2**-10 |
| 68 | | pub const f16_toint = 1.0 / f16_epsilon; |
| 69 | | |
| 70 | | pub const epsilon = @import("math/epsilon.zig").epsilon; |
| 39 | pub const floatExponentBits = @import("math/float.zig").floatExponentBits; |
| 40 | pub const floatMantissaBits = @import("math/float.zig").floatMantissaBits; |
| 41 | pub const floatMantissaDigits = @import("math/float.zig").floatMantissaDigits; |
| 42 | pub const floatExponentMin = @import("math/float.zig").floatExponentMin; |
| 43 | pub const floatExponentMax = @import("math/float.zig").floatExponentMax; |
| 44 | pub const floatTrueMin = @import("math/float.zig").floatTrueMin; |
| 45 | pub const floatMin = @import("math/float.zig").floatMin; |
| 46 | pub const floatMax = @import("math/float.zig").floatMax; |
| 47 | pub const floatEps = @import("math/float.zig").floatEps; |
| 48 | |
| 49 | // TODO Replace with @compileError("deprecated for foobar") after 0.10.0 is released. |
| 50 | pub const f16_true_min: comptime_float = floatTrueMin(f16); // prev: 0.000000059604644775390625 |
| 51 | pub const f32_true_min: comptime_float = floatTrueMin(f32); // prev: 1.40129846432481707092e-45 |
| 52 | pub const f64_true_min: comptime_float = floatTrueMin(f64); // prev: 4.94065645841246544177e-324 |
| 53 | pub const f80_true_min = floatTrueMin(f80); // prev: make_f80(.{ .fraction = 1, .exp = 0 }) |
| 54 | pub const f128_true_min = floatTrueMin(f128); // prev: @bitCast(f128, @as(u128, 0x00000000000000000000000000000001)) |
| 55 | pub const f16_min: comptime_float = floatMin(f16); // prev: 0.00006103515625 |
| 56 | pub const f32_min: comptime_float = floatMin(f32); // prev: 1.17549435082228750797e-38 |
| 57 | pub const f64_min: comptime_float = floatMin(f64); // prev: 2.2250738585072014e-308 |
| 58 | pub const f80_min = floatMin(f80); // prev: make_f80(.{ .fraction = 0x8000000000000000, .exp = 1 }) |
| 59 | pub const f128_min = floatMin(f128); // prev: @bitCast(f128, @as(u128, 0x00010000000000000000000000000000)) |
| 60 | pub const f16_max: comptime_float = floatMax(f16); // prev: 65504 |
| 61 | pub const f32_max: comptime_float = floatMax(f32); // prev: 3.40282346638528859812e+38 |
| 62 | pub const f64_max: comptime_float = floatMax(f64); // prev: 1.79769313486231570815e+308 |
| 63 | pub const f80_max = floatMax(f80); // prev: make_f80(.{ .fraction = 0xFFFFFFFFFFFFFFFF, .exp = 0x7FFE }) |
| 64 | pub const f128_max = floatMax(f128); // prev: @bitCast(f128, @as(u128, 0x7FFEFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) |
| 65 | pub const f16_epsilon: comptime_float = floatEps(f16); // prev: 0.0009765625 |
| 66 | pub const f32_epsilon: comptime_float = floatEps(f32); // prev: 1.1920928955078125e-07 |
| 67 | pub const f64_epsilon: comptime_float = floatEps(f64); // prev: 2.22044604925031308085e-16 |
| 68 | pub const f80_epsilon = floatEps(f80); // prev: make_f80(.{ .fraction = 0x8000000000000000, .exp = 0x3FC0 }) |
| 69 | pub const f128_epsilon = floatEps(f128); // prev: @bitCast(f128, @as(u128, 0x3F8F0000000000000000000000000000)) |
| 70 | pub const f16_toint: comptime_float = 1.0 / f16_epsilon; // same as before |
| 71 | pub const f32_toint: comptime_float = 1.0 / f32_epsilon; // same as before |
| 72 | pub const f64_toint: comptime_float = 1.0 / f64_epsilon; // same as before |
| 73 | pub const f80_toint = 1.0 / f80_epsilon; // same as before |
| 74 | pub const f128_toint = 1.0 / f128_epsilon; // same as before |
| 75 | pub const epsilon = floatEps; |
| 76 | // End of "soft deprecated" section |
| 71 | 77 | |
| 72 | 78 | pub const nan_u16 = @as(u16, 0x7C01); |
| 73 | 79 | pub const nan_f16 = @bitCast(f16, nan_u16); |
| ... | ... | @@ -294,36 +300,6 @@ test { |
| 294 | 300 | std.testing.refAllDecls(@This()); |
| 295 | 301 | } |
| 296 | 302 | |
| 297 | | /// Returns the number of bits in the mantissa of floating point type |
| 298 | | /// T. |
| 299 | | pub fn floatMantissaBits(comptime T: type) comptime_int { |
| 300 | | assert(@typeInfo(T) == .Float); |
| 301 | | |
| 302 | | return switch (@typeInfo(T).Float.bits) { |
| 303 | | 16 => 10, |
| 304 | | 32 => 23, |
| 305 | | 64 => 52, |
| 306 | | 80 => 64, |
| 307 | | 128 => 112, |
| 308 | | else => @compileError("unknown floating point type " ++ @typeName(T)), |
| 309 | | }; |
| 310 | | } |
| 311 | | |
| 312 | | /// Returns the number of bits in the exponent of floating point type |
| 313 | | /// T. |
| 314 | | pub fn floatExponentBits(comptime T: type) comptime_int { |
| 315 | | assert(@typeInfo(T) == .Float); |
| 316 | | |
| 317 | | return switch (@typeInfo(T).Float.bits) { |
| 318 | | 16 => 5, |
| 319 | | 32 => 8, |
| 320 | | 64 => 11, |
| 321 | | 80 => 15, |
| 322 | | 128 => 15, |
| 323 | | else => @compileError("unknown floating point type " ++ @typeName(T)), |
| 324 | | }; |
| 325 | | } |
| 326 | | |
| 327 | 303 | /// Given two types, returns the smallest one which is capable of holding the |
| 328 | 304 | /// full range of the minimum value. |
| 329 | 305 | pub fn Min(comptime A: type, comptime B: type) type { |