/* Copyright (c) 1996 by R. A. Vowels, from "Introduction to PL/I, Algorithms, and */
/* Structured Programming". Permission is given to reproduce and to use these procedures */
/* as part of a program, and to include them as part of a larger work to be sold for profit. */
/* However, the user is not permitted to sell the procedures separately. Provided always */
/* that these procedures and this copyright notice are reproduced in full. */
/* This generic function computes the smallest floating-point number. */
/* Modification to the specific calls may be required to suit a particular machine. */
DECLARE TINY GENERIC (
TINY6 WHEN (FLOAT DECIMAL (1)),
TINY6 WHEN (FLOAT DECIMAL (2)),
TINY6 WHEN (FLOAT DECIMAL (3)),
TINY6 WHEN (FLOAT DECIMAL (4)),
TINY6 WHEN (FLOAT DECIMAL (5)),
TINY6 WHEN (FLOAT DECIMAL (6)),
TINY15 WHEN (FLOAT DECIMAL (7)),
TINY15 WHEN (FLOAT DECIMAL (8)),
TINY15 WHEN (FLOAT) );
(UNDERFLOW):
TINY6:
PROCEDURE (X) OPTIONS (ORDER)
RETURNS (FLOAT DECIMAL);
DECLARE X FLOAT DECIMAL;
DECLARE Smallest FLOAT DECIMAL STATIC INITIAL (0);
IF Smallest ^= 0 THEN /* Once we know the smallest value, we don't need */
RETURN (Smallest); /* to determine it again. */
ON UNDERFLOW GO TO DONE;
Smallest = 1;
DO WHILE (Smallest ^= 0);
Smallest = Smallest/2;
END;
DONE: REVERT UNDERFLOW;
RETURN (Smallest);
END TINY6;
(UNDERFLOW):
TINY15:
PROCEDURE (X) OPTIONS (ORDER)
RETURNS (FLOAT DECIMAL (15));
DECLARE X FLOAT DECIMAL (15);
DECLARE Smallest FLOAT DECIMAL (15) STATIC INITIAL (0);
IF Smallest ^= 0 THEN /* Once we know the smallest value, we don't need */
RETURN (Smallest); /* to determine it again. */
ON UNDERFLOW GO TO DONE;
Smallest = 1;
DO WHILE (Smallest ^= 0);
Smallest = Smallest/2;
END;
DONE: REVERT UNDERFLOW;
RETURN (Smallest);
END TINY15;