NADCON5-ng
0.0.1
NADCON5 Next Generation
Home
Project Documentation
Code Documentation
Index
File List
File Members
onzd2.f
Go to the documentation of this file.
1
c> \ingroup core
2
c> Function to round a digit to one significant figure (one non zero digit), double precision
3
c>
4
c> Function "onzd" stands for "One Non Zero Digit"
5
c>
6
c> Version 2 operates just like version 1 (onzd()), only the input
7
c> and output will be real*8 values, not real*4.
8
c>
9
c> It takes a Real*8 number as input, and rounds that
10
c> number to the closest number containing only 1 non-zero digit.
11
c> The list of such numbers is infifinite, but contain
12
c> these, in order:
13
c>
14
c> 0.7 , 0.8 , 0.9 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9, 10 , 20 , 30 , etc etc
15
c>
16
c> \param[in] x input value
17
c> \return `real*8` rounded value of x to one non zero digit
18
c>
19
c> Examples of input/output are:
20
c>
21
c> 0.000019 => 0.000020
22
c> 0.007432 => 0.007000
23
c> 1.7 => 2.000000
24
c> 9.143 => 9.000000
25
c> 17.4 => 20.000000
26
c> 947.3 => 900.000000
27
c> 987.432 => 1000.000000
28
c> 1014.8 => 1000.000000
29
c> 1502.7 => 2000.000000
30
c>
31
function
onzd2
(x)
32
implicit none
33
real*8
onzd2,x,y
34
real*8
q,qten
35
integer*4
imag,iq,isign
36
37
c - Function "onzd2" stands for "One Non Zero Digit, version 2"
38
39
c - Version 2 operates just like version 1 (onzd.f), only the input
40
c - and output will be real*8 values, not real*4.
41
42
c - It takes a Real*8 number as input, and rounds that
43
c - number to the closest number containing only 1 non-zero digit.
44
c - The list of such numbers is infifinite, but contain
45
c - these, in order:
46
c - 0.7 , 0.8 , 0.9 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9, 10 , 20 , 30 , etc etc
47
c -
48
c - Examples of input/output are:
49
c - 0.000019 => 0.000020
50
c - 0.007432 => 0.007000
51
c - 1.7 => 2.000000
52
c - 9.143 => 9.000000
53
c - 17.4 => 20.000000
54
c - 947.3 => 900.000000
55
c - 987.432 => 1000.000000
56
c - 1014.8 => 1000.000000
57
c - 1502.7 => 2000.000000
58
59
y = x
60
isign = +1
61
if
(x.lt.0)
then
62
isign = -1
63
y = -x
64
endif
65
66
c - 1) Determine magnitude of x, in terms of integer exponent of ten
67
imag = floor(dlog10(y))
68
69
c - 1a) Get the multiplier
70
qten = (10.d0**imag)
71
72
c - 2) Get into a range between 0.0 and 10.0
73
q = dble(y) / qten
74
75
c - 3) Round to the closest integer (0 through 10)
76
iq = nint(q)
77
78
c - 4) Scale back to the original size
79
onzd2 = isign * dble(iq) * qten
80
81
c write(6,100)x,imag,qten,q,iq,onzd2
82
c 100 format(f30.15,1x,i10,1x,f30.15,1x,f30.15,1x,i10,1x,f30.15)
83
84
return
85
end
86
onzd2
real *8 function onzd2(x)
Function to round a digit to one significant figure (one non zero digit), double precision.
Definition:
onzd2.f:32
src
Subs
onzd2.f
Generated on Mon Nov 20 2017 16:14:46 for NADCON5-ng by
1.8.11