148081Sbostic(* 2*62156Sbostic * Copyright (c) 1980, 1993 3*62156Sbostic * The Regents of the University of California. All rights reserved. 448081Sbostic * 548081Sbostic * %sccs.include.redist.c% 648081Sbostic * 7*62156Sbostic * @(#)overflow.p 8.1 (Berkeley) 06/06/93 848081Sbostic *) 948081Sbostic 1048081Sbosticprogram fpexceptions(input,output); 1148081Sbostic type 1248081Sbostic fperrorkind = ( fperrorfirst, 1348081Sbostic overflow,underflow,divideby0,domain, 1448081Sbostic fperrolast ); 1548081Sbostic var 1648081Sbostic request : fperrorkind; 1748081Sbostic procedure genoverflow; 1848081Sbostic var 1948081Sbostic i : integer; 2048081Sbostic r : real; 2148081Sbostic begin 2248081Sbostic r := 2.0; 2348081Sbostic for i := 1 to 1000 do begin 2448081Sbostic r := r * r; 2548081Sbostic end; 2648081Sbostic writeln('this machine handles more than 2^1000'); 2748081Sbostic end; 2848081Sbostic procedure genunderflow; 2948081Sbostic var 3048081Sbostic i : integer; 3148081Sbostic r : real; 3248081Sbostic begin 3348081Sbostic r := 0.5; 3448081Sbostic for i := 1 to 1000 do begin 3548081Sbostic r := r * r; 3648081Sbostic end; 3748081Sbostic writeln('this machine handles more than 2^-1000'); 3848081Sbostic end; 3948081Sbostic procedure gendivideby0; 4048081Sbostic var 4148081Sbostic r : real; 4248081Sbostic begin 4348081Sbostic r := 17.0; 4448081Sbostic r := r - r; {should be 0.0} 4548081Sbostic r := 17.0 / r; 4648081Sbostic writeln('i wonder what r is?', r); 4748081Sbostic end; 4848081Sbostic procedure gendomain; 4948081Sbostic var 5048081Sbostic r : real; 5148081Sbostic begin 5248081Sbostic r := -17.0; 5348081Sbostic r := sqrt(r); 5448081Sbostic writeln('i wonder what r is?', r); 5548081Sbostic end; 5648081Sbostic begin 5748081Sbostic write('which do you want ('); 5848081Sbostic for request := succ(fperrorfirst) to pred(fperrolast) do begin 5948081Sbostic {this isn't standard pascal.} 6048081Sbostic write( ' ', request); 6148081Sbostic end; 6248081Sbostic write(' ): '); 6348081Sbostic {neither is this, but it sure is convenient.} 6448081Sbostic readln(request); 6548081Sbostic if request in [overflow,underflow,divideby0,domain] then begin 6648081Sbostic writeln('one ', request, ' coming right down'); 6748081Sbostic case request of 6848081Sbostic overflow: genoverflow; 6948081Sbostic underflow: genunderflow; 7048081Sbostic divideby0: gendivideby0; 7148081Sbostic domain: gendomain; 7248081Sbostic end; 7348081Sbostic end else begin 7448081Sbostic {default:} 7548081Sbostic writeln('oh, never mind'); 7648081Sbostic end; 7748081Sbostic end. 7848081Sbostic 79