| ... | @@ -633,30 +633,6 @@ pub fn logl(x: c_longdouble) callconv(.c) c_longdouble { | ... | @@ -633,30 +633,6 @@ pub fn logl(x: c_longdouble) callconv(.c) c_longdouble { |
| 633 | } | 633 | } |
| 634 | } | 634 | } |
| 635 | | 635 | |
| 636 | /// Returns (f, k) such that x = f * 2^k and f in [1,2). | | |
| 637 | /// Asserts that x is finite and positive. | | |
| 638 | pub fn frexp2(x: f128) math.Frexp(f128) { | | |
| 639 | std.debug.assert(math.isFinite(x)); | | |
| 640 | std.debug.assert(x > 0.0); | | |
| 641 | | | |
| 642 | const bits: u128 = @bitCast(x); | | |
| 643 | const uexp: i32 = @intCast(bits >> 112); | | |
| 644 | | | |
| 645 | std.debug.assert(uexp >= 0); | | |
| 646 | | | |
| 647 | if (uexp == 0) { | | |
| 648 | const shift: u7 = @intCast(@clz(bits) - 15); | | |
| 649 | | | |
| 650 | const exp = -@as(i32, shift) - 0x3ffe; | | |
| 651 | const frac: f128 = @bitCast((bits << shift) | (0x3fff << 112)); | | |
| 652 | return .{ .significand = frac, .exponent = exp }; | | |
| 653 | } | | |
| 654 | | | |
| 655 | const exp = uexp - 0x3fff; | | |
| 656 | const frac: f128 = @bitCast((0x3fff << 112) | ((bits << 16) >> 16)); | | |
| 657 | return .{ .significand = frac, .exponent = exp }; | | |
| 658 | } | | |
| 659 | | | |
| 660 | test "logf() special" { | 636 | test "logf() special" { |
| 661 | try expectEqual(logf(0.0), -math.inf(f32)); | 637 | try expectEqual(logf(0.0), -math.inf(f32)); |
| 662 | try expectEqual(logf(-0.0), -math.inf(f32)); | 638 | try expectEqual(logf(-0.0), -math.inf(f32)); |