Infinity: Difference between revisions

Content added Content deleted
(→‎{{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: Line 1,650:


=={{header|Zig}}==
=={{header|Zig}}==

'''Works with:''' 0.12.0-dev.1502+b3462b7ce

<syntaxhighlight lang="zig">const std = @import("std");
<syntaxhighlight lang="zig">const std = @import("std");


const debug = std.debug;
const math = std.math;
const math = std.math;


test "infinity" {
test "infinity" {
const infinite_f16 = math.inf(f16);
const expect = std.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(math.isInf(infinite_f16));
try expect(math.isInf(infinite_value));
debug.assert(math.isInf(infinite_f32));
try expect(math.isPositiveInf(infinite_value));
debug.assert(math.isInf(infinite_f64));
try expect(!math.isNegativeInf(infinite_value));
debug.assert(math.isInf(infinite_f128));
try expect(!math.isFinite(infinite_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>
}</syntaxhighlight>

{{out}}
<pre>
$ zig test src/infinity_float.zig
All 1 tests passed.
</pre>


=={{header|zkl}}==
=={{header|zkl}}==