1*48081Sbostic(* 2*48081Sbostic * Copyright (c) 1980 The Regents of the University of California. 3*48081Sbostic * All rights reserved. 4*48081Sbostic * 5*48081Sbostic * %sccs.include.redist.c% 6*48081Sbostic * 7*48081Sbostic * @(#)overflow.p 5.1 (Berkeley) 04/16/91 8*48081Sbostic *) 9*48081Sbostic 10*48081Sbosticprogram fpexceptions(input,output); 11*48081Sbostic type 12*48081Sbostic fperrorkind = ( fperrorfirst, 13*48081Sbostic overflow,underflow,divideby0,domain, 14*48081Sbostic fperrolast ); 15*48081Sbostic var 16*48081Sbostic request : fperrorkind; 17*48081Sbostic procedure genoverflow; 18*48081Sbostic var 19*48081Sbostic i : integer; 20*48081Sbostic r : real; 21*48081Sbostic begin 22*48081Sbostic r := 2.0; 23*48081Sbostic for i := 1 to 1000 do begin 24*48081Sbostic r := r * r; 25*48081Sbostic end; 26*48081Sbostic writeln('this machine handles more than 2^1000'); 27*48081Sbostic end; 28*48081Sbostic procedure genunderflow; 29*48081Sbostic var 30*48081Sbostic i : integer; 31*48081Sbostic r : real; 32*48081Sbostic begin 33*48081Sbostic r := 0.5; 34*48081Sbostic for i := 1 to 1000 do begin 35*48081Sbostic r := r * r; 36*48081Sbostic end; 37*48081Sbostic writeln('this machine handles more than 2^-1000'); 38*48081Sbostic end; 39*48081Sbostic procedure gendivideby0; 40*48081Sbostic var 41*48081Sbostic r : real; 42*48081Sbostic begin 43*48081Sbostic r := 17.0; 44*48081Sbostic r := r - r; {should be 0.0} 45*48081Sbostic r := 17.0 / r; 46*48081Sbostic writeln('i wonder what r is?', r); 47*48081Sbostic end; 48*48081Sbostic procedure gendomain; 49*48081Sbostic var 50*48081Sbostic r : real; 51*48081Sbostic begin 52*48081Sbostic r := -17.0; 53*48081Sbostic r := sqrt(r); 54*48081Sbostic writeln('i wonder what r is?', r); 55*48081Sbostic end; 56*48081Sbostic begin 57*48081Sbostic write('which do you want ('); 58*48081Sbostic for request := succ(fperrorfirst) to pred(fperrolast) do begin 59*48081Sbostic {this isn't standard pascal.} 60*48081Sbostic write( ' ', request); 61*48081Sbostic end; 62*48081Sbostic write(' ): '); 63*48081Sbostic {neither is this, but it sure is convenient.} 64*48081Sbostic readln(request); 65*48081Sbostic if request in [overflow,underflow,divideby0,domain] then begin 66*48081Sbostic writeln('one ', request, ' coming right down'); 67*48081Sbostic case request of 68*48081Sbostic overflow: genoverflow; 69*48081Sbostic underflow: genunderflow; 70*48081Sbostic divideby0: gendivideby0; 71*48081Sbostic domain: gendomain; 72*48081Sbostic end; 73*48081Sbostic end else begin 74*48081Sbostic {default:} 75*48081Sbostic writeln('oh, never mind'); 76*48081Sbostic end; 77*48081Sbostic end. 78*48081Sbostic 79