RosettaCodeData/Task/Test-integerness/ALGOL-68/test-integerness.alg

31 lines
962 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
# set the required precision of LONG LONG values using #
# "PR precision n PR" if required #
2024-10-16 18:07:41 -07:00
# PR precision 24 PR # # not requied for ALGOL 68 Genie #
# the default precision is > 24 #
# and can't be reduced to 24 #
2023-07-01 11:58:00 -04:00
# returns TRUE if v has an integer value, FALSE otherwise #
OP ISINT = ( LONG LONG COMPL v )BOOL:
IF im OF v /= 0 THEN
2024-10-16 18:07:41 -07:00
# v has an imaginarh part #
2023-07-01 11:58:00 -04:00
FALSE
ELSE
# v has a real part only #
ENTIER re OF v = v
FI; # ISINT #
# test ISINT #
PROC test is int = ( LONG LONG COMPLEX v )VOID:
2024-10-16 18:07:41 -07:00
BEGIN
print( ( float( re OF v, -36, 28, 4 ), "_", float( im OF v, -36, 28, 4 ) ) );
print( ( IF ISINT v THEN " is " ELSE " is not " FI, "integral", newline ) )
END # test is int # ;
2023-07-01 11:58:00 -04:00
test is int( 1 );
test is int( 1.00000001 );
test is int( 4 I 3 );
test is int( 4.0 I 0 );
test is int( 123456789012345678901234 )