Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
35
Task/Test-integerness/Pascal/test-integerness.pas
Normal file
35
Task/Test-integerness/Pascal/test-integerness.pas
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
program integerness(output);
|
||||
|
||||
{ determines whether a `complex` also fits in `integer` ---------------- }
|
||||
function isRealIntegral(protected x: complex): Boolean;
|
||||
begin
|
||||
{ It constitutes an error if no value for `trunc(x)` exists, }
|
||||
{ thus check re(x) is in the range -maxInt..maxInt first. }
|
||||
isRealIntegral := (im(x) = 0.0) and_then
|
||||
(abs(re(x)) <= maxInt * 1.0) and_then
|
||||
(trunc(re(x)) * 1.0 = re(x))
|
||||
end;
|
||||
|
||||
{ calls isRealIntegral with zero imaginary part ------------------------ }
|
||||
function isIntegral(protected x: real): Boolean;
|
||||
begin
|
||||
isIntegral := isRealIntegral(cmplx(x * 1.0, 0.0))
|
||||
end;
|
||||
|
||||
{ Rosetta code test ---------------------------------------------------- }
|
||||
procedure test(protected x: complex);
|
||||
begin
|
||||
writeLn(re(x), ' + ', im(x), ' 𝒾 : ',
|
||||
isIntegral(re(x)), ' ', isRealIntegral(x))
|
||||
end;
|
||||
|
||||
{ === MAIN ============================================================= }
|
||||
begin
|
||||
test(cmplx(25.0, 0.0));
|
||||
test(cmplx(24.999999, 0.0));
|
||||
test(cmplx(25.000100, 0.0));
|
||||
test(cmplx(-2.1E120, 0.0));
|
||||
test(cmplx(-5E-2, 0.0));
|
||||
test(cmplx(5.0, 0.0));
|
||||
test(cmplx(5, -5));
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue