-
Notifications
You must be signed in to change notification settings - Fork 418
/
Copy pathMath.java
268 lines (239 loc) · 12.5 KB
/
Math.java
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores
* CA 94065 USA or visit www.oracle.com if you need additional information or
* have any questions.
*/
package java.lang;
/**
* The class Math contains methods for performing basic numeric operations.
* Since: JDK1.0, CLDC 1.0
*/
public final class Math{
/**
* The double value that is closer than any other to e, the base of the natural logarithms.
* Since: CLDC 1.1 See Also:Constant Field Values
*/
public static final double E=2.718281828459045d;
/**
* The double value that is closer than any other to
* , the ratio of the circumference of a circle to its diameter.
* Since: CLDC 1.1 See Also:Constant Field Values
*/
public static final double PI=3.141592653589793d;
/**
* Returns the absolute value of a double value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned. Special cases: If the argument is positive zero or negative zero, the result is positive zero. If the argument is infinite, the result is positive infinity. If the argument is NaN, the result is NaN. In other words, the result is equal to the value of the expression:
* Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)
*/
public static double abs(double a){
return 0.0d; //TODO codavaj!!
}
/**
* Returns the absolute value of a float value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned. Special cases: If the argument is positive zero or negative zero, the result is positive zero. If the argument is infinite, the result is positive infinity. If the argument is NaN, the result is NaN. In other words, the result is equal to the value of the expression:
* Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))
*/
public static float abs(float a){
return 0.0f; //TODO codavaj!!
}
/**
* Returns the absolute value of an int value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.
* Note that if the argument is equal to the value of Integer.MIN_VALUE, the most negative representable int value, the result is that same value, which is negative.
*/
public static int abs(int a){
return 0; //TODO codavaj!!
}
/**
* Returns the absolute value of a long value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.
* Note that if the argument is equal to the value of Long.MIN_VALUE, the most negative representable long value, the result is that same value, which is negative.
*/
public static long abs(long a){
return 0l; //TODO codavaj!!
}
/**
* Returns the smallest (closest to negative infinity) double value that is not less than the argument and is equal to a mathematical integer. Special cases: If the argument value is already equal to a mathematical integer, then the result is the same as the argument. If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument. If the argument value is less than zero but greater than -1.0, then the result is negative zero. Note that the value of Math.ceil(x) is exactly the value of -Math.floor(-x).
*/
public static double ceil(double a){
return 0.0d; //TODO codavaj!!
}
/**
* Returns the trigonometric cosine of an angle. Special case: If the argument is NaN or an infinity, then the result is NaN.
*/
public static double cos(double a){
return 0.0d; //TODO codavaj!!
}
/**
* Returns the largest (closest to positive infinity) double value that is not greater than the argument and is equal to a mathematical integer. Special cases: If the argument value is already equal to a mathematical integer, then the result is the same as the argument. If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
*/
public static double floor(double a){
return 0.0d; //TODO codavaj!!
}
/**
* Returns the greater of two double values. That is, the result is the argument closer to positive infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other negative zero, the result is positive zero.
*/
public static double max(double a, double b){
return 0.0d; //TODO codavaj!!
}
/**
* Returns the greater of two float values. That is, the result is the argument closer to positive infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other negative zero, the result is positive zero.
*/
public static float max(float a, float b){
return 0.0f; //TODO codavaj!!
}
/**
* Returns the greater of two int values. That is, the result is the argument closer to the value of Integer.MAX_VALUE. If the arguments have the same value, the result is that same value.
*/
public static int max(int a, int b){
return 0; //TODO codavaj!!
}
/**
* Returns the greater of two long values. That is, the result is the argument closer to the value of Long.MAX_VALUE. If the arguments have the same value, the result is that same value.
*/
public static long max(long a, long b){
return 0l; //TODO codavaj!!
}
/**
* Returns the smaller of two double values. That is, the result is the value closer to negative infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other is negative zero, the result is negative zero.
*/
public static double min(double a, double b){
return 0.0d; //TODO codavaj!!
}
/**
* Returns the smaller of two float values. That is, the result is the value closer to negative infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other is negative zero, the result is negative zero.
*/
public static float min(float a, float b){
return 0.0f; //TODO codavaj!!
}
/**
* Returns the smaller of two int values. That is, the result the argument closer to the value of Integer.MIN_VALUE. If the arguments have the same value, the result is that same value.
*/
public static int min(int a, int b){
return 0; //TODO codavaj!!
}
/**
* Returns the smaller of two long values. That is, the result is the argument closer to the value of Long.MIN_VALUE. If the arguments have the same value, the result is that same value.
*/
public static long min(long a, long b){
return 0l; //TODO codavaj!!
}
/**
* Returns the trigonometric sine of an angle. Special cases: If the argument is NaN or an infinity, then the result is NaN. If the argument is positive zero, then the result is positive zero; if the argument is negative zero, then the result is negative zero.
*/
public static double sin(double a){
return 0.0d; //TODO codavaj!!
}
/**
* Returns the correctly rounded positive square root of a double value. Special cases: If the argument is NaN or less than zero, then the result is NaN. If the argument is positive infinity, then the result is positive infinity. If the argument is positive zero or negative zero, then the result is the same as the argument.
*/
public static double sqrt(double a){
return 0.0d; //TODO codavaj!!
}
/**
* Returns the trigonometric tangent of an angle. Special cases: If the argument is NaN or an infinity, then the result is NaN. If the argument is positive zero, then the result is positive zero; if the argument is negative zero, then the result is negative zero
*/
public static double tan(double a){
return 0.0d; //TODO codavaj!!
}
/**
* Converts an angle measured in radians to the equivalent angle measured in degrees.
*/
public static double toDegrees(double angrad){
return 0.0d; //TODO codavaj!!
}
/**
* Converts an angle measured in degrees to the equivalent angle measured in radians.
*/
public static double toRadians(double angdeg){
return 0.0d; //TODO codavaj!!
}
/**
* Returns the result of rounding the argument to an integer. The result is
* equivalent to {@code (long) Math.floor(d+0.5)}.
* <p>
* Special cases:
* <ul>
* <li>{@code round(+0.0) = (long) +0.0}</li>
* <li>{@code round(-0.0) = (long) +0.0}</li>
* <li>{@code round((anything > Long.MAX_VALUE) = Long.MAX_VALUE}</li>
* <li>{@code round((anything < Long.MIN_VALUE) = Long.MIN_VALUE}</li>
* <li>{@code round(+infinity) = Long.MAX_VALUE}</li>
* <li>{@code round(-infinity) = Long.MIN_VALUE}</li>
* <li>{@code round(NaN) = (long) +0.0}</li>
* </ul>
*
* @param d
* the value to be rounded.
* @return the closest integer to the argument.
*/
public static long round(double d) {
// check for NaN
if (d != d) {
return 0L;
}
return (long) floor(d + 0.5d);
}
/**
* Returns the result of rounding the argument to an integer. The result is
* equivalent to {@code (int) Math.floor(f+0.5)}.
* <p>
* Special cases:
* <ul>
* <li>{@code round(+0.0) = (int) +0.0}</li>
* <li>{@code round(-0.0) = (int) +0.0}</li>
* <li>{@code round((anything > Integer.MAX_VALUE) = Integer.MAX_VALUE}</li>
* <li>{@code round((anything < Integer.MIN_VALUE) = Integer.MIN_VALUE}</li>
* <li>{@code round(+infinity) = Integer.MAX_VALUE}</li>
* <li>{@code round(-infinity) = Integer.MIN_VALUE}</li>
* <li>{@code round(NaN) = (int) +0.0}</li>
* </ul>
*
* @param f
* the value to be rounded.
* @return the closest integer to the argument.
*/
public static int round(float f) {
// check for NaN
if (f != f) {
return 0;
}
return (int) floor(f + 0.5f);
}
public static double nextDown(double d) {
if (Double.isNaN(d)) {
return d;
}
if (d == Double.NEGATIVE_INFINITY) {
return d;
}
long bits = Double.doubleToLongBits(d);
boolean negative = (bits & (1L << 63)) != 0;
if (negative) {
bits++;
} else {
bits--;
}
return Double.longBitsToDouble(bits);
}
public static double nextAfter(double start, double direction) {
return 0;
}
public static float nextAfter(float start, double direction) {
return 0;
}
}