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 Type Function

Self

Private Type Function
std.fmt.parse_float.common.BiasedFp.Self
pub fn BiasedFp(comptime T: type) type

A custom N-bit floating point type, representing f * 2^e. e is biased, so it be directly shifted into the exponent bits. Negative exponent indicates an invalid result.

Fields

f: MantissaT

The significant digits.

e: i32

The biased, binary exponent.

File

fmt/parse_float/common.zig:6
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
pub fn BiasedFp(comptime T: type) type {
    const MantissaT = mantissaType(T);

    return struct {
        const Self = @This();

        /// The significant digits.
        f: MantissaT,
        /// The biased, binary exponent.
        e: i32,

        pub fn zero() Self {
            return .{ .f = 0, .e = 0 };
        }

        pub fn zeroPow2(e: i32) Self {
            return .{ .f = 0, .e = e };
        }

        pub fn inf(comptime FloatT: type) Self {
            const e = (1 << std.math.floatExponentBits(FloatT)) - 1;
            return switch (FloatT) {
                f80 => .{ .f = 0x8000000000000000, .e = e },
                else => .{ .f = 0, .e = e },
            };
        }

        pub fn eql(self: Self, other: Self) bool {
            return self.f == other.f and self.e == other.e;
        }

        pub fn toFloat(self: Self, comptime FloatT: type, negative: bool) FloatT {
            var word = self.f;
            word |= @as(MantissaT, @intCast(self.e)) << std.math.floatMantissaBits(FloatT);
            var f = floatFromUnsigned(FloatT, MantissaT, word);
            if (negative) f = -f;
            return f;
        }
    };
}