home *** CD-ROM | disk | FTP | other *** search
- { -----------------------------------------------------------------------------
-
- NOTICE:
-
- THESE MATERIALS are UNSUPPORTED by OSS! If you do not understand how to
- use them do not contact OSS for help! We will not teach you how to
- program in Pascal. If you find an error in these materials, feel free
- to SEND US A LETTER explaining the error, and how to fix it.
-
- THE BOTTOM LINE:
-
- Use it, enjoy it, but you are on your own when using these materials!
-
-
- DISCLAIMER:
-
- OSS makes no representations or warranties with respect to the contents
- hereof and specifically disclaim all warranties of merchantability or
- fitness for any particular purpose. This document is subject to change
- without notice.
-
- OSS provides these materials for use with Personal Pascal. Use them in
- any way you wish.
-
- -------------------------------------------------------------------------- }
-
-
- PROGRAM int;
-
- VAR
- r: real;
-
- FUNCTION rtrunc( n: real ): real;
-
- TYPE
- funny = RECORD
- CASE boolean OF
- true: ( r: real );
- false: ( b: PACKED ARRAY[ 0..5 ] OF byte );
- END;
-
- VAR
- temp: funny;
- exp: integer; { Exponent byte }
- last: 0..4;
-
- BEGIN
- temp.r := n;
- exp := temp.b[5] - $80;
- IF exp <= 0 THEN
- rtrunc := 0
- ELSE IF exp >= 40 THEN
- rtrunc := temp.r
- ELSE
- BEGIN
- last := exp DIV 8;
- temp.b[last] := temp.b[last] & shl( $FF, 8-(exp MOD 8));
- WHILE last < 4 DO
- BEGIN
- last := last + 1;
- temp.b[last] := 0;
- END;
- rtrunc := temp.r;
- END;
- END;
-
- FUNCTION rint( n: real ): real;
-
- VAR
- temp: real;
-
- BEGIN
- temp := rtrunc( n );
- IF (temp <> n) AND (n < 0) THEN
- temp := temp-1;
- rint := temp;
- END;
-
- FUNCTION rround( n: real ): real;
-
- BEGIN
- IF n >= 0 THEN
- rround := rtrunc( n+0.5 )
- ELSE
- rround := rtrunc( n-0.5 )
- END;
-
- BEGIN
- WHILE true DO
- BEGIN
- write( '>>' );
- readln( r );
- writeln( 'int(', r, ') = ', rint(r), rtrunc(r), rround(r) );
- END;
- END.
-