Infinity: Difference between revisions

590 bytes removed ,  2 months ago
m
 
(15 intermediate revisions by 8 users not shown)
Line 158:
 
=={{header|AWK}}==
 
<syntaxhighlight lang="awk"> BEGIN {
k=1;
Line 169 ⟶ 168:
<pre> inf </pre>
 
=={{header|BASIC256BASIC}}==
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">onerror TratoError
infinity = 1e300*1e300
Line 178:
return</syntaxhighlight>
 
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> *FLOAT 64
Line 204:
</pre>
 
==={{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 526 ⟶ 536:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Infinity}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
Fōrmulæ does not use floating point numbers, but arbitrary-size integers and arbitrary-precision decimal numbers.
In '''[https://formulae.org/?example=Infinity this]''' page you can see the program(s) related to this task and their results.
 
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 675 ⟶ 693:
The global isFinite() function tests for finiteness:
<syntaxhighlight lang="javascript">isFinite(x)</syntaxhighlight>
 
=={{header|Joy}}==
<syntaxhighlight lang="jqjoy">def1 isinfinite:1024 .ldexp ==dup infinite;neg stack.</syntaxhighlight>
{{out}}
<pre>[-inf inf]</pre>
 
=={{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>
 
<syntaxhighlight lang="jq">def infinite: 1e1000;</syntaxhighlight>
To test whether a jq value is equal to `infinite`, one can simply use `==` in the expected manner. Thus, assuming `infinite` has been defined, one could define a predicate, isinfinite, as follows:
 
<syntaxhighlight lang="jq">def isinfinite: . == infinite;</syntaxhighlight>
 
To test whether a jq value is equal to `infinite` or `- infinite`, one can use the built-in filter `isinfinite`. One can also use `==` in the expected manner.
Currently, the infinite value prints as though it were a very large floating point number.
 
=={{header|Julia}}==
Line 1,591 ⟶ 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,627 ⟶ 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