Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
49
Task/Test-integerness/Ada/test-integerness.ada
Normal file
49
Task/Test-integerness/Ada/test-integerness.ada
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
-- Big_Numbers is an Ada 2022 unit
|
||||
|
||||
with Ada.Numerics.Big_Numbers.Big_Integers,
|
||||
Ada.Numerics.Big_Numbers.Big_Reals,
|
||||
Ada.Numerics.Generic_Complex_Types,
|
||||
Ada.Text_IO;
|
||||
|
||||
use Ada.Numerics.Big_Numbers.Big_Integers,
|
||||
Ada.Numerics.Big_Numbers.Big_Reals,
|
||||
Ada.Text_IO;
|
||||
|
||||
procedure Test_Integer is
|
||||
-- These are the only numerical types defined in package
|
||||
-- "Standard" which is always incuded. 'Base also covers anything
|
||||
-- with the same Base types.
|
||||
function Is_Integer (N : Integer'Base) return Boolean is (True);
|
||||
function Is_Integer (N : Float'Base) return Boolean is (Float'Base'Floor (N) = N);
|
||||
|
||||
-- Additional types defined in the standard library.
|
||||
function Is_Integer (N : Big_Integer) return Boolean is (True);
|
||||
|
||||
-- The type says real, but these are rational approximations of
|
||||
-- real numbers.
|
||||
function Is_Integer (N : Big_Real) return Boolean is (Denominator (N) = 1);
|
||||
|
||||
package Complex_Float is new Ada.Numerics.Generic_Complex_Types (Float);
|
||||
use Complex_Float;
|
||||
|
||||
function Is_Integer (N : Complex) return Boolean
|
||||
is (Im (N) = 0.0 and then Is_Integer (Re (N)));
|
||||
|
||||
Int_One : Integer := 1;
|
||||
Flo_One : Float := 1.0;
|
||||
Flo_OneH : Float := 1.5;
|
||||
BInt_One : Big_Integer := To_Big_Integer (1);
|
||||
BFlo_One : Big_Real := To_Big_Real (1);
|
||||
BFlo_OneH : Big_Real := From_String ("1.5");
|
||||
CInt_One : Complex := 1.0 + 0.0 * I;
|
||||
CInt_OneI : Complex := 1.0 + 1.0 * I;
|
||||
begin
|
||||
Put_Line (Int_One'Image & " is integer? " & Is_Integer (Int_One)'Image);
|
||||
Put_Line (Flo_One'Image & " is integer? " & Is_Integer (Flo_One)'Image);
|
||||
Put_Line (Flo_OneH'Image & " is integer? " & Is_Integer (Flo_OneH)'Image);
|
||||
Put_Line (BInt_One'Image & " is integer? " & Is_Integer (BInt_One)'Image);
|
||||
Put_Line (BFlo_One'Image & " is integer? " & Is_Integer (BFlo_One)'Image);
|
||||
Put_Line (BFlo_OneH'Image & " is integer? " & Is_Integer (BFlo_OneH)'Image);
|
||||
Put_Line (CInt_One'Image & " is integer? " & Is_Integer (CInt_One)'Image);
|
||||
Put_Line (CInt_OneI'Image & " is integer? " & Is_Integer (CInt_OneI)'Image);
|
||||
end Test_Integer;
|
||||
3
Task/Test-integerness/DuckDB/test-integerness-1.duckdb
Normal file
3
Task/Test-integerness/DuckDB/test-integerness-1.duckdb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
create type Complex as struct (r float, i float);
|
||||
|
||||
create type Rational as struct (n integer, d integer);
|
||||
16
Task/Test-integerness/DuckDB/test-integerness-2.duckdb
Normal file
16
Task/Test-integerness/DuckDB/test-integerness-2.duckdb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
create or replace function number_integerp(x) as (
|
||||
x = trunc(x)
|
||||
);
|
||||
|
||||
# Return true iff x has the type signature of a Rational
|
||||
# with the denominator dividing the numerator evenly.
|
||||
create or replace function rational_integerp(x) as (
|
||||
typeof(x) = 'STRUCT(n INTEGER, d INTEGER)'
|
||||
and x.n % x.d = 0
|
||||
);
|
||||
|
||||
# Return true if x can be cast to a Complex with
|
||||
# the imaginary part equal to 0 and an integer real part.
|
||||
create or replace function complex_integerp(x) as (
|
||||
(x::Complex).i = 0 and number_integerp(x.r)
|
||||
);
|
||||
37
Task/Test-integerness/Pluto/test-integerness.pluto
Normal file
37
Task/Test-integerness/Pluto/test-integerness.pluto
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
require "complex"
|
||||
require "rat"
|
||||
require "table2"
|
||||
local fmt = require "fmt"
|
||||
|
||||
local tests1 = {25.000000, 24.999999, 25.000100}
|
||||
local tests2 = {-2.1e120}
|
||||
local tests3 = {-5e-2, 0/0, 1/0}
|
||||
local tests4 = {complex.of(5, 0), complex.of(5, -5)}
|
||||
local tests5 = {rat.of(24, 8), rat.of(-5, 1), rat.of(17, 2)}
|
||||
local tests6 = tests1:joined({-5e-2})
|
||||
|
||||
print("Using exact arithmetic:\n")
|
||||
for tests1 as t do
|
||||
fmt.print(" %-9.6f is integer? %s", t, t % 1 == 0)
|
||||
end
|
||||
print()
|
||||
for tests2 as t do
|
||||
fmt.print(" %-9g is integer? %s", t, t % 1 == 0)
|
||||
end
|
||||
for tests3 as t do
|
||||
fmt.print(" %-9.6f is integer? %s", t, t % 1 == 0)
|
||||
end
|
||||
print()
|
||||
for tests4 as t do
|
||||
fmt.print(" %-9s is integer? %s", t, t:getReal() % 1 == 0 and t:getImag() == 0)
|
||||
end
|
||||
print()
|
||||
for tests5 as t do
|
||||
fmt.print(" %-9s is integer? %s", t, t:isint())
|
||||
end
|
||||
print("\nWithin a tolerance of 0.00001:\n")
|
||||
local tol = 0.00001
|
||||
for tests6 as t do
|
||||
local d = math.abs(t - math.round(t))
|
||||
fmt.print(" %9.6f is integer? %s", t, d <= tol)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue