1 /* ====== BEGIN INCLUDE SEGMENT apl_floor_fcn.incl.pl1 ================================== */ 2 3 apl_floor_: 4 procedure (bv_value) returns (float); 5 6 /* Function to compute the floor of an apl value, taking 7 integer fuzz into account. In apl, for both the ceiling and floor functions, 8 if the input argument is within "integer fuzz" of its integer value, 9 then the result of the floor is this integer value. Otherwise, the result 10 is the normal floor (or ceiling). This procedure is followed so that 11 binary numbers which are within a few bits of the exact decimal 12 representation will behave properly. 13 14 Written 750714 by PG 15 */ 16 17 /* parameters */ 18 19 dcl bv_value float; 20 21 /* automatic */ 22 23 dcl (value, result) float; 24 25 /* builtins */ 26 27 dcl (abs, floor) builtin; 28 29 /* this function requires the following include files: 30 %include apl_number_data; 31 %include apl_ws_info; 32 */ 33 34 /* program */ 35 36 value = bv_value; /* copy argument for efficiency */ 37 result = floor (value + .5e0); /* form trial result */ 38 39 if abs (result - value) >= integer_fuzz /* if trial not eq input value */ 40 then result = floor (value); /* then use normal floor */ 41 42 return (result); 43 44 end apl_floor_; 45 46 /* ------ END INCLUDE SEGMENT apl_floor_fcn.incl.pl1 ---------------------------------- */