Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
category:
- Discrete math
from: http://rosettacode.org/wiki/Infinity
note: Basic language learning

10
Task/Infinity/00-TASK.txt Normal file
View file

@ -0,0 +1,10 @@
;Task:
Write a function which tests if infinity is supported for floating point numbers (this step should be omitted for languages where the language specification already demands the existence of infinity, e.g. by demanding [[IEEE]] numbers), and if so, returns positive infinity.   Otherwise, return the largest possible positive floating point number.
For languages with several floating point types, use the type of the literal constant   '''1.5'''   as floating point type.
;Related task:
*   [[Extreme floating point values]]
<br><br>

View file

@ -0,0 +1 @@
print(Float.infinity)

View file

@ -0,0 +1,7 @@
printf(($"max int: "gl$,max int));
printf(($"long max int: "gl$,long max int));
printf(($"long long max int: "gl$,long long max int));
printf(($"max real: "gl$,max real));
printf(($"long max real: "gl$,long max real));
printf(($"long long max real: "gl$,long long max real));
printf(($"error char: "gl$,error char))

View file

@ -0,0 +1 @@
inf {/}

View file

@ -0,0 +1,6 @@
BEGIN {
k=1;
while (2^(k-1) < 2^k) k++;
INF = 2^k;
print INF;
}

View file

@ -0,0 +1,2 @@
trace(5 / 0); // outputs "Infinity"
trace(isFinite(5 / 0)); // outputs "false"

View file

@ -0,0 +1,24 @@
with Ada.Text_IO; use Ada.Text_IO;
procedure Infinities is
function Sup return Float is -- Only for predefined types
Result : Float := Float'Last;
begin
if not Float'Machine_Overflows then
Result := Float'Succ (Result);
end if;
return Result;
end Sup;
function Inf return Float is -- Only for predefined types
Result : Float := Float'First;
begin
if not Float'Machine_Overflows then
Result := Float'Pred (Result);
end if;
return Result;
end Inf;
begin
Put_Line ("Supremum" & Float'Image (Sup));
Put_Line ("Infimum " & Float'Image (Inf));
end Infinities;

View file

@ -0,0 +1,26 @@
with Ada.Text_IO; use Ada.Text_IO;
procedure Infinities is
type Real is digits 5 range -10.0..10.0;
function Sup return Real is
Result : Real := Real'Last;
begin
return Real'Succ (Result);
exception
when Constraint_Error =>
return Result;
end Sup;
function Inf return Real is
Result : Real := Real'First;
begin
return Real'Pred (Result);
exception
when Constraint_Error =>
return Result;
end Inf;
begin
Put_Line ("Supremum" & Real'Image (Sup));
Put_Line ("Infimum " & Real'Image (Inf));
end Infinities;

View file

@ -0,0 +1 @@
subtype Safe_Float is Float range Float'Range;

View file

@ -0,0 +1,3 @@
use std
printf "%f\n" atof "infinity" (: this prints "inf" :)
#extern :atof<text>: -> real

View file

@ -0,0 +1,2 @@
print infinity
print neg infinity

View file

@ -0,0 +1,7 @@
onerror TratoError
infinity = 1e300*1e300
end
TratoError:
if lasterror = 29 then print lasterrormessage
return

View file

@ -0,0 +1,19 @@
*FLOAT 64
PRINT FNinfinity
END
DEF FNinfinity
LOCAL supported%, maxpos, prev, inct
supported% = TRUE
ON ERROR LOCAL supported% = FALSE
IF supported% THEN = 1/0
RESTORE ERROR
inct = 1E10
REPEAT
prev = maxpos
inct *= 2
ON ERROR LOCAL inct /= 2
maxpos += inct
RESTORE ERROR
UNTIL maxpos = prev
= maxpos

View file

@ -0,0 +1 @@
10 print 1/0

View file

@ -0,0 +1,9 @@
#include <limits>
double inf()
{
if (std::numeric_limits<double>::has_infinity)
return std::numeric_limits<double>::infinity();
else
return std::numeric_limits<double>::max();
}

View file

@ -0,0 +1,14 @@
using System;
class Program
{
static double PositiveInfinity()
{
return double.PositiveInfinity;
}
static void Main()
{
Console.WriteLine(PositiveInfinity());
}
}

View file

@ -0,0 +1 @@
Infinity

View file

@ -0,0 +1,11 @@
#include <math.h> /* HUGE_VAL */
#include <stdio.h> /* printf() */
double inf(void) {
return HUGE_VAL;
}
int main() {
printf("%g\n", inf());
return 0;
}

View file

@ -0,0 +1,9 @@
#define _ISOC99_SOURCE
#include <math.h>
#include <stdio.h>
int main() {
printf("%g\n", INFINITY);
return 0;
}

View file

@ -0,0 +1,3 @@
##Inf ;; same as Double/POSITIVE_INFINITY
##-Inf ;; same as Double/NEGATIVE_INFINITY
(Double/isInfinite ##Inf) ;; true

View file

@ -0,0 +1 @@
Infinity

View file

@ -0,0 +1,2 @@
Number.POSITIVE_INFINITY
Number.NEGATIVE_INFINITY

View file

@ -0,0 +1 @@
isFinite x

View file

@ -0,0 +1,13 @@
> (apropos "MOST-POSITIVE" :cl)
MOST-POSITIVE-LONG-FLOAT, value: 1.7976931348623158D308
MOST-POSITIVE-SHORT-FLOAT, value: 3.4028172S38
MOST-POSITIVE-SINGLE-FLOAT, value: 3.4028235E38
MOST-POSITIVE-DOUBLE-FLOAT, value: 1.7976931348623158D308
MOST-POSITIVE-FIXNUM, value: 536870911
> (apropos "MOST-NEGATIVE" :cl)
MOST-NEGATIVE-SINGLE-FLOAT, value: -3.4028235E38
MOST-NEGATIVE-LONG-FLOAT, value: -1.7976931348623158D308
MOST-NEGATIVE-SHORT-FLOAT, value: -3.4028172S38
MOST-NEGATIVE-DOUBLE-FLOAT, value: -1.7976931348623158D308
MOST-NEGATIVE-FIXNUM, value: -536870912

View file

@ -0,0 +1,10 @@
MODULE Infinity;
IMPORT StdLog;
PROCEDURE Do*;
VAR
x: REAL;
BEGIN
x := 1 / 0;
StdLog.String("x:> ");StdLog.Real(x);StdLog.Ln
END Do;

View file

@ -0,0 +1,5 @@
auto inf() {
return typeof(1.5).infinity;
}
void main() {}

View file

@ -0,0 +1,2 @@
Infinity = 1.0 / 0.0;
NegInfinity = -1.0 / 0.0;

View file

@ -0,0 +1 @@
Math.IsInfinite()

View file

@ -0,0 +1 @@
func infinityTask() => Float.Infinity

View file

@ -0,0 +1,3 @@
def infinityTask() {
return Infinity # predefined variable holding positive infinity
}

View file

@ -0,0 +1,15 @@
PROGRAM INFINITY
EXCEPTION
PRINT("INFINITY")
ESCI%=TRUE
END EXCEPTION
BEGIN
ESCI%=FALSE
K=1
WHILE 2^K>0 DO
EXIT IF ESCI%
K+=1
END WHILE
END PROGRAM

View file

@ -0,0 +1,18 @@
class
APPLICATION
inherit
ARGUMENTS
create
make
feature {NONE} -- Initialization
number:REAL_64
make
-- Run application.
do
number := 2^2000
print(number)
print("%N")
print(number.is_positive_infinity)
print("%N")
end
end

View file

@ -0,0 +1,3 @@
constant infinity = 1E400
? infinity -- outputs "inf"

View file

@ -0,0 +1 @@
printfn "%f" (1.0/0.0)

View file

@ -0,0 +1 @@
1/0.

View file

@ -0,0 +1,5 @@
class Main
{
static Float getInfinity () { Float.posInf }
public static Void main () { echo (getInfinity ()) }
}

View file

@ -0,0 +1,7 @@
: inf ( -- f ) 1e 0e f/ ;
inf f. \ implementation specific. GNU Forth will output "inf"
: inf? ( f -- ? ) s" MAX-FLOAT" environment? drop f> ;
\ IEEE infinity is the only value for which this will return true
: has-inf ( -- ? ) ['] inf catch if false else inf? then ;

View file

@ -0,0 +1,18 @@
program to_f_the_ineffable
use, intrinsic :: ieee_arithmetic
integer :: i
real dimension(2) :: y, x = (/ 30, ieee_value(y,ieee_positive_inf) /)
do i = 1, 2
if (ieee_support_datatype(x(i))) then
if (ieee_is_finite(x(i))) then
print *, 'x(',i,') is finite'
else
print *, 'x(',i,') is infinite'
end if
else
print *, 'x(',i,') is not in an IEEE-supported format'
end if
end do
end program to_f_the_ineffable

View file

@ -0,0 +1,2 @@
real :: x
real :: huge_real = huge(x)

View file

@ -0,0 +1,8 @@
' FB 1.05.0 Win64
#Include "crt/math.bi"
#Print Typeof(1.5) ' Prints DOUBLE at compile time
Dim d As Typeof(1.5) = INFINITY
Print d; " (String representation of Positive Infinity)"
Sleep

View file

@ -0,0 +1,3 @@
printf @"%g", INFINITY
HandleEvents

View file

@ -0,0 +1,9 @@
# Floating point infinity
inf := FLOAT_INT(1) / FLOAT_INT(0);
IS_FLOAT(inf);
#true;
# GAP has also a formal ''infinity'' value
infinity in Cyclotomics;
# true

View file

@ -0,0 +1,19 @@
package main
import (
"fmt"
"math"
)
// function called for by task
func posInf() float64 {
return math.Inf(1) // argument specifies positive infinity
}
func main() {
x := 1.5 // type of x determined by literal
// that this compiles demonstrates that PosInf returns same type as x,
// the type specified by the task.
x = posInf() // test function
fmt.Println(x, math.IsInf(x, 1)) // demonstrate result
}

View file

@ -0,0 +1 @@
def biggest = { Double.POSITIVE_INFINITY }

View file

@ -0,0 +1,2 @@
println biggest()
printf ( "0x%xL \n", Double.doubleToLongBits(biggest()) )

View file

@ -0,0 +1,8 @@
maxRealFloat :: RealFloat a => a -> a
maxRealFloat x = encodeFloat b (e-1) `asTypeOf` x where
b = floatRadix x - 1
(_,e) = floatRange x
infinity :: RealFloat a => a
infinity = if isInfinite inf then inf else maxRealFloat 1.0 where
inf = 1/0

View file

@ -0,0 +1,4 @@
*Main> infinity :: Float
Infinity
*Main> infinity :: Double
Infinity

View file

@ -0,0 +1,4 @@
Prelude> 1 / 0 :: Float
Infinity
Prelude> 1 / 0 :: Double
Infinity

View file

@ -0,0 +1,4 @@
Prelude> read "Infinity" :: Float
Infinity
Prelude> read "Infinity" :: Double
Infinity

View file

@ -0,0 +1,2 @@
print, !Values.f_infinity ;; for normal floats or
print, !Values.D_infinity ;; for doubles

View file

@ -0,0 +1 @@
PRINT INF

View file

@ -0,0 +1 @@
inf := 1/0

View file

@ -0,0 +1 @@
Number constants inf

View file

@ -0,0 +1,6 @@
_ * 5 NB. multiplying infinity to 5 results in infinity
_
5 % _ NB. dividing 5 by infinity results in 0
0
5 % 0 NB. dividing 5 by 0 results in infinity
_

View file

@ -0,0 +1,2 @@
double infinity = Double.POSITIVE_INFINITY; //defined as 1.0/0.0
Double.isInfinite(infinity); //true

View file

@ -0,0 +1,3 @@
public static double getInf(){
return Double.POSITIVE_INFINITY;
}

View file

@ -0,0 +1 @@
double biggestNumber = Double.MAX_VALUE;

View file

@ -0,0 +1 @@
Infinity

View file

@ -0,0 +1,2 @@
Number.POSITIVE_INFINITY
Number.NEGATIVE_INFINITY

View file

@ -0,0 +1 @@
isFinite(x)

View file

@ -0,0 +1 @@
1 1024 ldexp dup neg stack.

View file

@ -0,0 +1 @@
def infinite: 1e1000;

View file

@ -0,0 +1 @@
def isinfinite: . == infinite;

View file

@ -0,0 +1,2 @@
julia> julia> Inf32 == Inf64 == Inf16 == Inf
true

View file

@ -0,0 +1,49 @@
/ Integer infinities
/ 0I is just 2147483647
/ -0I is just -2147483647
/ -2147483648 is a special "null integer"(NaN) 0N
0I*0I
1
0I-0I
0
0I+1
0N
0I+2
-0I
0I+3 / -0I+1
-2147483646
0I-1
2147483646
0I%0I
1
0I^2
4.611686e+18
0I^0I
0i
0I^-0I
0.0
1%0
0I
0%0
0
0i^2
0i
0i^0i
0i
/ Floating point infinities in K are something like
/ IEEE 754 values
/ Also there is floating point NaN -- 0n
0i+1
0i
0i*0i
0i
0i-0i
0n
0i%0i
0n
0i%0n
0n
/ but
0.0%0.0
0.0

View file

@ -0,0 +1,3 @@
1e300 dup mult tostr "inf" equal ["Infinity" print] if
" " input

View file

@ -0,0 +1,11 @@
fun main(args: Array<String>) {
val p = Double.POSITIVE_INFINITY // +∞
println(p.isInfinite()) // true
println(p.isFinite()) // false
println("${p < 0} ${p > 0}") // false true
val n = Double.NEGATIVE_INFINITY // -∞
println(n.isInfinite()) // true
println(n.isFinite()) // false
println("${n < 0} ${n > 0}") // true false
}

View file

@ -0,0 +1,8 @@
{/ 1 0}
-> Infinity
{/ 1 Infinity}
-> 0
{< {pow 10 100} Infinity}
-> true
{< {pow 10 1000} Infinity}
-> false

View file

@ -0,0 +1,3 @@
infinity
'<br />'
infinity -> type

View file

@ -0,0 +1,7 @@
x = (1-power(2, -53)) * power(2, 1023) * 2
put ilk(x), x
-- #float 1.79769313486232e308
x = (1-power(2, -53)) * power(2, 1023) * 3
put ilk(x), x, -x
-- #float INF -INF

View file

@ -0,0 +1,3 @@
function infinity()
return 1/0 --lua uses unboxed C floats for all numbers
end

View file

@ -0,0 +1,47 @@
Rem : locale 1033
Module CheckIt {
Form 66,40
Cls 5
Pen 14
\\ Ensure True/False for Print boolean (else -1/0)
\\ from m2000 console use statement Switches without Set.
\\ use Monitor statement to see all switches.
Set Switches "+SBL"
IF version<9.4 then exit
IF version=9.4 and revision<25 then exit
Function Infinity(positive=True) {
buffer clear inf as byte*8
m=0x7F
if not positive then m+=128
return inf, 7:=m, 6:=0xF0
=eval(inf, 0 as double)
}
K=Infinity(false)
L=Infinity()
Function TestNegativeInfinity(k) {
=str$(k, 1033) = "-1.#INF"
}
Function TestPositiveInfinity(k) {
=str$(k, 1033) = "1.#INF"
}
Function TestInvalid {
=str$(Number, 1033) = "-1.#IND"
}
Pen 11 {Print " True True"}
Print TestNegativeInfinity(K), TestPositiveInfinity(L)
Pen 11 {Print " -1.#INF 1.#INF -1.#INF 1.#INF -1.#INF 1.#INF"}
Print K, L, K*100, L*100, K+K, L+L
M=K/L
Pen 11 {Print " -1.#IND -1.#IND True True" }
Print K/L, L/K, TestInvalid(M), TestInvalid(K/L)
M=K+L
Pen 11 {Print " -1.#IND -1.#IND -1.#IND True True"}
Print M, K+L, L+K, TestInvalid(M), TestInvalid(K+L)
Pen 11 {Print " -1.#INF 1.#INF"}
Print 1+K+2, 1+L+2
Pen 11 {Print " -1.#INF"}
Print K-L
Pen 11 {Print " 1.#INF"}
Print L-K
}
Checkit

View file

@ -0,0 +1,2 @@
a = +Inf;
isinf(a)

View file

@ -0,0 +1,2 @@
> proc() Float(infinity) end();
Float(infinity)

View file

@ -0,0 +1,2 @@
> proc() HFloat(infinity) end();
HFloat(infinity)

View file

@ -0,0 +1,4 @@
Sum[1/n^2,{n,Infinity}]
1/Infinity
Integrate[Exp[-x^2], {x, -Infinity, Infinity}]
10^100 < Infinity

View file

@ -0,0 +1 @@
Integrate[Exp[-x^2]/(x^2 - 1), {x, 0, DirectedInfinity[Exp[I Pi/4]]}]

View file

@ -0,0 +1,14 @@
/* Maxima has inf (positive infinity) and minf (negative infinity) */
declare(x, real)$
is(x < inf);
/* true */
is(x > minf);
/* true */
/* However, it is an error to try to divide by zero, even with floating-point numbers */
1.0/0.0;
/* expt: undefined: 0 to a negative exponent.
-- an error. To debug this try: debugmode(true); */

View file

@ -0,0 +1 @@
infinity := 4095.99998;

View file

@ -0,0 +1,2 @@
posInfinity = 1/0
print posInfinity

View file

@ -0,0 +1,8 @@
MODULE inf;
IMPORT InOut;
BEGIN
InOut.WriteReal (1.0 / 0.0, 12, 12);
InOut.WriteLn
END inf.

View file

@ -0,0 +1,4 @@
jan@Beryllium:~/modula/rosetta$ inf
**** RUNTIME ERROR bound check error
Floating point exception

View file

@ -0,0 +1,8 @@
MODULE Inf EXPORTS Main;
IMPORT IO, IEEESpecial;
BEGIN
IO.PutReal(IEEESpecial.RealPosInf);
IO.Put("\n");
END Inf.

View file

@ -0,0 +1 @@
10 PRINT 1/0

View file

@ -0,0 +1,4 @@
def posinf = double.PositiveInfinity;
def a = IsInfinity(posinf); // a = true
def b = IsNegativeInfinity(posinf); // b = false
def c = IsPositiveInfinity(posinf); // c = true

View file

@ -0,0 +1 @@
Inf

View file

@ -0,0 +1,2 @@
var f = Inf
echo f

View file

@ -0,0 +1 @@
infinity

View file

@ -0,0 +1 @@
10 1000.0 powf dup println dup neg println 1 swap / println

View file

@ -0,0 +1,8 @@
(define (infinite? x) (or (equal? x +inf.0) (equal? x -inf.0)))
(infinite? +inf.0) ==> #true
(infinite? -inf.0) ==> #true
(infinite? +nan.0) ==> #false
(infinite? 123456) ==> #false
(infinite? 1/3456) ==> #false
(infinite? 17+28i) ==> #false

View file

@ -0,0 +1,5 @@
MESSAGE
1.0 / 0.0 SKIP
-1.0 / 0.0 SKIP(1)
( 1.0 / 0.0 ) = ( -1.0 / 0.0 )
VIEW-AS ALERT-BOX.

View file

@ -0,0 +1,20 @@
print 1.5e-400 '0
print 1.5e400 '#INF
print -1.5e400 '#-INF
print 0/-1.5 '-0
print 1.5/0 '#INF
print -1.5/0 '#-INF
print 0/0 '#qNAN
function f() as double
return -1.5/0
end function
print f '#-INF

View file

@ -0,0 +1,13 @@
declare
PosInf = 1./0.
NegInf = ~1./0.
in
{Show PosInf}
{Show NegInf}
%% some assertion
42. / PosInf = 0.
42. / NegInf = 0.
PosInf * PosInf = PosInf
PosInf * NegInf = NegInf
NegInf * NegInf = PosInf

View file

@ -0,0 +1 @@
+oo

View file

@ -0,0 +1,3 @@
infty()={
[1] \\ Used for many functions like intnum
};

View file

@ -0,0 +1 @@
INF

View file

@ -0,0 +1,3 @@
declare x float, y float (15), z float (18);
put skip list (huge(x), huge(y), huge(z));

View file

@ -0,0 +1,2 @@
my $x = 0 + "inf";
my $y = 0 + "+inf";

View file

@ -0,0 +1,2 @@
my $x = 0 - "inf";
my $y = 0 + "-inf";

Some files were not shown because too many files have changed in this diff Show more