# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. # ADVZ -- Vector divide with checking for zero divisors. If the result of a # divide would be undefined a user supplied function is called to get the # output pixel value. # # NOTE: in the interests of simplicity a somewhat arbitrary tolerance is used # to check for an undefined divide, i.e., a divide by zero or a divide by a # number small enough to cause floating point overflow. A better way to do # this would be to provide a machine dependent version of this operator in # host$as which catches the hardware exception rather than using a comparison. procedure advz$t (a, b, c, npix, errfcn) PIXEL a[ARB], b[ARB], c[ARB] # numerator, divisor, and output arrays int npix # number of pixels PIXEL errfcn() # user function, called on divide by zero int i PIXEL divisor $if (datatype == rd) PIXEL tol $endif extern errfcn() errchk errfcn begin $if (datatype == r) tol = 1.0E-20 $else $if (datatype == d) tol = 1.0D-20 $endif $endif do i = 1, npix { divisor = b[i] $if (datatype == rd) # The following is most efficient when the data tends to be # positive. if (divisor < tol) if (divisor > -tol) { c[i] = errfcn (a[i]) next } c[i] = a[i] / divisor $else if (divisor == 0$f) c[i] = errfcn (a[i]) else c[i] = a[i] / divisor $endif } end