Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!mcsun!ukc!strath-cs!ex-dcs!exua!CDHWilli From: CDHWilli@exua.exeter.ac.uk (Charles Williams) Newsgroups: comp.lang.pascal Subject: Re: On error goto for pascal? Message-ID: Date: 4 May 91 23:03:18 GMT References: <9105030125.AA18493@cue.bc.ca> <1991May3.045355.14444@maytag.waterloo.edu> Sender: CDHWilli@exua.exeter.ac.uk Organization: Computer Unit. - University of Exeter. UK Lines: 35 In-reply-to: dmurdoch@watstat.waterloo.edu's message of 3 May 91 04:53:55 GMT # #>eg: if a user enters 2 real numbers and the program multiplies them #>together, and if the result is too large for even a real number to #>handle, the program will quit with an error. #>Instead I would like to check (via a variable or address) if the #>result was ok, before proceeding, else it will take steps to #>deal with the problem. # #This is hard. The Turbo and Object Professional packages from TurboPower #allow automatic recovery from some errors, but not floating point errors. #For those, the only way I know of is as follows: # #[IEEE stuff, FPU modes etc] # Checking status bits and using IEEE (pronounced I-trickery?) is fast but if portability is important then there are other approaches which are worth thinking about...for example: Q) Will A*B overflow? A) overflow:=(ln(MinReal+abs(A))+ln(MinReal+abs(B)))>ln(MaxReal); Q) Will A/B overflow? A1) overflow:=(ln(MinReal+abs(A))-ln(MinReal+abs(B)))>ln(MaxReal); A2) overflow:=abs(A/MaxReal)>abs(B); Where MaxReal and MinReal are the smallest and largest normalised postive reals. If you've got a good elementary function library then taking logs is remarkably fast. (If you want to hack-up the speed a bit then you can use variant record structures to extract the binary exponents from the reals by overlaying with a set and a couple of integers and use them in place of the logs, but then you're back in the tar-pit again...) =============================================================================== ================== World's most embarassing alias: l 'ls *.f' ================= ===============================================================================