Infinity: Difference between revisions

Content added Content deleted
mNo edit summary
m (syntax highlighting fixup automation)
Line 13: Line 13:


=={{header|11l}}==
=={{header|11l}}==
<lang 11l>print(Float.infinity)</lang>
<syntaxhighlight lang="11l">print(Float.infinity)</syntaxhighlight>


{{out}}
{{out}}
Line 22: Line 22:
=={{header|ActionScript}}==
=={{header|ActionScript}}==
ActionScript has the built in function isFinite() to test if a number is finite or not.
ActionScript has the built in function isFinite() to test if a number is finite or not.
<lang actionscript>trace(5 / 0); // outputs "Infinity"
<syntaxhighlight lang="actionscript">trace(5 / 0); // outputs "Infinity"
trace(isFinite(5 / 0)); // outputs "false"</lang>
trace(isFinite(5 / 0)); // outputs "false"</syntaxhighlight>


=={{header|Ada}}==
=={{header|Ada}}==
<lang ada>with Ada.Text_IO; use Ada.Text_IO;
<syntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;


procedure Infinities is
procedure Infinities is
Line 49: Line 49:
Put_Line ("Supremum" & Float'Image (Sup));
Put_Line ("Supremum" & Float'Image (Sup));
Put_Line ("Infimum " & Float'Image (Inf));
Put_Line ("Infimum " & Float'Image (Inf));
end Infinities;</lang>
end Infinities;</syntaxhighlight>
The language-defined attribute Machine_Overflows is defined for each floating-point type. It is true when an overflow or divide-by-zero results in Constraint_Error exception propagation. When the underlying machine type is incapable to implement this semantics the attribute is false. It is to expect that on the machines with [[IEEE]] 754 hardware Machine_Overflows is true. The language-defined attributes Succ and Pred yield the value next or previous to the argument, correspondingly.
The language-defined attribute Machine_Overflows is defined for each floating-point type. It is true when an overflow or divide-by-zero results in Constraint_Error exception propagation. When the underlying machine type is incapable to implement this semantics the attribute is false. It is to expect that on the machines with [[IEEE]] 754 hardware Machine_Overflows is true. The language-defined attributes Succ and Pred yield the value next or previous to the argument, correspondingly.


Line 60: Line 60:


Here is the code that should work for any type on any machine:
Here is the code that should work for any type on any machine:
<lang ada>with Ada.Text_IO; use Ada.Text_IO;
<syntaxhighlight lang="ada">with Ada.Text_IO; use Ada.Text_IO;


procedure Infinities is
procedure Infinities is
Line 85: Line 85:
Put_Line ("Supremum" & Real'Image (Sup));
Put_Line ("Supremum" & Real'Image (Sup));
Put_Line ("Infimum " & Real'Image (Inf));
Put_Line ("Infimum " & Real'Image (Inf));
end Infinities;</lang>
end Infinities;</syntaxhighlight>
Sample output. Note that the compiler is required to generate Constraint_Error even if the hardware is [[IEEE]] 754. So the upper and lower bounds are 10.0 and -10.0:
Sample output. Note that the compiler is required to generate Constraint_Error even if the hardware is [[IEEE]] 754. So the upper and lower bounds are 10.0 and -10.0:
<pre>
<pre>
Line 93: Line 93:
===Getting rid of IEEE ideals===
===Getting rid of IEEE ideals===
There is a simple way to strip [[IEEE]] 754 ideals (non-numeric values) from a predefined floating-point type such as Float or Long_Float:
There is a simple way to strip [[IEEE]] 754 ideals (non-numeric values) from a predefined floating-point type such as Float or Long_Float:
<lang ada>subtype Safe_Float is Float range Float'Range;</lang>
<syntaxhighlight lang="ada">subtype Safe_Float is Float range Float'Range;</syntaxhighlight>
The subtype Safe_Float keeps all the range of Float, yet behaves properly upon overflow, underflow and zero-divide.
The subtype Safe_Float keeps all the range of Float, yet behaves properly upon overflow, underflow and zero-divide.


Line 107: Line 107:
ALGOL 68 does have some 7 built in [[Exceptions#ALGOL_68|exceptions]], these might be used to detect exceptions during transput, and so <u>if</u> the underlying hardware <u>does</u> support &infin;, then it would be detected with a ''on value error'' while printing and if ''mended'' would appear as a field full of ''error char''.
ALGOL 68 does have some 7 built in [[Exceptions#ALGOL_68|exceptions]], these might be used to detect exceptions during transput, and so <u>if</u> the underlying hardware <u>does</u> support &infin;, then it would be detected with a ''on value error'' while printing and if ''mended'' would appear as a field full of ''error char''.


<lang algol68>printf(($"max int: "gl$,max int));
<syntaxhighlight lang="algol68">printf(($"max int: "gl$,max int));
printf(($"long max int: "gl$,long max int));
printf(($"long max int: "gl$,long max int));
printf(($"long long max int: "gl$,long long max int));
printf(($"long long max int: "gl$,long long max int));
Line 113: Line 113:
printf(($"long max real: "gl$,long max real));
printf(($"long max real: "gl$,long max real));
printf(($"long long max real: "gl$,long long max real));
printf(($"long long max real: "gl$,long long max real));
printf(($"error char: "gl$,error char))</lang>
printf(($"error char: "gl$,error char))</syntaxhighlight>
Output:
Output:
<pre>
<pre>
Line 132: Line 132:
that support infinity, this will be infinity. Otherwise, it will be some large, but finite value.
that support infinity, this will be infinity. Otherwise, it will be some large, but finite value.


<lang apl>inf ← {⌊/⍬}</lang>
<syntaxhighlight lang="apl">inf ← {⌊/⍬}</syntaxhighlight>
{{out}}
{{out}}


Line 143: Line 143:
=={{header|Argile}}==
=={{header|Argile}}==
{{trans|C}} (simplified)
{{trans|C}} (simplified)
<lang Argile>use std
<syntaxhighlight lang="argile">use std
printf "%f\n" atof "infinity" (: this prints "inf" :)
printf "%f\n" atof "infinity" (: this prints "inf" :)
#extern :atof<text>: -> real</lang>
#extern :atof<text>: -> real</syntaxhighlight>


=={{header|Arturo}}==
=={{header|Arturo}}==


<lang rebol>print infinity
<syntaxhighlight lang="rebol">print infinity
print neg infinity</lang>
print neg infinity</syntaxhighlight>


{{out}}
{{out}}
Line 159: Line 159:
=={{header|AWK}}==
=={{header|AWK}}==


<lang AWK> BEGIN {
<syntaxhighlight lang="awk"> BEGIN {
k=1;
k=1;
while (2^(k-1) < 2^k) k++;
while (2^(k-1) < 2^k) k++;
INF = 2^k;
INF = 2^k;
print INF;
print INF;
}</lang>
}</syntaxhighlight>


This has been tested with GAWK 3.1.7 and MAWK, both return
This has been tested with GAWK 3.1.7 and MAWK, both return
Line 170: Line 170:


=={{header|BASIC256}}==
=={{header|BASIC256}}==
<lang BASIC256>onerror TratoError
<syntaxhighlight lang="basic256">onerror TratoError
infinity = 1e300*1e300
infinity = 1e300*1e300
end
end
Line 176: Line 176:
TratoError:
TratoError:
if lasterror = 29 then print lasterrormessage
if lasterror = 29 then print lasterrormessage
return</lang>
return</syntaxhighlight>


=={{header|BBC BASIC}}==
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
<lang bbcbasic> *FLOAT 64
<syntaxhighlight lang="bbcbasic"> *FLOAT 64
PRINT FNinfinity
PRINT FNinfinity
END
END
Line 198: Line 198:
RESTORE ERROR
RESTORE ERROR
UNTIL maxpos = prev
UNTIL maxpos = prev
= maxpos</lang>
= maxpos</syntaxhighlight>
Output:
Output:
<pre>
<pre>
Line 206: Line 206:
=={{header|bootBASIC}}==
=={{header|bootBASIC}}==
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.
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.
<lang bootBASIC>10 print 1/0</lang>
<syntaxhighlight lang="bootbasic">10 print 1/0</syntaxhighlight>


=={{header|BQN}}==
=={{header|BQN}}==
Line 228: Line 228:
C89 has a macro HUGE_VAL in <math.h>. HUGE_VAL is a <tt>double</tt>. HUGE_VAL will be infinity if infinity exists, else it will be the largest possible number. HUGE_VAL is a <tt>double</tt>.
C89 has a macro HUGE_VAL in <math.h>. HUGE_VAL is a <tt>double</tt>. HUGE_VAL will be infinity if infinity exists, else it will be the largest possible number. HUGE_VAL is a <tt>double</tt>.


<lang c>#include <math.h> /* HUGE_VAL */
<syntaxhighlight lang="c">#include <math.h> /* HUGE_VAL */
#include <stdio.h> /* printf() */
#include <stdio.h> /* printf() */


Line 238: Line 238:
printf("%g\n", inf());
printf("%g\n", inf());
return 0;
return 0;
}</lang>
}</syntaxhighlight>


The output from the above program might be "inf", "1.#INF", or something else.
The output from the above program might be "inf", "1.#INF", or something else.
Line 244: Line 244:
C99 also has a macro for infinity:
C99 also has a macro for infinity:


<lang c>#define _ISOC99_SOURCE
<syntaxhighlight lang="c">#define _ISOC99_SOURCE


#include <math.h>
#include <math.h>
Line 252: Line 252:
printf("%g\n", INFINITY);
printf("%g\n", INFINITY);
return 0;
return 0;
}</lang>
}</syntaxhighlight>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
<lang csharp>using System;
<syntaxhighlight lang="csharp">using System;


class Program
class Program
Line 268: Line 268:
Console.WriteLine(PositiveInfinity());
Console.WriteLine(PositiveInfinity());
}
}
}</lang>
}</syntaxhighlight>
Output:
Output:
<lang>Infinity</lang>
<syntaxhighlight lang="text">Infinity</syntaxhighlight>


=={{header|C++}}==
=={{header|C++}}==


<lang cpp>#include <limits>
<syntaxhighlight lang="cpp">#include <limits>


double inf()
double inf()
Line 282: Line 282:
else
else
return std::numeric_limits<double>::max();
return std::numeric_limits<double>::max();
}</lang>
}</syntaxhighlight>


=={{header|Clojure}}==
=={{header|Clojure}}==
{{trans|Java}}
{{trans|Java}}
Java's floating-point types (float, double) all support infinity. Clojure has literals for infinity:
Java's floating-point types (float, double) all support infinity. Clojure has literals for infinity:
<lang clojure>##Inf ;; same as Double/POSITIVE_INFINITY
<syntaxhighlight lang="clojure">##Inf ;; same as Double/POSITIVE_INFINITY
##-Inf ;; same as Double/NEGATIVE_INFINITY
##-Inf ;; same as Double/NEGATIVE_INFINITY
(Double/isInfinite ##Inf) ;; true</lang>
(Double/isInfinite ##Inf) ;; true</syntaxhighlight>


The largest possible number in Java (without using the Big classes) is also in the Double class
The largest possible number in Java (without using the Big classes) is also in the Double class
Line 299: Line 299:


JavaScript has a special global property called "Infinity":
JavaScript has a special global property called "Infinity":
<lang coffeescript>Infinity</lang>
<syntaxhighlight lang="coffeescript">Infinity</syntaxhighlight>
as well as constants in the Number class:
as well as constants in the Number class:
<lang coffeescript>Number.POSITIVE_INFINITY
<syntaxhighlight lang="coffeescript">Number.POSITIVE_INFINITY
Number.NEGATIVE_INFINITY</lang>
Number.NEGATIVE_INFINITY</syntaxhighlight>


The global isFinite function tests for finiteness:
The global isFinite function tests for finiteness:
<lang coffeescript>isFinite x</lang>
<syntaxhighlight lang="coffeescript">isFinite x</syntaxhighlight>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
Line 313: Line 313:
{{works with|LispWorks}} 5.1.2, Intel, OS X, 32-bit
{{works with|LispWorks}} 5.1.2, Intel, OS X, 32-bit


<lang lisp>> (apropos "MOST-POSITIVE" :cl)
<syntaxhighlight lang="lisp">> (apropos "MOST-POSITIVE" :cl)
MOST-POSITIVE-LONG-FLOAT, value: 1.7976931348623158D308
MOST-POSITIVE-LONG-FLOAT, value: 1.7976931348623158D308
MOST-POSITIVE-SHORT-FLOAT, value: 3.4028172S38
MOST-POSITIVE-SHORT-FLOAT, value: 3.4028172S38
Line 325: Line 325:
MOST-NEGATIVE-SHORT-FLOAT, value: -3.4028172S38
MOST-NEGATIVE-SHORT-FLOAT, value: -3.4028172S38
MOST-NEGATIVE-DOUBLE-FLOAT, value: -1.7976931348623158D308
MOST-NEGATIVE-DOUBLE-FLOAT, value: -1.7976931348623158D308
MOST-NEGATIVE-FIXNUM, value: -536870912</lang>
MOST-NEGATIVE-FIXNUM, value: -536870912</syntaxhighlight>


=={{header|Component Pascal}}==
=={{header|Component Pascal}}==
BlackBox Component Builder
BlackBox Component Builder
<lang oberon2>
<syntaxhighlight lang="oberon2">
MODULE Infinity;
MODULE Infinity;
IMPORT StdLog;
IMPORT StdLog;
Line 341: Line 341:
END Do;
END Do;


</syntaxhighlight>
</lang>
Execute: ^Q Infinity.Do<br/>
Execute: ^Q Infinity.Do<br/>
Output:
Output:
Line 350: Line 350:
=={{header|D}}==
=={{header|D}}==


<lang d>auto inf() {
<syntaxhighlight lang="d">auto inf() {
return typeof(1.5).infinity;
return typeof(1.5).infinity;
}
}


void main() {}</lang>
void main() {}</syntaxhighlight>


=={{header|Delphi}}==
=={{header|Delphi}}==


Delphi defines the following constants in Math:
Delphi defines the following constants in Math:
<lang Delphi> Infinity = 1.0 / 0.0;
<syntaxhighlight lang="delphi"> Infinity = 1.0 / 0.0;
NegInfinity = -1.0 / 0.0;</lang>
NegInfinity = -1.0 / 0.0;</syntaxhighlight>
Test for infinite value using:
Test for infinite value using:
<lang Delphi>Math.IsInfinite()</lang>
<syntaxhighlight lang="delphi">Math.IsInfinite()</syntaxhighlight>


=={{header|Dyalect}}==
=={{header|Dyalect}}==
Line 369: Line 369:
Dyalect floating point number support positive infinity:
Dyalect floating point number support positive infinity:


<lang Dyalect>func infinityTask() => Float.Infinity</lang>
<syntaxhighlight lang="dyalect">func infinityTask() => Float.Infinity</syntaxhighlight>


=={{header|E}}==
=={{header|E}}==


<lang e>def infinityTask() {
<syntaxhighlight lang="e">def infinityTask() {
return Infinity # predefined variable holding positive infinity
return Infinity # predefined variable holding positive infinity
}</lang>
}</syntaxhighlight>


=={{header|Eiffel}}==
=={{header|Eiffel}}==
<lang eiffel>
<syntaxhighlight lang="eiffel">
class
class
APPLICATION
APPLICATION
Line 397: Line 397:
end
end
end
end
</syntaxhighlight>
</lang>


Output:
Output:
Line 413: Line 413:
floating and MAXLONGREAL for double precision floating. An infinity test can be achieved with
floating and MAXLONGREAL for double precision floating. An infinity test can be achieved with
an EXCEPTION:
an EXCEPTION:
<syntaxhighlight lang="erre">
<lang ERRE>
PROGRAM INFINITY
PROGRAM INFINITY


Line 429: Line 429:
END WHILE
END WHILE
END PROGRAM
END PROGRAM
</syntaxhighlight>
</lang>


=={{header|Euphoria}}==
=={{header|Euphoria}}==


<lang Euphoria>constant infinity = 1E400
<syntaxhighlight lang="euphoria">constant infinity = 1E400


? infinity -- outputs "inf"</lang>
? infinity -- outputs "inf"</syntaxhighlight>


=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<lang fsharp>
<syntaxhighlight lang="fsharp">
printfn "%f" (1.0/0.0)
printfn "%f" (1.0/0.0)
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 447: Line 447:


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>1/0.</lang>
<syntaxhighlight lang="factor">1/0.</syntaxhighlight>


=={{header|Fantom}}==
=={{header|Fantom}}==
Line 453: Line 453:
Fantom's <code>Float</code> data type is an IEEE 754 64-bit floating point type. Positive infinity is represented by the constant <code>posInf</code>.
Fantom's <code>Float</code> data type is an IEEE 754 64-bit floating point type. Positive infinity is represented by the constant <code>posInf</code>.


<lang fantom>
<syntaxhighlight lang="fantom">
class Main
class Main
{
{
Line 459: Line 459:
public static Void main () { echo (getInfinity ()) }
public static Void main () { echo (getInfinity ()) }
}
}
</syntaxhighlight>
</lang>


=={{header|Forth}}==
=={{header|Forth}}==
<lang forth>: inf ( -- f ) 1e 0e f/ ;
<syntaxhighlight lang="forth">: inf ( -- f ) 1e 0e f/ ;
inf f. \ implementation specific. GNU Forth will output "inf"
inf f. \ implementation specific. GNU Forth will output "inf"


Line 468: Line 468:
\ IEEE infinity is the only value for which this will return true
\ IEEE infinity is the only value for which this will return true


: has-inf ( -- ? ) ['] inf catch if false else inf? then ;</lang>
: has-inf ( -- ? ) ['] inf catch if false else inf? then ;</syntaxhighlight>


=={{header|Fortran}}==
=={{header|Fortran}}==
ISO Fortran 2003 or later supports an IEEE_ARITHMETIC module which defines a wide range of intrinsic functions and types in support of IEEE floating point formats and arithmetic rules.
ISO Fortran 2003 or later supports an IEEE_ARITHMETIC module which defines a wide range of intrinsic functions and types in support of IEEE floating point formats and arithmetic rules.
<lang fortran>program to_f_the_ineffable
<syntaxhighlight lang="fortran">program to_f_the_ineffable
use, intrinsic :: ieee_arithmetic
use, intrinsic :: ieee_arithmetic
integer :: i
integer :: i
Line 489: Line 489:
end if
end if
end do
end do
end program to_f_the_ineffable</lang>
end program to_f_the_ineffable</syntaxhighlight>


ISO Fortran 90 or later supports a HUGE intrinsic which returns the largest value supported by the data type of the number given.
ISO Fortran 90 or later supports a HUGE intrinsic which returns the largest value supported by the data type of the number given.
<lang fortran>real :: x
<syntaxhighlight lang="fortran">real :: x
real :: huge_real = huge(x)</lang>
real :: huge_real = huge(x)</syntaxhighlight>


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64


#Include "crt/math.bi"
#Include "crt/math.bi"
Line 504: Line 504:
Print d; " (String representation of Positive Infinity)"
Print d; " (String representation of Positive Infinity)"
Sleep
Sleep
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 520: Line 520:


=={{header|GAP}}==
=={{header|GAP}}==
<lang gap># Floating point infinity
<syntaxhighlight lang="gap"># Floating point infinity
inf := FLOAT_INT(1) / FLOAT_INT(0);
inf := FLOAT_INT(1) / FLOAT_INT(0);


Line 528: Line 528:
# GAP has also a formal ''infinity'' value
# GAP has also a formal ''infinity'' value
infinity in Cyclotomics;
infinity in Cyclotomics;
# true</lang>
# true</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 549: Line 549:
x = posInf() // test function
x = posInf() // test function
fmt.Println(x, math.IsInf(x, 1)) // demonstrate result
fmt.Println(x, math.IsInf(x, 1)) // demonstrate result
}</lang>
}</syntaxhighlight>
Output:
Output:
<pre>
<pre>
Line 557: Line 557:
=={{header|Groovy}}==
=={{header|Groovy}}==
Groovy, like Java, requires full support for IEEE 32-bit (Float) and 64-bit (Double) formats. So the solution function would simply return either the Float or Double constant encoded as IEEE infinity.
Groovy, like Java, requires full support for IEEE 32-bit (Float) and 64-bit (Double) formats. So the solution function would simply return either the Float or Double constant encoded as IEEE infinity.
<lang groovy>def biggest = { Double.POSITIVE_INFINITY }</lang>
<syntaxhighlight lang="groovy">def biggest = { Double.POSITIVE_INFINITY }</syntaxhighlight>


Test program:
Test program:
<lang groovy>println biggest()
<syntaxhighlight lang="groovy">println biggest()
printf ( "0x%xL \n", Double.doubleToLongBits(biggest()) )</lang>
printf ( "0x%xL \n", Double.doubleToLongBits(biggest()) )</syntaxhighlight>


Output:
Output:
Line 573: Line 573:
Nevertheless, the following may come close to the task description:
Nevertheless, the following may come close to the task description:


<lang haskell>maxRealFloat :: RealFloat a => a -> a
<syntaxhighlight lang="haskell">maxRealFloat :: RealFloat a => a -> a
maxRealFloat x = encodeFloat b (e-1) `asTypeOf` x where
maxRealFloat x = encodeFloat b (e-1) `asTypeOf` x where
b = floatRadix x - 1
b = floatRadix x - 1
Line 580: Line 580:
infinity :: RealFloat a => a
infinity :: RealFloat a => a
infinity = if isInfinite inf then inf else maxRealFloat 1.0 where
infinity = if isInfinite inf then inf else maxRealFloat 1.0 where
inf = 1/0</lang>
inf = 1/0</syntaxhighlight>


Test for the two standard floating point types:
Test for the two standard floating point types:


<lang haskell>*Main> infinity :: Float
<syntaxhighlight lang="haskell">*Main> infinity :: Float
Infinity
Infinity
*Main> infinity :: Double
*Main> infinity :: Double
Infinity</lang>
Infinity</syntaxhighlight>


Or you can simply use division by 0:
Or you can simply use division by 0:
<lang haskell>Prelude> 1 / 0 :: Float
<syntaxhighlight lang="haskell">Prelude> 1 / 0 :: Float
Infinity
Infinity
Prelude> 1 / 0 :: Double
Prelude> 1 / 0 :: Double
Infinity</lang>
Infinity</syntaxhighlight>


Or use "read" to read the string representation:
Or use "read" to read the string representation:
<lang haskell>Prelude> read "Infinity" :: Float
<syntaxhighlight lang="haskell">Prelude> read "Infinity" :: Float
Infinity
Infinity
Prelude> read "Infinity" :: Double
Prelude> read "Infinity" :: Double
Infinity</lang>
Infinity</syntaxhighlight>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==
Line 610: Line 610:
IDL provides the standard IEEE values for _inf and _NaN in the !Values system structure:
IDL provides the standard IEEE values for _inf and _NaN in the !Values system structure:


<lang idl>print, !Values.f_infinity ;; for normal floats or
<syntaxhighlight lang="idl">print, !Values.f_infinity ;; for normal floats or
print, !Values.D_infinity ;; for doubles</lang>
print, !Values.D_infinity ;; for doubles</syntaxhighlight>


=={{header|Io}}==
=={{header|Io}}==
<lang io>inf := 1/0</lang>
<syntaxhighlight lang="io">inf := 1/0</syntaxhighlight>


or
or


<lang io>Number constants inf</lang>
<syntaxhighlight lang="io">Number constants inf</syntaxhighlight>


=={{header|IS-BASIC}}==
=={{header|IS-BASIC}}==
<lang IS-BASIC>PRINT INF</lang>
<syntaxhighlight lang="is-basic">PRINT INF</syntaxhighlight>
Output:
Output:
<pre>
<pre>
Line 632: Line 632:


Example:
Example:
<syntaxhighlight lang="j">
<lang j>
_ * 5 NB. multiplying infinity to 5 results in infinity
_ * 5 NB. multiplying infinity to 5 results in infinity
_
_
Line 639: Line 639:
5 % 0 NB. dividing 5 by 0 results in infinity
5 % 0 NB. dividing 5 by 0 results in infinity
_
_
</syntaxhighlight>
</lang>


=={{header|Java}}==
=={{header|Java}}==
Java's floating-point types (<tt>float</tt>, <tt>double</tt>) all support infinity. You can get infinity from constants in the corresponding wrapper class; for example, <tt>Double</tt>:
Java's floating-point types (<tt>float</tt>, <tt>double</tt>) all support infinity. You can get infinity from constants in the corresponding wrapper class; for example, <tt>Double</tt>:
<lang java>double infinity = Double.POSITIVE_INFINITY; //defined as 1.0/0.0
<syntaxhighlight lang="java">double infinity = Double.POSITIVE_INFINITY; //defined as 1.0/0.0
Double.isInfinite(infinity); //true</lang>
Double.isInfinite(infinity); //true</syntaxhighlight>
As a function:
As a function:
<lang java>public static double getInf(){
<syntaxhighlight lang="java">public static double getInf(){
return Double.POSITIVE_INFINITY;
return Double.POSITIVE_INFINITY;
}</lang>
}</syntaxhighlight>
The largest possible number in Java (without using the <tt>Big</tt> classes) is also in the <tt>Double</tt> class.
The largest possible number in Java (without using the <tt>Big</tt> classes) is also in the <tt>Double</tt> class.
<lang java>double biggestNumber = Double.MAX_VALUE;</lang>
<syntaxhighlight lang="java">double biggestNumber = Double.MAX_VALUE;</syntaxhighlight>
Its value is (2-2<sup>-52</sup>)*2<sup>1023</sup> or 1.7976931348623157*10<sup>308</sup> (a.k.a. "big"). Other number classes (<tt>Integer</tt>, <tt>Long</tt>, <tt>Float</tt>, <tt>Byte</tt>, and <tt>Short</tt>) have maximum values that can be accessed in the same way.
Its value is (2-2<sup>-52</sup>)*2<sup>1023</sup> or 1.7976931348623157*10<sup>308</sup> (a.k.a. "big"). Other number classes (<tt>Integer</tt>, <tt>Long</tt>, <tt>Float</tt>, <tt>Byte</tt>, and <tt>Short</tt>) have maximum values that can be accessed in the same way.


=={{header|JavaScript}}==
=={{header|JavaScript}}==
JavaScript has a special global property called "Infinity":
JavaScript has a special global property called "Infinity":
<lang javascript>Infinity</lang>
<syntaxhighlight lang="javascript">Infinity</syntaxhighlight>
as well as constants in the Number class:
as well as constants in the Number class:
<lang javascript>Number.POSITIVE_INFINITY
<syntaxhighlight lang="javascript">Number.POSITIVE_INFINITY
Number.NEGATIVE_INFINITY</lang>
Number.NEGATIVE_INFINITY</syntaxhighlight>


The global isFinite() function tests for finiteness:
The global isFinite() function tests for finiteness:
<lang javascript>isFinite(x)</lang>
<syntaxhighlight lang="javascript">isFinite(x)</syntaxhighlight>


=={{header|jq}}==
=={{header|jq}}==
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:
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:


<lang jq>def infinite: 1e1000;</lang>
<syntaxhighlight lang="jq">def infinite: 1e1000;</syntaxhighlight>


To test whether a JSON entity 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:
To test whether a JSON entity 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:


<lang jq>def isinfinite: . == infinite;</lang>
<syntaxhighlight lang="jq">def isinfinite: . == infinite;</syntaxhighlight>


Currently, the infinite value prints as though it were a very large floating point number.
Currently, the infinite value prints as though it were a very large floating point number.
Line 677: Line 677:
Julia uses IEEE floating-point arithmetic and includes a built-in constant `Inf` for (64-bit) floating-point infinity. Inf32 can be used as 32-bit infinity, when avoiding type promotions to Int64.
Julia uses IEEE floating-point arithmetic and includes a built-in constant `Inf` for (64-bit) floating-point infinity. Inf32 can be used as 32-bit infinity, when avoiding type promotions to Int64.


<syntaxhighlight lang="julia">
<lang Julia>
julia> julia> Inf32 == Inf64 == Inf16 == Inf
julia> julia> Inf32 == Inf64 == Inf16 == Inf
true
true
</syntaxhighlight>
</lang>


=={{header|K}}==
=={{header|K}}==
K has predefined positive and negative integer and float infinities: -0I, 0I, -0i, 0i. They have following properties:
K has predefined positive and negative integer and float infinities: -0I, 0I, -0i, 0i. They have following properties:
{{works with|Kona}}
{{works with|Kona}}
<lang K> / Integer infinities
<syntaxhighlight lang="k"> / Integer infinities
/ 0I is just 2147483647
/ 0I is just 2147483647
/ -0I is just -2147483647
/ -0I is just -2147483647
Line 733: Line 733:
/ but
/ but
0.0%0.0
0.0%0.0
0.0</lang>
0.0</syntaxhighlight>


=={{header|Klingphix}}==
=={{header|Klingphix}}==
<lang Klingphix>1e300 dup mult tostr "inf" equal ["Infinity" print] if
<syntaxhighlight lang="klingphix">1e300 dup mult tostr "inf" equal ["Infinity" print] if


" " input</lang>
" " input</syntaxhighlight>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
<lang scala>fun main(args: Array<String>) {
<syntaxhighlight lang="scala">fun main(args: Array<String>) {
val p = Double.POSITIVE_INFINITY // +∞
val p = Double.POSITIVE_INFINITY // +∞
println(p.isInfinite()) // true
println(p.isInfinite()) // true
Line 751: Line 751:
println(n.isFinite()) // false
println(n.isFinite()) // false
println("${n < 0} ${n > 0}") // true false
println("${n < 0} ${n > 0}") // true false
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>true
<pre>true
Line 762: Line 762:
=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
Lambdatalk is built on Javascript and can inherit lots of its capabilities. For instance:
Lambdatalk is built on Javascript and can inherit lots of its capabilities. For instance:
<lang scheme>
<syntaxhighlight lang="scheme">
{/ 1 0}
{/ 1 0}
-> Infinity
-> Infinity
Line 771: Line 771:
{< {pow 10 1000} Infinity}
{< {pow 10 1000} Infinity}
-> false
-> false
</syntaxhighlight>
</lang>


=={{header|Lasso}}==
=={{header|Lasso}}==
Lasso supports 64-bit decimals.. This gives Lasso's decimal numbers a range from approximately negative to positive 2x10^300 and with precision down to 2x10^-300. Lasso also supports decimal literals for NaN (not a number) as well and positive and negative infinity.
Lasso supports 64-bit decimals.. This gives Lasso's decimal numbers a range from approximately negative to positive 2x10^300 and with precision down to 2x10^-300. Lasso also supports decimal literals for NaN (not a number) as well and positive and negative infinity.
<lang Lasso>infinity
<syntaxhighlight lang="lasso">infinity
'<br />'
'<br />'
infinity -> type</lang>
infinity -> type</syntaxhighlight>
-> inf
-> inf


Line 785: Line 785:
Lingo stores floats using IEEE 754 double-precision (64-bit) format.
Lingo stores floats using IEEE 754 double-precision (64-bit) format.
INF is not a constant that can be used programmatically, but only a special return value.
INF is not a constant that can be used programmatically, but only a special return value.
<lang lingo>x = (1-power(2, -53)) * power(2, 1023) * 2
<syntaxhighlight lang="lingo">x = (1-power(2, -53)) * power(2, 1023) * 2
put ilk(x), x
put ilk(x), x
-- #float 1.79769313486232e308
-- #float 1.79769313486232e308
Line 791: Line 791:
x = (1-power(2, -53)) * power(2, 1023) * 3
x = (1-power(2, -53)) * power(2, 1023) * 3
put ilk(x), x, -x
put ilk(x), x, -x
-- #float INF -INF</lang>
-- #float INF -INF</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
<lang lua>
<syntaxhighlight lang="lua">
function infinity()
function infinity()
return 1/0 --lua uses unboxed C floats for all numbers
return 1/0 --lua uses unboxed C floats for all numbers
end
end
</syntaxhighlight>
</lang>


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Rem : locale 1033
Rem : locale 1033
Module CheckIt {
Module CheckIt {
Line 849: Line 849:
}
}
Checkit
Checkit
</syntaxhighlight>
</lang>


=={{header|Maple}}==
=={{header|Maple}}==
Maple's floating point numerics are a strict extension of IEEE/754 and IEEE/854 so there is already a built-in infinity. (In fact, there are several.) The following procedure just returns the floating point (positive) infinity directly.
Maple's floating point numerics are a strict extension of IEEE/754 and IEEE/854 so there is already a built-in infinity. (In fact, there are several.) The following procedure just returns the floating point (positive) infinity directly.
<syntaxhighlight lang="maple">
<lang Maple>
> proc() Float(infinity) end();
> proc() Float(infinity) end();
Float(infinity)
Float(infinity)
</syntaxhighlight>
</lang>
There is also an exact infinity ("infinity"), a negative float infinity ("Float(-infinity)" or "-Float(infinity)") and a suite of complex infinities. The next procedure returns a boxed machine (double precision) float infinity.
There is also an exact infinity ("infinity"), a negative float infinity ("Float(-infinity)" or "-Float(infinity)") and a suite of complex infinities. The next procedure returns a boxed machine (double precision) float infinity.
<syntaxhighlight lang="maple">
<lang Maple>
> proc() HFloat(infinity) end();
> proc() HFloat(infinity) end();
HFloat(infinity)
HFloat(infinity)
</syntaxhighlight>
</lang>


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Mathematica has infinity built-in as a symbol. Which can be used throughout the software:
Mathematica has infinity built-in as a symbol. Which can be used throughout the software:
<lang Mathematica>Sum[1/n^2,{n,Infinity}]
<syntaxhighlight lang="mathematica">Sum[1/n^2,{n,Infinity}]
1/Infinity
1/Infinity
Integrate[Exp[-x^2], {x, -Infinity, Infinity}]
Integrate[Exp[-x^2], {x, -Infinity, Infinity}]
10^100 < Infinity</lang>
10^100 < Infinity</syntaxhighlight>
gives back:
gives back:
<pre>Pi^2/6
<pre>Pi^2/6
Line 875: Line 875:
True</pre>
True</pre>
Moreover Mathematica has 2 other variables that represent 'infinity': DirectedInfinity[r] and ComplexInfinity. DirectInfinity[r] represents an infinite quantity with complex direction r. ComplexInfinity represents an infinite quantity with an undetermined direction; like 1/0. Which has infinite size but undetermined direction. So the general infinity is DirectedInfinity, however if the direction is unknown it will turn to ComplexInfinity, DirectedInfinity[-1] will return -infinity and DirectedInfinity[1] will return infinity. Directed infinity can, for example, be used to integrate over an infinite domain with a given complex direction: one might want to integrate Exp[-x^2]/(x^2-1) from 0 to DirectedInfinity[Exp[I Pi/4]]:
Moreover Mathematica has 2 other variables that represent 'infinity': DirectedInfinity[r] and ComplexInfinity. DirectInfinity[r] represents an infinite quantity with complex direction r. ComplexInfinity represents an infinite quantity with an undetermined direction; like 1/0. Which has infinite size but undetermined direction. So the general infinity is DirectedInfinity, however if the direction is unknown it will turn to ComplexInfinity, DirectedInfinity[-1] will return -infinity and DirectedInfinity[1] will return infinity. Directed infinity can, for example, be used to integrate over an infinite domain with a given complex direction: one might want to integrate Exp[-x^2]/(x^2-1) from 0 to DirectedInfinity[Exp[I Pi/4]]:
<lang Mathematica>Integrate[Exp[-x^2]/(x^2 - 1), {x, 0, DirectedInfinity[Exp[I Pi/4]]}]</lang>
<syntaxhighlight lang="mathematica">Integrate[Exp[-x^2]/(x^2 - 1), {x, 0, DirectedInfinity[Exp[I Pi/4]]}]</syntaxhighlight>
gives back:
gives back:
<pre>-((Pi (I+Erfi[1]))/(2 E))</pre>
<pre>-((Pi (I+Erfi[1]))/(2 E))</pre>
Line 882: Line 882:
MATLAB implements the IEEE 754 floating point standard as the default for all numeric data types. +Inf and -Inf are by default implemented and supported by MATLAB. To check if a variable has the value +/-Inf, one can use the built-in function "isinf()" which will return a Boolean 1 if the number is +/-inf.
MATLAB implements the IEEE 754 floating point standard as the default for all numeric data types. +Inf and -Inf are by default implemented and supported by MATLAB. To check if a variable has the value +/-Inf, one can use the built-in function "isinf()" which will return a Boolean 1 if the number is +/-inf.


<lang Matlab>a = +Inf;
<syntaxhighlight lang="matlab">a = +Inf;
isinf(a)
isinf(a)
</syntaxhighlight>
</lang>


Returns:
Returns:
Line 893: Line 893:


=={{header|Maxima}}==
=={{header|Maxima}}==
<lang maxima>/* Maxima has inf (positive infinity) and minf (negative infinity) */
<syntaxhighlight lang="maxima">/* Maxima has inf (positive infinity) and minf (negative infinity) */


declare(x, real)$
declare(x, real)$
Line 906: Line 906:
1.0/0.0;
1.0/0.0;
/* expt: undefined: 0 to a negative exponent.
/* expt: undefined: 0 to a negative exponent.
-- an error. To debug this try: debugmode(true); */</lang>
-- an error. To debug this try: debugmode(true); */</syntaxhighlight>


=={{header|Metafont}}==
=={{header|Metafont}}==
Line 912: Line 912:
Metafont numbers are a little bit odd (it uses fixed binary arithmetic). For Metafont, the biggest number (and so the one which is also considered to be infinity) is 4095.99998. In fact, in the basic set of macros for Metafont, we can read
Metafont numbers are a little bit odd (it uses fixed binary arithmetic). For Metafont, the biggest number (and so the one which is also considered to be infinity) is 4095.99998. In fact, in the basic set of macros for Metafont, we can read


<lang metafont>infinity := 4095.99998;</lang>
<syntaxhighlight lang="metafont">infinity := 4095.99998;</syntaxhighlight>


=={{header|MiniScript}}==
=={{header|MiniScript}}==
MiniScript uses IEEE numerics, so:
MiniScript uses IEEE numerics, so:


<lang MiniScript>posInfinity = 1/0
<syntaxhighlight lang="miniscript">posInfinity = 1/0
print posInfinity</lang>
print posInfinity</syntaxhighlight>
{{out}}
{{out}}
<pre>INF</pre>
<pre>INF</pre>


=={{header|Modula-2}}==
=={{header|Modula-2}}==
<lang Modula-2>MODULE inf;
<syntaxhighlight lang="modula-2">MODULE inf;


IMPORT InOut;
IMPORT InOut;
Line 930: Line 930:
InOut.WriteReal (1.0 / 0.0, 12, 12);
InOut.WriteReal (1.0 / 0.0, 12, 12);
InOut.WriteLn
InOut.WriteLn
END inf.</lang>
END inf.</syntaxhighlight>
Producing
Producing
<lang Modula-2>jan@Beryllium:~/modula/rosetta$ inf
<syntaxhighlight lang="modula-2">jan@Beryllium:~/modula/rosetta$ inf


**** RUNTIME ERROR bound check error
**** RUNTIME ERROR bound check error
Floating point exception</lang>
Floating point exception</syntaxhighlight>


=={{header|Modula-3}}==
=={{header|Modula-3}}==
Line 941: Line 941:


If the implementation doesn't support IEEE floats, the program prints arbitrary values (Critical Mass Modula-3 implementation does support IEEE floats).
If the implementation doesn't support IEEE floats, the program prints arbitrary values (Critical Mass Modula-3 implementation does support IEEE floats).
<lang modula3>MODULE Inf EXPORTS Main;
<syntaxhighlight lang="modula3">MODULE Inf EXPORTS Main;


IMPORT IO, IEEESpecial;
IMPORT IO, IEEESpecial;
Line 948: Line 948:
IO.PutReal(IEEESpecial.RealPosInf);
IO.PutReal(IEEESpecial.RealPosInf);
IO.Put("\n");
IO.Put("\n");
END Inf.</lang>
END Inf.</syntaxhighlight>


Output:
Output:
Line 957: Line 957:
=={{header|Nemerle}}==
=={{header|Nemerle}}==
Both single and double precision floating point numbers support PositiveInfinity, NegativeInfinity and NaN.
Both single and double precision floating point numbers support PositiveInfinity, NegativeInfinity and NaN.
<lang Nemerle>def posinf = double.PositiveInfinity;
<syntaxhighlight lang="nemerle">def posinf = double.PositiveInfinity;
def a = IsInfinity(posinf); // a = true
def a = IsInfinity(posinf); // a = true
def b = IsNegativeInfinity(posinf); // b = false
def b = IsNegativeInfinity(posinf); // b = false
def c = IsPositiveInfinity(posinf); // c = true</lang>
def c = IsPositiveInfinity(posinf); // c = true</syntaxhighlight>


=={{header|Nim}}==
=={{header|Nim}}==
<lang nim>Inf</lang>
<syntaxhighlight lang="nim">Inf</syntaxhighlight>
is a predefined constant in Nim:
is a predefined constant in Nim:
<lang nim>var f = Inf
<syntaxhighlight lang="nim">var f = Inf
echo f</lang>
echo f</syntaxhighlight>


=={{header|NS-HUBASIC}}==
=={{header|NS-HUBASIC}}==
<lang NS-HUBASIC>10 PRINT 1/0</lang>
<syntaxhighlight lang="ns-hubasic">10 PRINT 1/0</syntaxhighlight>
{{out}}
{{out}}
?DZ ERROR is a division by zero error in NS-HUBASIC.
?DZ ERROR is a division by zero error in NS-HUBASIC.
Line 977: Line 977:


=={{header|OCaml}}==
=={{header|OCaml}}==
<lang ocaml>infinity</lang>
<syntaxhighlight lang="ocaml">infinity</syntaxhighlight>
is already a pre-defined value in OCaml.
is already a pre-defined value in OCaml.


Line 989: Line 989:
=={{header|Oforth}}==
=={{header|Oforth}}==


<lang Oforth>10 1000.0 powf dup println dup neg println 1 swap / println</lang>
<syntaxhighlight lang="oforth">10 1000.0 powf dup println dup neg println 1 swap / println</syntaxhighlight>


{{out}}
{{out}}
Line 1,004: Line 1,004:
-inf.0 ; negative infinity
-inf.0 ; negative infinity


<lang scheme>
<syntaxhighlight lang="scheme">
(define (infinite? x) (or (equal? x +inf.0) (equal? x -inf.0)))
(define (infinite? x) (or (equal? x +inf.0) (equal? x -inf.0)))


Line 1,013: Line 1,013:
(infinite? 1/3456) ==> #false
(infinite? 1/3456) ==> #false
(infinite? 17+28i) ==> #false
(infinite? 17+28i) ==> #false
</syntaxhighlight>
</lang>


=={{header|OpenEdge/Progress}}==
=={{header|OpenEdge/Progress}}==
Line 1,019: Line 1,019:
The unknown value (represented by a question mark) can be considered to equal infinity. There is no difference between positive and negative infinity but the unknown value sometimes sorts low and sometimes sorts high when used in queries.
The unknown value (represented by a question mark) can be considered to equal infinity. There is no difference between positive and negative infinity but the unknown value sometimes sorts low and sometimes sorts high when used in queries.


<lang progress>MESSAGE
<syntaxhighlight lang="progress">MESSAGE
1.0 / 0.0 SKIP
1.0 / 0.0 SKIP
-1.0 / 0.0 SKIP(1)
-1.0 / 0.0 SKIP(1)
( 1.0 / 0.0 ) = ( -1.0 / 0.0 )
( 1.0 / 0.0 ) = ( -1.0 / 0.0 )
VIEW-AS ALERT-BOX.</lang>
VIEW-AS ALERT-BOX.</syntaxhighlight>


Output
Output
Line 1,040: Line 1,040:
=={{header|OxygenBasic}}==
=={{header|OxygenBasic}}==
Using double precision floats:
Using double precision floats:
<lang oxygenbasic>
<syntaxhighlight lang="oxygenbasic">
print 1.5e-400 '0
print 1.5e-400 '0


Line 1,061: Line 1,061:


print f '#-INF
print f '#-INF
</syntaxhighlight>
</lang>


=={{header|Oz}}==
=={{header|Oz}}==
<lang oz>declare
<syntaxhighlight lang="oz">declare
PosInf = 1./0.
PosInf = 1./0.
NegInf = ~1./0.
NegInf = ~1./0.
Line 1,076: Line 1,076:
PosInf * PosInf = PosInf
PosInf * PosInf = PosInf
PosInf * NegInf = NegInf
PosInf * NegInf = NegInf
NegInf * NegInf = PosInf</lang>
NegInf * NegInf = PosInf</syntaxhighlight>


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
{{works with|PARI/GP|version 2.8.0 and higher}}
{{works with|PARI/GP|version 2.8.0 and higher}}
<lang parigp>+oo</lang>
<syntaxhighlight lang="parigp">+oo</syntaxhighlight>


{{works with|PARI/GP|version 2.2.9 to 2.7.0}}
{{works with|PARI/GP|version 2.2.9 to 2.7.0}}
<lang parigp>infty()={
<syntaxhighlight lang="parigp">infty()={
[1] \\ Used for many functions like intnum
[1] \\ Used for many functions like intnum
};</lang>
};</syntaxhighlight>


=={{header|Pascal}}==
=={{header|Pascal}}==
Line 1,092: Line 1,092:
=={{header|Perl}}==
=={{header|Perl}}==
Positive infinity:
Positive infinity:
<lang perl>my $x = 0 + "inf";
<syntaxhighlight lang="perl">my $x = 0 + "inf";
my $y = 0 + "+inf";</lang>
my $y = 0 + "+inf";</syntaxhighlight>
Negative infinity:
Negative infinity:
<lang perl>my $x = 0 - "inf";
<syntaxhighlight lang="perl">my $x = 0 - "inf";
my $y = 0 + "-inf";</lang>
my $y = 0 + "-inf";</syntaxhighlight>
The "<code>0 + </code>..." is used here to make sure that the variable stores a value that is actually an infinitive number instead of just a string <code>"inf"</code> but in practice one can use just:
The "<code>0 + </code>..." is used here to make sure that the variable stores a value that is actually an infinitive number instead of just a string <code>"inf"</code> but in practice one can use just:
<lang perl>my $x = "inf";</lang>
<syntaxhighlight lang="perl">my $x = "inf";</syntaxhighlight>
and <code>$x</code> while originally holding a string will get converted to an infinite number when it is first used as a number.
and <code>$x</code> while originally holding a string will get converted to an infinite number when it is first used as a number.


Some programmers use expressions that overflow the IEEE floating point numbers such as:
Some programmers use expressions that overflow the IEEE floating point numbers such as:
<lang perl>my $x = 1e1000;</lang>
<syntaxhighlight lang="perl">my $x = 1e1000;</syntaxhighlight>
which is 10<sup>1000</sup> or googol<sup>10</sup> or even numbers like this one:
which is 10<sup>1000</sup> or googol<sup>10</sup> or even numbers like this one:
<lang perl>my $y = 10**10**10;</lang>
<syntaxhighlight lang="perl">my $y = 10**10**10;</syntaxhighlight>
which is 10<sup>10000000000</sup> but it has to make some assumptions about the underlying hardware format and its size. Furthermore, using such literals in the scope of some pragmas such as <code>bigint</code>, <code>bignum</code> or <code>bigrat</code> would actually compute those numbers:
which is 10<sup>10000000000</sup> but it has to make some assumptions about the underlying hardware format and its size. Furthermore, using such literals in the scope of some pragmas such as <code>bigint</code>, <code>bignum</code> or <code>bigrat</code> would actually compute those numbers:


<lang perl>use bigint;
<syntaxhighlight lang="perl">use bigint;
my $x = 1e1000;
my $x = 1e1000;
my $y = 10**10**10; # N.B. this will consume vast quantities of RAM</lang>
my $y = 10**10**10; # N.B. this will consume vast quantities of RAM</syntaxhighlight>
Here the <code>$x</code> and <code>$y</code> when printed would give 1001 and 10000000001-digit numbers respectively, the latter taking no less than 10GB of space to just output.
Here the <code>$x</code> and <code>$y</code> when printed would give 1001 and 10000000001-digit numbers respectively, the latter taking no less than 10GB of space to just output.


Under those pragmas, however, there is a simpler way to use infinite values, thanks to the <code>inf</code> symbol being exported into the namespace by default:
Under those pragmas, however, there is a simpler way to use infinite values, thanks to the <code>inf</code> symbol being exported into the namespace by default:
<lang perl>use bigint;
<syntaxhighlight lang="perl">use bigint;
my $x = inf;
my $x = inf;
my $y = -inf;</lang>
my $y = -inf;</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">infinity</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1e300</span><span style="color: #0000FF;">*</span><span style="color: #000000;">1e300</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">infinity</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1e300</span><span style="color: #0000FF;">*</span><span style="color: #000000;">1e300</span>
<span style="color: #0000FF;">?</span> <span style="color: #000000;">infinity</span>
<span style="color: #0000FF;">?</span> <span style="color: #000000;">infinity</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
desktop/Phix:
desktop/Phix:
Line 1,134: Line 1,134:


=={{header|Phixmonti}}==
=={{header|Phixmonti}}==
<lang Phixmonti>1e300 dup * tostr "inf" == if "Infinity" print endif</lang>
<syntaxhighlight lang="phixmonti">1e300 dup * tostr "inf" == if "Infinity" print endif</syntaxhighlight>


=={{header|PHP}}==
=={{header|PHP}}==
This is how you get infinity:
This is how you get infinity:
<lang php>INF</lang>
<syntaxhighlight lang="php">INF</syntaxhighlight>
Unfortunately, "1.0 / 0.0" doesn't evaluate to infinity; but instead seems to evaluate to False, which is more like 0 than infinity.
Unfortunately, "1.0 / 0.0" doesn't evaluate to infinity; but instead seems to evaluate to False, which is more like 0 than infinity.


Line 1,149: Line 1,149:
support (scaled bignum arithmetics), but some functions return 'T' for infinite
support (scaled bignum arithmetics), but some functions return 'T' for infinite
results.
results.
<lang PicoLisp>(load "@lib/math.l")
<syntaxhighlight lang="picolisp">(load "@lib/math.l")


: (exp 1000.0)
: (exp 1000.0)
-> T</lang>
-> T</syntaxhighlight>


=={{header|PL/I}}==
=={{header|PL/I}}==
<syntaxhighlight lang="pl/i">
<lang PL/I>
declare x float, y float (15), z float (18);
declare x float, y float (15), z float (18);


put skip list (huge(x), huge(y), huge(z));
put skip list (huge(x), huge(y), huge(z));
</syntaxhighlight>
</lang>


=={{header|PostScript}}==
=={{header|PostScript}}==
<lang postscript>/infinity { 9 99 exp } def</lang>
<syntaxhighlight lang="postscript">/infinity { 9 99 exp } def</syntaxhighlight>


=={{header|PowerShell}}==
=={{header|PowerShell}}==
A .NET floating-point number representing infinity is available.
A .NET floating-point number representing infinity is available.
<lang powershell>function infinity {
<syntaxhighlight lang="powershell">function infinity {
[double]::PositiveInfinity
[double]::PositiveInfinity
}</lang>
}</syntaxhighlight>


=={{header|PureBasic}}==
=={{header|PureBasic}}==
Line 1,174: Line 1,174:
PureBasic uses [[wp:IEEE_754-2008|IEEE 754]] coding for float types. PureBasic also includes the function <tt>Infinity()</tt> that return the positive value for infinity and the boolean function <tt>IsInfinite(value.f)</tt> that returns true if the floating point value is either positive or negative infinity.
PureBasic uses [[wp:IEEE_754-2008|IEEE 754]] coding for float types. PureBasic also includes the function <tt>Infinity()</tt> that return the positive value for infinity and the boolean function <tt>IsInfinite(value.f)</tt> that returns true if the floating point value is either positive or negative infinity.


<lang PureBasic>If OpenConsole()
<syntaxhighlight lang="purebasic">If OpenConsole()
Define.d a, b
Define.d a, b
b = 0
b = 0
Line 1,193: Line 1,193:
CloseConsole()
CloseConsole()
EndIf
EndIf
</syntaxhighlight>
</lang>


''Outputs''
''Outputs''
Line 1,203: Line 1,203:
=={{header|Python}}==
=={{header|Python}}==
This is how you get infinity:
This is how you get infinity:
<lang python>>>> float('infinity')
<syntaxhighlight lang="python">>>> float('infinity')
inf</lang>
inf</syntaxhighlight>
''Note: When passing in a string to float(), values for NaN and Infinity may be returned, depending on the underlying C library. The specific set of strings accepted which cause these values to be returned depends entirely on the underlying C library used to compile Python itself, and is known to vary.'' <br>
''Note: When passing in a string to float(), values for NaN and Infinity may be returned, depending on the underlying C library. The specific set of strings accepted which cause these values to be returned depends entirely on the underlying C library used to compile Python itself, and is known to vary.'' <br>
''The Decimal module explicitly supports +/-infinity Nan, +/-0.0, etc without exception.''
''The Decimal module explicitly supports +/-infinity Nan, +/-0.0, etc without exception.''


Floating-point division by 0 doesn't give you infinity, it raises an exception:
Floating-point division by 0 doesn't give you infinity, it raises an exception:
<lang python>>>> 1.0 / 0.0
<syntaxhighlight lang="python">>>> 1.0 / 0.0
Traceback (most recent call last):
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <module>
ZeroDivisionError: float division</lang>
ZeroDivisionError: float division</syntaxhighlight>


If <tt>float('infinity')</tt> doesn't work on your platform, you could use this trick:
If <tt>float('infinity')</tt> doesn't work on your platform, you could use this trick:
Line 1,220: Line 1,220:


=={{header|QB64}}==
=={{header|QB64}}==
<lang c++>#include<math.h>
<syntaxhighlight lang="c++">#include<math.h>
//save as inf.h
//save as inf.h
double inf(void){
double inf(void){
return HUGE_VAL;
return HUGE_VAL;
}</lang>
}</syntaxhighlight>
<lang vb>Declare CustomType Library "inf"
<syntaxhighlight lang="vb">Declare CustomType Library "inf"
Function inf#
Function inf#
End Declare
End Declare


Print inf</lang>
Print inf</syntaxhighlight>


=={{header|QBasic}}==
=={{header|QBasic}}==
{{works with|QBasic|1.1}}
{{works with|QBasic|1.1}}
<lang QBasic>DECLARE FUNCTION f! ()
<syntaxhighlight lang="qbasic">DECLARE FUNCTION f! ()


ON ERROR GOTO TratoError
ON ERROR GOTO TratoError
Line 1,259: Line 1,259:
FUNCTION f!
FUNCTION f!
f! = -1.5 / 0
f! = -1.5 / 0
END FUNCTION</lang>
END FUNCTION</syntaxhighlight>




=={{header|R}}==
=={{header|R}}==
<lang R> Inf #positive infinity
<syntaxhighlight lang="r"> Inf #positive infinity
-Inf #negative infinity
-Inf #negative infinity
.Machine$double.xmax # largest finite floating-point number
.Machine$double.xmax # largest finite floating-point number
Line 1,273: Line 1,273:
forcefinite(c(1, -1, 0, .Machine$double.xmax, -.Machine$double.xmax, Inf, -Inf))
forcefinite(c(1, -1, 0, .Machine$double.xmax, -.Machine$double.xmax, Inf, -Inf))
# [1] 1.000000e+00 -1.000000e+00 0.000000e+00 1.797693e+308
# [1] 1.000000e+00 -1.000000e+00 0.000000e+00 1.797693e+308
# [5] -1.797693e+308 1.797693e+308 -1.797693e+308</lang>
# [5] -1.797693e+308 1.797693e+308 -1.797693e+308</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
Line 1,279: Line 1,279:
as in Scheme:
as in Scheme:


<lang Racket>#lang racket
<syntaxhighlight lang="racket">#lang racket


+inf.0 ; positive infinity
+inf.0 ; positive infinity
(define (finite? x) (< -inf.0 x +inf.0))
(define (finite? x) (< -inf.0 x +inf.0))
(define (infinite? x) (not (finite? x)))</lang>
(define (infinite? x) (not (finite? x)))</syntaxhighlight>


=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
Inf support is required by language spec on all abstract Numeric types (in the absence of subset constraints) including Num, Rat and Int types. Native integers cannot support Inf, so attempting to assign Inf will result in an exception; native floats are expected to follow IEEE standards including +/- Inf and NaN.
Inf support is required by language spec on all abstract Numeric types (in the absence of subset constraints) including Num, Rat and Int types. Native integers cannot support Inf, so attempting to assign Inf will result in an exception; native floats are expected to follow IEEE standards including +/- Inf and NaN.
<lang perl6>my $x = 1.5/0; # Failure: catchable error, if evaluated will return: "Attempt to divide by zero ...
<syntaxhighlight lang="raku" line>my $x = 1.5/0; # Failure: catchable error, if evaluated will return: "Attempt to divide by zero ...
my $y = (1.5/0).Num; # assigns 'Inf'</lang>
my $y = (1.5/0).Num; # assigns 'Inf'</syntaxhighlight>


=={{header|REXX}}==
=={{header|REXX}}==
Line 1,330: Line 1,330:


=={{header|RLaB}}==
=={{header|RLaB}}==
<syntaxhighlight lang="rlab">
<lang RLaB>
>> x = inf()
>> x = inf()
inf
inf
Line 1,339: Line 1,339:
>> -inf() > 10
>> -inf() > 10
0
0
</syntaxhighlight>
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==
Infinity is a Float value
Infinity is a Float value
<lang ruby>a = 1.0/0 # => Infinity
<syntaxhighlight lang="ruby">a = 1.0/0 # => Infinity
a.finite? # => false
a.finite? # => false
a.infinite? # => 1
a.infinite? # => 1
Line 1,352: Line 1,352:
a = Float::MAX # => 1.79769313486232e+308
a = Float::MAX # => 1.79769313486232e+308
a.finite? # => true
a.finite? # => true
a.infinite? # => nil</lang>
a.infinite? # => nil</syntaxhighlight>
{{works with|Ruby|1.9.2+}}
{{works with|Ruby|1.9.2+}}
<lang ruby>a = Float::INFINITY # => Infinity</lang>
<syntaxhighlight lang="ruby">a = Float::INFINITY # => Infinity</syntaxhighlight>


=={{header|Rust}}==
=={{header|Rust}}==
Rust has builtin function for floating types which returns infinity. This program outputs 'inf'.
Rust has builtin function for floating types which returns infinity. This program outputs 'inf'.
<lang rust>fn main() {
<syntaxhighlight lang="rust">fn main() {
let inf = f32::INFINITY;
let inf = f32::INFINITY;
println!("{}", inf);
println!("{}", inf);
}</lang>
}</syntaxhighlight>


=={{header|Scala}}==
=={{header|Scala}}==
Line 1,369: Line 1,369:
* [[Extreme_floating_point_values#Scala]]
* [[Extreme_floating_point_values#Scala]]
In order to be compliant with IEEE-754, Scala has all support for infinity on its floating-point types (<tt>float</tt>, <tt>double</tt>). You can get infinity from constants in the corresponding wrapper class; for example, <tt>Double</tt>:
In order to be compliant with IEEE-754, Scala has all support for infinity on its floating-point types (<tt>float</tt>, <tt>double</tt>). You can get infinity from constants in the corresponding wrapper class; for example, <tt>Double</tt>:
<lang Scala>val inf = Double.PositiveInfinity //defined as 1.0/0.0
<syntaxhighlight lang="scala">val inf = Double.PositiveInfinity //defined as 1.0/0.0
inf.isInfinite; //true</lang>
inf.isInfinite; //true</syntaxhighlight>
The largest possible number in Scala (without using the <tt>Big</tt> classes) is also in the <tt>Double</tt> class.
The largest possible number in Scala (without using the <tt>Big</tt> classes) is also in the <tt>Double</tt> class.
<lang Scala>val biggestNumber = Double.MaxValue</lang>
<syntaxhighlight lang="scala">val biggestNumber = Double.MaxValue</syntaxhighlight>


REPL session:
REPL session:
<lang scala>scala> 1 / 0.
<syntaxhighlight lang="scala">scala> 1 / 0.
res2: Double = Infinity
res2: Double = Infinity


Line 1,385: Line 1,385:


scala> 1 / Double.NegativeInfinity
scala> 1 / Double.NegativeInfinity
res5: Double = -0.0</lang>
res5: Double = -0.0</syntaxhighlight>


=={{header|Scheme}}==
=={{header|Scheme}}==
<lang scheme>+inf.0 ; positive infinity
<syntaxhighlight lang="scheme">+inf.0 ; positive infinity
(define (finite? x) (< -inf.0 x +inf.0))
(define (finite? x) (< -inf.0 x +inf.0))
(define (infinite? x) (not (finite? x)))</lang>
(define (infinite? x) (not (finite? x)))</syntaxhighlight>


=={{header|Seed7}}==
=={{header|Seed7}}==
Line 1,396: Line 1,396:
The library [http://seed7.sourceforge.net/libraries/float.htm float.s7i] defines
The library [http://seed7.sourceforge.net/libraries/float.htm float.s7i] defines
the constant [http://seed7.sourceforge.net/libraries/float.htm#Infinity Infinity] as:
the constant [http://seed7.sourceforge.net/libraries/float.htm#Infinity Infinity] as:
<lang seed7>const float: Infinity is 1.0 / 0.0;</lang>
<syntaxhighlight lang="seed7">const float: Infinity is 1.0 / 0.0;</syntaxhighlight>
Checks for infinity can be done by comparing with this constant.
Checks for infinity can be done by comparing with this constant.


=={{header|Sidef}}==
=={{header|Sidef}}==
<lang ruby>var a = 1.5/0 # Inf
<syntaxhighlight lang="ruby">var a = 1.5/0 # Inf
say a.is_inf # true
say a.is_inf # true
say a.is_pos # true
say a.is_pos # true
Line 1,410: Line 1,410:
var inf = Inf
var inf = Inf
var ninf = -Inf
var ninf = -Inf
say (inf == -ninf) # true</lang>
say (inf == -ninf) # true</syntaxhighlight>


=={{header|Slate}}==
=={{header|Slate}}==


<lang slate>PositiveInfinity</lang>
<syntaxhighlight lang="slate">PositiveInfinity</syntaxhighlight>


=={{header|Smalltalk}}==
=={{header|Smalltalk}}==
Line 1,427: Line 1,427:
{{works with|Smalltalk/X}}
{{works with|Smalltalk/X}}
The behavior is slightly different, in that an exception is raised if you divide by zero:
The behavior is slightly different, in that an exception is raised if you divide by zero:
<lang smalltalk>FloatD infinity -> INF
<syntaxhighlight lang="smalltalk">FloatD infinity -> INF
1.0 / 0.0 -> "ZeroDivide exception"</lang>
1.0 / 0.0 -> "ZeroDivide exception"</syntaxhighlight>
but we can simulate the other behavior with:
but we can simulate the other behavior with:
<lang smalltalk>[
<syntaxhighlight lang="smalltalk">[
1.0 / 0.0
1.0 / 0.0
] on: ZeroDivide do:[:ex |
] on: ZeroDivide do:[:ex |
ex proceedWith: (FloatD infinity)
ex proceedWith: (FloatD infinity)
]
]
-> INF</lang>
-> INF</syntaxhighlight>


=={{header|Standard ML}}==
=={{header|Standard ML}}==
<lang sml>Real.posInf</lang>
<syntaxhighlight lang="sml">Real.posInf</syntaxhighlight>


<pre>
<pre>
Line 1,449: Line 1,449:
=={{header|Swift}}==
=={{header|Swift}}==
Swift's floating-point types (<tt>Float</tt>, <tt>Double</tt>, and any other type that conforms to the <tt>FloatingPointNumber</tt> protocol) all support infinity. You can get infinity from the <tt>infinity</tt> class property in the type:
Swift's floating-point types (<tt>Float</tt>, <tt>Double</tt>, and any other type that conforms to the <tt>FloatingPointNumber</tt> protocol) all support infinity. You can get infinity from the <tt>infinity</tt> class property in the type:
<lang swift>let inf = Double.infinity
<syntaxhighlight lang="swift">let inf = Double.infinity
inf.isInfinite //true</lang>
inf.isInfinite //true</syntaxhighlight>
As a function:
As a function:
<lang swift>func getInf() -> Double {
<syntaxhighlight lang="swift">func getInf() -> Double {
return Double.infinity
return Double.infinity
}</lang>
}</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
Line 1,460: Line 1,460:


Tcl 8.5 has Infinite as a floating point value, not an integer value
Tcl 8.5 has Infinite as a floating point value, not an integer value
<lang tcl>package require Tcl 8.5
<syntaxhighlight lang="tcl">package require Tcl 8.5


expr {1.0 / 0} ;# ==> Inf
expr {1.0 / 0} ;# ==> Inf
expr {-1.0 / 0} ;# ==> -Inf
expr {-1.0 / 0} ;# ==> -Inf
expr {inf} ;# ==> Inf
expr {inf} ;# ==> Inf
expr {1 / 0} ;# ==> "divide by zero" error; Inf not part of range of integer division</lang>
expr {1 / 0} ;# ==> "divide by zero" error; Inf not part of range of integer division</syntaxhighlight>


A maximal integer is not easy to find, as Tcl switches to unbounded integers when a 64-bit integer is about to roll over:
A maximal integer is not easy to find, as Tcl switches to unbounded integers when a 64-bit integer is about to roll over:
<lang Tcl>% format %lx -1 ;# all bits set
<syntaxhighlight lang="tcl">% format %lx -1 ;# all bits set
ffffffffffffffff
ffffffffffffffff


Line 1,478: Line 1,478:


% incr ii
% incr ii
9223372036854775808 ;# silently upgrade to unbounded integer, still positive</lang>
9223372036854775808 ;# silently upgrade to unbounded integer, still positive</syntaxhighlight>
A theoretical MAXINT, though very impractical, could be
A theoretical MAXINT, though very impractical, could be
string repeat 9 [expr 2**32-1]
string repeat 9 [expr 2**32-1]
Line 1,484: Line 1,484:
=={{header|TI-89 BASIC}}==
=={{header|TI-89 BASIC}}==


<lang ti89b>∞</lang>
<syntaxhighlight lang="ti89b">∞</syntaxhighlight>


=={{header|TorqueScript}}==
=={{header|TorqueScript}}==
<lang TorqueScript>function infinity()
<syntaxhighlight lang="torquescript">function infinity()
{
{
return 1/0;
return 1/0;
}</lang>
}</syntaxhighlight>


=={{header|Trith}}==
=={{header|Trith}}==
The following functions are included as part of the core operators:
The following functions are included as part of the core operators:
<lang trith>
<syntaxhighlight lang="trith">
: inf 1.0 0.0 / ;
: inf 1.0 0.0 / ;
: -inf inf neg ;
: -inf inf neg ;
: inf? abs inf = ;
: inf? abs inf = ;
</syntaxhighlight>
</lang>


=={{header|Ursa}}==
=={{header|Ursa}}==
Infinity is a defined value in Ursa.
Infinity is a defined value in Ursa.
<lang ursa>decl double d
<syntaxhighlight lang="ursa">decl double d
set d Infinity</lang>
set d Infinity</syntaxhighlight>


=={{header|Ursala}}==
=={{header|Ursala}}==
Line 1,512: Line 1,512:




<lang Ursala>#import flo
<syntaxhighlight lang="ursala">#import flo


infinity = inf!</lang>
infinity = inf!</syntaxhighlight>


=={{header|Visual Basic}}==
=={{header|Visual Basic}}==
Line 1,524: Line 1,524:
Positive infinity, negative infinity and indefinite number (usable as NaN) can be generated by deliberately dividing by zero under the influence of <code>On Error Resume Next</code>:
Positive infinity, negative infinity and indefinite number (usable as NaN) can be generated by deliberately dividing by zero under the influence of <code>On Error Resume Next</code>:


<lang vb>Option Explicit
<syntaxhighlight lang="vb">Option Explicit


Private Declare Sub GetMem8 Lib "msvbvm60.dll" _
Private Declare Sub GetMem8 Lib "msvbvm60.dll" _
Line 1,550: Line 1,550:
DoubleAsHex = Right$(String$(8, "0") & Hex$(l(1)), 8) _
DoubleAsHex = Right$(String$(8, "0") & Hex$(l(1)), 8) _
& Right$(String$(8, "0") & Hex$(l(0)), 8)
& Right$(String$(8, "0") & Hex$(l(0)), 8)
End Function</lang>
End Function</syntaxhighlight>
{{out}}<pre>PlusInfinity = 1,#INF (7FF0000000000000)
{{out}}<pre>PlusInfinity = 1,#INF (7FF0000000000000)
MinusInfinity = -1,#INF (FFF0000000000000)
MinusInfinity = -1,#INF (FFF0000000000000)
Line 1,557: Line 1,557:


=={{header|Vlang}}==
=={{header|Vlang}}==
<lang vlang>import math
<syntaxhighlight lang="vlang">import math
fn main() {
fn main() {
Line 1,565: Line 1,565:
x = math.inf(1)
x = math.inf(1)
println('$x ${math.is_inf(x, 1)}') // demonstrate result
println('$x ${math.is_inf(x, 1)}') // demonstrate result
}</lang>
}</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
Wren certainly supports infinity for floating point numbers as we already have a method ''Num.isInfinity'' to test for it.
Wren certainly supports infinity for floating point numbers as we already have a method ''Num.isInfinity'' to test for it.
<lang ecmascript>var x = 1.5
<syntaxhighlight lang="ecmascript">var x = 1.5
var y = x / 0
var y = x / 0
System.print("x = %(x)")
System.print("x = %(x)")
System.print("y = %(y)")
System.print("y = %(y)")
System.print("'x' is infinite? %(x.isInfinity)")
System.print("'x' is infinite? %(x.isInfinity)")
System.print("'y' is infinite? %(y.isInfinity)")</lang>
System.print("'y' is infinite? %(y.isInfinity)")</syntaxhighlight>


{{out}}
{{out}}
Line 1,586: Line 1,586:
=={{header|XPL0}}==
=={{header|XPL0}}==
The IEEE 754 floating point standard is used.
The IEEE 754 floating point standard is used.
<lang XPL0>int A;
<syntaxhighlight lang="xpl0">int A;
real X;
real X;
[Format(0, 15); \output in scientific notation
[Format(0, 15); \output in scientific notation
Line 1,593: Line 1,593:
A(1):= $7FEF_FFFF;
A(1):= $7FEF_FFFF;
RlOut(0, X); \display it
RlOut(0, X); \display it
]</lang>
]</syntaxhighlight>


{{out}}
{{out}}
Line 1,601: Line 1,601:


=={{header|Yabasic}}==
=={{header|Yabasic}}==
<lang Yabasic>infinity = 1e300*1e300
<syntaxhighlight lang="yabasic">infinity = 1e300*1e300
if str$(infinity) = "inf" print "Infinity"</lang>
if str$(infinity) = "inf" print "Infinity"</syntaxhighlight>


=={{header|Zig}}==
=={{header|Zig}}==
<lang zig>const std = @import("std");
<syntaxhighlight lang="zig">const std = @import("std");


const debug = std.debug;
const debug = std.debug;
Line 1,638: Line 1,638:
// isFinite(f128) is not implemented.
// isFinite(f128) is not implemented.
//debug.assert(!math.isFinite(infinite_f128));
//debug.assert(!math.isFinite(infinite_f128));
}</lang>
}</syntaxhighlight>


=={{header|zkl}}==
=={{header|zkl}}==
zkl doesn't like INF, NaN, etc but sorta knows about them:
zkl doesn't like INF, NaN, etc but sorta knows about them:
<lang zkl>1.5/0</lang>
<syntaxhighlight lang="zkl">1.5/0</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,649: Line 1,649:


=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==
ZX Spectrum BASIC has no infinity handling; <lang zxbasic>PRINT 1/0</lang> will be met with <pre>6 Number too big, 0:1</pre>
ZX Spectrum BASIC has no infinity handling; <syntaxhighlight lang="zxbasic">PRINT 1/0</syntaxhighlight> will be met with <pre>6 Number too big, 0:1</pre>
A quick doubling loop will get you halfway to the maximum floating point value:
A quick doubling loop will get you halfway to the maximum floating point value:
<lang zxbasic>10 LET z=1
<syntaxhighlight lang="zxbasic">10 LET z=1
20 PRINT z
20 PRINT z
30 LET z=z*2
30 LET z=z*2
40 GO TO 20</lang>
40 GO TO 20</syntaxhighlight>


Output will end with:
Output will end with: