Infinity: Difference between revisions

m
 
(12 intermediate revisions by 6 users not shown)
Line 205:
 
==={{header|bootBASIC}}===
There are no floating point numbers in bootBASIC. All numbers and variables are 2 byte unsigned integers.
 
The code below can't print anything on the screen, plus the program won't end. No way is currently known to break out of the program.
<syntaxhighlight lang="bootbasicBASIC">10 print 1/0</syntaxhighlight>
 
=={{header|BQN}}==
Line 376 ⟶ 378:
return Infinity # predefined variable holding positive infinity
}</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight>
print number "inf"
# or
print 1 / 0
 
</syntaxhighlight>
 
=={{header|Eiffel}}==
Line 527 ⟶ 537:
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Infinity}}
 
'''Solution'''
 
Fōrmulæ does not use floating point numbers, but arbitrary-size integers and arbitrary-precision decimal numbers.
 
Infinity is a predefined expression in Fōrmulæ.
 
Reduction of certain expressions can produce it:
 
[[File:Fōrmulæ - Infinity 01.png]]
 
[[File:Fōrmulæ - Infinity 02.png]]
 
=={{header|GAP}}==
Line 678 ⟶ 700:
 
=={{header|jq}}==
Sufficiently recent versions of the C, Go and Rust implementations of jq (jq, gojq, and jaq, respectively) all allow `infinite` as a scalar value in jq programs; jq and gojq display its value as 1.7976931348623157e+308. The C implementation also allows the token `inf` when reading JSON, and stores it as `infinite`.
jq uses IEEE 754 64-bit floating-point arithmetic, and very large number literals, e.g. 1e1000, are evaluated as IEEE 754 infinity. If your version of jq does not include `infinite` as a built-in, you could therefore define it as follows:
 
The C implementation of jq uses IEEE 754 64-bit floating-point arithmetic, and very large real number literals, e.g. 1e1000, are evaluated as IEEE 754 infinity., so Ifif your version of jq does not include `infinite` as a built-in, you could therefore define it as follows:
 
<syntaxhighlight lang="jq">def infinite: 1e1000;</syntaxhighlight>
 
To test whether a jq value is equal to `infinite` or `- infinite`, one can simply use `==`the built-in the expected manner. Thus, assumingfilter `infiniteisinfinite`. has beenOne defined,can onealso coulduse define`==` ain predicate,the isinfinite,expected as follows:manner.
 
<syntaxhighlight lang="jq">def isinfinite: . == infinite;</syntaxhighlight>
 
Currently, the infinite value prints as though it were a very large floating point number.
 
=={{header|Julia}}==
Line 1,592 ⟶ 1,612:
=={{header|Wren}}==
Wren certainly supports infinity for floating point numbers as we already have a method ''Num.isInfinity'' to test for it.
<syntaxhighlight lang="ecmascriptwren">var x = 1.5
var y = x / 0
System.print("x = %(x)")
Line 1,628 ⟶ 1,648:
 
=={{header|Zig}}==
 
'''Works with:''' 0.10.x, 0.11.x, 0.12.0-dev.1577+9ad03b628
 
Assumes that defaul float optimization mode was not changed via @setFloatMode (performed in Strict mode, not Optimized, latter is equivalent to -ffast-math).
 
<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, c_longdouble };
// 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}}==
2,120

edits