Zig 0.17.0-dev (Split by item) 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.
std › math › frexp › FrexpTests Private Type Function FrexpTests Doc Source Private Type Function std.math.frexp.FrexpTests
fn FrexpTests (comptime Float : type ) type Values File math/frexp.zig: 89
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155 fn FrexpTests (comptime Float : type ) type {
return struct {
const T = Float ;
test "normal" {
const epsilon = 1e-6 ;
var r : Frexp (T ) = undefined ;
r = frexp (@as (T , 1.3 ));
try expectApproxEqAbs (0.65 , r .significand , epsilon );
try expectEqual (1 , r .exponent );
r = frexp (@as (T , 78.0234 ));
try expectApproxEqAbs (0.609558 , r .significand , epsilon );
try expectEqual (7 , r .exponent );
r = frexp (@as (T , -1234.5678 ));
try expectEqual (11 , r .exponent );
try expectApproxEqAbs (-0.602816 , r .significand , epsilon );
}
test "max" {
const exponent = math .floatExponentMax (T ) + 1 ;
const significand = 1.0 - math .floatEps (T ) / 2 ;
const r : Frexp (T ) = frexp (math .floatMax (T ));
try expectEqual (exponent , r .exponent );
try expectEqual (significand , r .significand );
}
test "min" {
const exponent = math .floatExponentMin (T ) + 1 ;
const r : Frexp (T ) = frexp (math .floatMin (T ));
try expectEqual (exponent , r .exponent );
try expectEqual (0.5 , r .significand );
}
test "subnormal" {
const normal_min_exponent = math .floatExponentMin (T ) + 1 ;
const exponent = normal_min_exponent - math .floatFractionalBits (T );
const r : Frexp (T ) = frexp (math .floatTrueMin (T ));
try expectEqual (exponent , r .exponent );
try expectEqual (0.5 , r .significand );
}
test "zero" {
var r : Frexp (T ) = undefined ;
r = frexp (@as (T , 0.0 ));
try expectEqual (0 , r .exponent );
try expect (math .isPositiveZero (r .significand ));
r = frexp (@as (T , -0.0 ));
try expectEqual (0 , r .exponent );
try expect (math .isNegativeZero (r .significand ));
}
test "inf" {
var r : Frexp (T ) = undefined ;
r = frexp (math .inf (T ));
try expectEqual (0 , r .exponent );
try expect (math .isPositiveInf (r .significand ));
r = frexp (-math .inf (T ));
try expectEqual (0 , r .exponent );
try expect (math .isNegativeInf (r .significand ));
}
test "nan" {
const r : Frexp (T ) = frexp (math .nan (T ));
try expect (math .isNan (r .significand ));
}
};
}
Generate a namespace of tests for frexp on values of the given type