blob: 45ad3f2a76dad655ec0eb9662c9f3dd82404eea0 (
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
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <mach.h>
# FP_NORMR -- Normalize a single precision number x to the value NORMX, in the
# range [1-10). EXPON is returned such that x = normx * (10.0E0 ** expon).
procedure fp_normr (x, normx, expon)
real x # number to be normalized
real normx # X normalized to the range 1-10 (output)
int expon # exponent of normalized X
real absx, tol
begin
tol = EPSILONR * 10.0
absx = abs (x)
expon = 0
if (absx > 0) {
while (absx < (1.0E0 - tol)) {
absx = absx * 10.0E0
expon = expon - 1
if (absx == 0.0) { # check for underflow to zero
normx = 0
expon = 0
return
}
}
while (absx >= (10.0E0 + tol)) {
absx = absx / 10.0E0
expon = expon + 1
}
}
if (x < 0)
normx = -absx
else
normx = absx
end
|