Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Private Function

atanBinary16

Private Function
std.math.atan.atanBinary16
fn atanBinary16(x: f16) f16

Params

  • x: f16

File

math/atan.zig:45
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
fn atanBinary16(x: f16) f16 {
    const atanhi: []const f32 = &.{
        4.6364760399e-01, // atan(0.5)hi 0x3eed6338
        7.8539812565e-01, // atan(1.0)hi 0x3f490fda
        9.8279368877e-01, // atan(1.5)hi 0x3f7b985e
        1.5707962513e+00, // atan(inf)hi 0x3fc90fda
    };
    const aT: []const f32 = &.{
        0x1.fffcccp-1,
        -0x1.52e8ccp-2,
        0x1.522336p-3,
    };

    const hx: u16 = @bitCast(x);
    const ix = hx & 0x7fff;
    const sign = (hx >> 15) != 0;
    // if |x| >= 2^11
    if (ix >= 0x6800) {
        if (math.isNan(x)) {
            return x;
        }
        const z = atanhi[3] + 0x1p-120;
        return @floatCast(if (sign) -z else z);
    }
    const x_: f32, const id: ?usize = blk: {
        // |x| < 0.4375
        if (ix < 0x3700) {
            // |x| < 2^(-6)
            if (ix < 0x2400) {
                if (ix < 0x400) {
                    // raise underflow for subnormal x
                    mem.doNotOptimizeAway(x * x);
                }
                return x;
            }
            break :blk .{ @floatCast(x), null };
        } else {
            const x_: f32 = @floatCast(@abs(x));
            // |x| < 1.1875
            if (ix < 0x3cc0) {
                // 7/16 <= |x| < 11/16
                if (ix < 0x3980) {
                    break :blk .{ (2.0 * x_ - 1.0) / (2.0 + x_), 0 };
                }
                // 11/16 <= |x| < 19/16
                else {
                    break :blk .{ (x_ - 1.0) / (x_ + 1.0), 1 };
                }
            } else {
                // |x| < 2.4375
                if (ix < 0x40e0) {
                    break :blk .{ (x_ - 1.5) / (1.0 + 1.5 * x_), 2 };
                }
                // 2.4375 <= |x| < 2^11
                else {
                    break :blk .{ -1.0 / x_, 3 };
                }
            }
        }
    };
    // end of argument reduction
    const z = x_ * x_;
    const s = aT[0] + z * (aT[1] + z * aT[2]);
    if (id) |id_| {
        const z_ = atanhi[id_] + x_ * s;
        return @floatCast(if (sign) -z_ else z_);
    } else {
        return @floatCast(x_ * s);
    }
}