Sunday, 22 October 2017
arrow Previous Versions arrow JDiceLock 6.0.0.1 arrow RandomTest arrow MathematicalFunctions.java (2)
MathematicalFunctions.java (2nd part) (mathematical functions Java source code file) Print E-mail
Get C++ DiceLock cipher architecture source code packages of DiceLock for Microsoft Visual Studio 2013 and DiceLock-x for Linux with Test Driver Programs and Response Test Vector files to verify that both them work as expected.
DiceLock for Windows and Linux
DiceLock Security governing software licenses are Free/Libre Source Code License and Educational and Research License

DiceLock is protected by US patent 7508945 and European Patent 1182777 where applicable.

DiceLock and DiceLock logo are trademarks or registered trademarks in the EC, USA and others.

License information can be obtained at our corporate web site




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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
 
    /**
     * Error function in double precision
     *
     * @param     x         x value to evaluate error function in double precision
     * @return    double:   error function in double precision of value "x"
     */
    public double ErF(double x) {
        final double TWO_SQRTPI = 1.128379167095512574;
        final double REL_ERROR = 1E-12;
        double sum = x, term = x, xsqr = x * x;
        int j = 1;
 
        if (Math.abs(x) > 2.2)
            return 1.0 - this.ErFc(x);
        do {
            term *= xsqr / j;
            sum -= term / (2 * j + 1);
            j++;
            term *= xsqr / j;
            sum += term / (2 * j + 1);
            j++;
        } while (Math.abs(term) / sum > REL_ERROR);
        return TWO_SQRTPI * sum;
    }
 
    /**
     * Error function in double precision
     *
     * @param     x         x value to evaluate error function in double precision
     * @return    double:   error function in double precision of value "x"
     */
    public double ErFc(double x) {
        final double ONE_SQRTPI = 0.564189583547756287;
        final double REL_ERROR = 1E-12;
        double a = 1, b = x, c = x, d = x * x + 0.5;
        double q1, q2 = b / d, n = 1.0, t;
 
        if (Math.abs(x) < 2.2)
            return 1.0 - this.ErF(x);
        if (x < 0)
            return 2.0 - this.ErFc(-x);
        do {
            t = a * n + b * x;
            a = b;
            b = t;
            t = c * n + d * x;
            c = d;
            d = t;
            n += 0.5;
            q1 = q2;
            q2 = b / d;
        } while (Math.abs(q1 - q2) / q2 > REL_ERROR);
        return ONE_SQRTPI * Math.exp(-x * x) * q2;
    }
 
    /**
     * Statistical Normal function
     *
     * @param     x         x value to evaluate statistical normal function
     * @return    double:   statistical normal function of value "x"
     */
    public double Normal(double x) {
        final double SQRT2 = 1.414213562373095048801688724209698078569672;
        double arg, result;
 
        if (x > 0) {
            arg = x / SQRT2;
            result = 0.5 * (1 + this.ErF(arg));
        } else {
            arg = -x / SQRT2;
            result = 0.5 * (1 - this.ErF(arg));
        }
        return (result);
    }
 
    /**
     * Get mathematical error boolean if last executed function failed
     *
     * @return    boolean:   boolean indicating if last executed function produced an error
     */
    public boolean GetError() {
 
        return this.error;
    }
 
    /**
     * Get mathematical error boolean if last executed function failed
     *
     * @return    MathematicalErrors:   MathematicalErrors enumeration indicating error of last executed function
     */
    public MathematicalErrors GetMathError() {
 
        return this.mathError;
    }
 
    // DEFINES AS METHODS
 
    /**
     * Returns the greater of two double values
     *
     * @param     x         double x value to evaluate greater value
     * @param     y         double y value to evaluate greater value
     * @return    double:   returns greater value of "x" and "y"
     */
    public double max(double x, double y) {
 
        return ((x) < (y) ? (y) : (x));
    }
 
    /**
     * Returns the lesser of two double values
     *
     * @param     x         double x value to evaluate greater value
     * @param     y         double y value to evaluate greater value
     * @return    double:   returns greater value of "x" and "y"
     */
    public double min(double x, double y) {
 
        return ((x) > (y) ? (y) : (x));
    }
 
    /**
     * Returns if a double is non positive
     *
     * @param     x   double x value to evaluate if it is non positive
     * @return    boolean:   true:   if it is non positive
     *                       false:  if it is positive
     */
    public double isNonPositive(double x) {
 
        return ((x) <= 0.e0 ? 1 : 0);
    }
 
    /**
     * Returns if a double is positive
     *
     * @param     x   double x value to evaluate if it is positive
     * @return    boolean:    true:   if it is positive
     *                        false:  if it is non positive
     */
    public boolean isPositive(double x) {
 
        return ((x) > 0.e0 ? true : false);
    }
 
    /**
     * Returns if a double is negative
     *
     * @param     x   double x value to evaluate if it is negative
     * @return    boolean:    true:   if it is negative
     *                        false:  if it is non negative
     */
    public boolean isNegative(double x) {
 
        return ((x) < 0.e0 ? true : false);
    }
 
    /**
     * Returns if a double is greater than 1
     *
     * @param     x   double x value to evaluate if it is greater than 1
     * @return    boolean:    true:   if it is greater than 1
     *                        false:  if it is non greater than 1
     */
    public boolean isGreaterThanOne(double x) {
 
        return ((x) > 1.e0 ? true : false);
    }
 
    /**
     * Returns if a double equals 0
     *
     * @param     x   double x value to evaluate if it equals 0
     * @return    boolean:    true:   if it equals 0
     *                        false:  if it no equals 0
     */
    public boolean isZero(double x) {
 
        return ((x) == 0.e0 ? true : false);
    }
 
    /**
     * Returns if a double equals 1
     *
     * @param     x   double x value to evaluate if it equals 1
     * @return    boolean:    true:   if it equals 1
     *                        false:  if it no equals 1
     */
    public boolean isOne(double x) {
 
        return ((x) == 1.e0 ? true : false);
    }
 
}