Infinity: Difference between revisions

568 bytes removed ,  7 months ago
→‎{{header|Zig}}: Replace assertion with testing function, add missing types and checks (that were implemented since last change of Zig section), annotate versions.
(→‎{{header|Zig}}: Replace assertion with testing function, add missing types and checks (that were implemented since last change of Zig section), annotate versions.)
Line 1,650:
 
=={{header|Zig}}==
 
'''Works with:''' 0.12.0-dev.1502+b3462b7ce
 
<syntaxhighlight lang="zig">const std = @import("std");
 
const debug = std.debug;
const math = std.math;
 
test "infinity" {
const infinite_f16expect = mathstd.inf(f16)testing.expect;
const infinite_f32 = math.inf(f32);
const infinite_f64 = math.inf(f64);
const infinite_f128 = math.inf(f128);
 
const float_types = [_]type{ f16, f32, f64, f80, f128 };
// Any other types besides these four floating types are not implemented.
inline for (float_types) |T| {
const infinite_value: T = comptime std.math.inf(T);
 
debug.assert try expect(math.isInf(infinite_f16infinite_value));
debug.assert try expect(math.isInfisPositiveInf(infinite_f32infinite_value));
debug.assert try expect(!math.isInfisNegativeInf(infinite_f64infinite_value));
debug.assert try expect(!math.isInfisFinite(infinite_f128infinite_value));
}
 
debug.assert(math.isPositiveInf(infinite_f16));
debug.assert(math.isPositiveInf(infinite_f32));
debug.assert(math.isPositiveInf(infinite_f64));
debug.assert(math.isPositiveInf(infinite_f128));
 
debug.assert(math.isNegativeInf(-infinite_f16));
debug.assert(math.isNegativeInf(-infinite_f32));
debug.assert(math.isNegativeInf(-infinite_f64));
debug.assert(math.isNegativeInf(-infinite_f128));
 
debug.assert(!math.isFinite(infinite_f16));
debug.assert(!math.isFinite(infinite_f32));
debug.assert(!math.isFinite(infinite_f64));
// isFinite(f128) is not implemented.
//debug.assert(!math.isFinite(infinite_f128));
}</syntaxhighlight>
 
{{out}}
<pre>
$ zig test src/infinity_float.zig
All 1 tests passed.
</pre>
 
=={{header|zkl}}==
28

edits