blob: ff8e30e059c472dea62002fb0f483cb3759fb058 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
# ARCZ -- Vector reciprocal 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 arcz$t (a, b, c, npix, errfcn)
PIXEL a # numerator
PIXEL b[ARB], c[ARB] # 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 (a == 0$f) {
call aclr$t (c, npix)
return
}
$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)
next
}
c[i] = a / divisor
$else
if (divisor == 0$f)
c[i] = errfcn (a)
else
c[i] = a / divisor
$endif
}
end
|