Article View: sci.math.num-analysis
Article #1166Robust division subroutine
From: Eric Kostelich
Date: Tue, 12 Sep 1995 17:02
Date: Tue, 12 Sep 1995 17:02
32 lines
1825 bytes
1825 bytes
I want to write a C routine like int safediv(double x, double y, double *result) that performs the computation *result = x/y when x and y are valid floating-point doubles and x/y can be represented on the processor without overflow or underflow. (I'm interested in machines that implement IEEE arithmetic.) Of course, a number of errors could occur: x and y might be NaN's, y might be 0, or x/y might overflow or underflow. In such cases, I want savediv to return a negative value without raising an arithmetic exception. Otherwise, if x/y can be computed, savediv should put the ratio in *result and return 0. In other words, to the extent feasible, I'd like to have a bulletproof division subroutine. My questions: (1) is there a library of similar routines that is publicly available? (2) if not, what is the best way to go about writing such a routine? Robustness is more important than speed for my application. (3) Is there a portable way to implement this routine? By "portable" I mean a routine that operates on, say, Sun Solaris, IBM AIX, SGI Irix, DEC Alpha and HP-UX workstations. Other requirements: savediv should operate the same way regardless of how the remainder of the program treats floating point exceptions, and the routine must not affect how the remainder of the program treats floating point exceptions. All insights and suggestions are appreciated.
Technical Details
Message-ID:
<434ef2$210@keck2.umd.edu>Path:
arc1-ca.pugleaf.net!keck2.umd.edu!not-for-mailShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!keck2.umd.edu!not-for-mail From: kostelic@Glue.umd.edu (Eric Kostelich) Newsgroups: sci.math.num-analysis,comp.lang.c,comp.unix.misc Subject: Robust division subroutine Date: 12 Sep 1995 13:02:26 -0400 Organization: Project Glue, University of Maryland, College Park Distribution: inet Message-ID: <434ef2$210@keck2.umd.edu> NNTP-Posting-Host: keck2.umd.edu