/* 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 largest floating-point number. */
/* Modification to the specific calls may be required to suit a particular machine. */
DECLARE HUGE GENERIC (
HUGE6 WHEN (FLOAT DECIMAL (1)),
HUGE6 WHEN (FLOAT DECIMAL (2)),
HUGE6 WHEN (FLOAT DECIMAL (3)),
HUGE6 WHEN (FLOAT DECIMAL (4)),
HUGE6 WHEN (FLOAT DECIMAL (5)),
HUGE6 WHEN (FLOAT DECIMAL (6)),
HUGE15 WHEN (FLOAT DECIMAL (7)),
HUGE15 WHEN (FLOAT DECIMAL (8)),
HUGE15 WHEN (FLOAT) );
(OVERFLOW):
HUGE6:
PROCEDURE (X) OPTIONS (ORDER)
RETURNS (FLOAT DECIMAL);
DECLARE X FLOAT DECIMAL;
DECLARE Largest FLOAT DECIMAL STATIC INITIAL (0);
IF Largest ^= 0 THEN /* Once we know the largest value, we don't need*/
RETURN (Largest); /* to determine it again. */
ON OVERFLOW GO TO DONE;
Largest = 1;
DO WHILE ( '1'B);
Largest = Largest*2+1;
END;
DONE: REVERT OVERFLOW;
RETURN (Largest);
END HUGE6;
(OVERFLOW):
HUGE15:
PROCEDURE (X) OPTIONS (ORDER)
RETURNS (FLOAT DECIMAL (15) );
DECLARE X FLOAT DECIMAL(15);
DECLARE Largest FLOAT DECIMAL(15) STATIC INITIAL (0);
IF Largest ^= 0 THEN /* Once we know the largest value, we don't need*/
RETURN (Largest); /* to determine it again. */
ON OVERFLOW GO TO DONE;
Largest = 1;
DO WHILE ( '1'B);
Largest = Largest*2+1;
END;
DONE: REVERT OVERFLOW;
RETURN (Largest);
END HUGE15;