| 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 | |
package org.galagosearch.core.eval.stat; |
| 38 | |
|
| 39 | |
import java.util.Vector; |
| 40 | |
|
| 41 | 0 | public class Fmath { |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
public static final double N_AVAGADRO = 6.0221419947e23; |
| 46 | |
public static final double K_BOLTZMANN = 1.380650324e-23; |
| 47 | |
public static final double H_PLANCK = 6.6260687652e-34; |
| 48 | |
public static final double H_PLANCK_RED = H_PLANCK/(2*Math.PI); |
| 49 | |
public static final double C_LIGHT = 2.99792458e8; |
| 50 | |
public static final double R_GAS = 8.31447215; |
| 51 | |
public static final double F_FARADAY = 9.6485341539e4; |
| 52 | |
public static final double T_ABS = -273.15; |
| 53 | |
public static final double Q_ELECTRON = -1.60217646263e-19; |
| 54 | |
public static final double M_ELECTRON = 9.1093818872e-31; |
| 55 | |
public static final double M_PROTON = 1.6726215813e-27; |
| 56 | |
public static final double M_NEUTRON = 1.6749271613e-27; |
| 57 | |
public static final double EPSILON_0 = 8.854187817e-12; |
| 58 | |
public static final double MU_0 = Math.PI*4e-7; |
| 59 | |
|
| 60 | |
|
| 61 | |
public static final double EULER_CONSTANT_GAMMA = 0.5772156649015627; |
| 62 | |
public static final double PI = Math.PI; |
| 63 | |
public static final double E = Math.E; |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
public static double log10(double a){ |
| 72 | 0 | return Math.log(a)/Math.log(10.0D); |
| 73 | |
} |
| 74 | |
|
| 75 | |
|
| 76 | |
public static float log10(float a){ |
| 77 | 0 | return (float) (Math.log((double)a)/Math.log(10.0D)); |
| 78 | |
} |
| 79 | |
|
| 80 | |
|
| 81 | |
public static double antilog10(double x){ |
| 82 | 0 | return Math.pow(10.0D, x); |
| 83 | |
} |
| 84 | |
|
| 85 | |
|
| 86 | |
public static float antilog10(float x){ |
| 87 | 0 | return (float)Math.pow(10.0D, (double)x); |
| 88 | |
} |
| 89 | |
|
| 90 | |
|
| 91 | |
public static double log(double a){ |
| 92 | 0 | return Math.log(a); |
| 93 | |
} |
| 94 | |
|
| 95 | |
|
| 96 | |
public static float log(float a){ |
| 97 | 0 | return (float)Math.log((double)a); |
| 98 | |
} |
| 99 | |
|
| 100 | |
|
| 101 | |
public static double antilog(double x){ |
| 102 | 0 | return Math.exp(x); |
| 103 | |
} |
| 104 | |
|
| 105 | |
|
| 106 | |
public static float antilog(float x){ |
| 107 | 0 | return (float)Math.exp((double)x); |
| 108 | |
} |
| 109 | |
|
| 110 | |
|
| 111 | |
public static double log2(double a){ |
| 112 | 0 | return Math.log(a)/Math.log(2.0D); |
| 113 | |
} |
| 114 | |
|
| 115 | |
|
| 116 | |
public static float log2(float a){ |
| 117 | 0 | return (float) (Math.log((double)a)/Math.log(2.0D)); |
| 118 | |
} |
| 119 | |
|
| 120 | |
|
| 121 | |
public static double antilog2(double x){ |
| 122 | 0 | return Math.pow(2.0D, x); |
| 123 | |
} |
| 124 | |
|
| 125 | |
|
| 126 | |
public static float antilog2(float x){ |
| 127 | 0 | return (float)Math.pow(2.0D, (double)x); |
| 128 | |
} |
| 129 | |
|
| 130 | |
|
| 131 | |
public static double log10(double a, double b){ |
| 132 | 0 | return Math.log(a)/Math.log(b); |
| 133 | |
} |
| 134 | |
|
| 135 | |
|
| 136 | |
public static double log10(double a, int b){ |
| 137 | 0 | return Math.log(a)/Math.log((double)b); |
| 138 | |
} |
| 139 | |
|
| 140 | |
|
| 141 | |
public static float log10(float a, float b){ |
| 142 | 0 | return (float) (Math.log((double)a)/Math.log((double)b)); |
| 143 | |
} |
| 144 | |
|
| 145 | |
|
| 146 | |
public static float log10(float a, int b){ |
| 147 | 0 | return (float) (Math.log((double)a)/Math.log((double)b)); |
| 148 | |
} |
| 149 | |
|
| 150 | |
|
| 151 | |
public static double square(double a){ |
| 152 | 0 | return a*a; |
| 153 | |
} |
| 154 | |
|
| 155 | |
|
| 156 | |
public static float square(float a){ |
| 157 | 0 | return a*a; |
| 158 | |
} |
| 159 | |
|
| 160 | |
|
| 161 | |
public static int square(int a){ |
| 162 | 0 | return a*a; |
| 163 | |
} |
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
public static int factorial(int n){ |
| 169 | 0 | if(n<0)throw new IllegalArgumentException("n must be a positive integer"); |
| 170 | 0 | if(n>12)throw new IllegalArgumentException("n must less than 13 to avoid integer overflow\nTry long or double argument"); |
| 171 | 0 | int f = 1; |
| 172 | 0 | for(int i=1; i<=n; i++)f*=i; |
| 173 | 0 | return f; |
| 174 | |
} |
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
public static long factorial(long n){ |
| 180 | 0 | if(n<0)throw new IllegalArgumentException("n must be a positive integer"); |
| 181 | 0 | if(n>20)throw new IllegalArgumentException("n must less than 21 to avoid long integer overflow\nTry double argument"); |
| 182 | 0 | long f = 1; |
| 183 | 0 | for(int i=1; i<=n; i++)f*=i; |
| 184 | 0 | return f; |
| 185 | |
} |
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
public static double factorial(double n){ |
| 192 | 0 | if(n<0 || (n-(int)n)!=0)throw new IllegalArgumentException("\nn must be a positive integer\nIs a Gamma funtion [Fmath.gamma(x)] more appropriate?"); |
| 193 | 0 | double f = 1.0D; |
| 194 | 0 | int nn = (int)n; |
| 195 | 0 | for(int i=1; i<=nn; i++)f*=i; |
| 196 | 0 | return f; |
| 197 | |
} |
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | |
public static double logFactorial(int n){ |
| 203 | 0 | if(n<0 || (n-(int)n)!=0)throw new IllegalArgumentException("\nn must be a positive integer\nIs a Gamma funtion [Fmath.gamma(x)] more appropriate?"); |
| 204 | 0 | double f = 0.0D; |
| 205 | 0 | for(int i=2; i<=n; i++)f+=Math.log(i); |
| 206 | 0 | return f; |
| 207 | |
} |
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
public static double logFactorial(double n){ |
| 214 | 0 | if(n<0 || (n-(int)n)!=0)throw new IllegalArgumentException("\nn must be a positive integer\nIs a Gamma funtion [Fmath.gamma(x)] more appropriate?"); |
| 215 | 0 | double f = 0.0D; |
| 216 | 0 | int nn = (int)n; |
| 217 | 0 | for(int i=2; i<=nn; i++)f+=Math.log(i); |
| 218 | 0 | return f; |
| 219 | |
} |
| 220 | |
|
| 221 | |
|
| 222 | |
public static double maximum(double[] aa){ |
| 223 | 0 | int n = aa.length; |
| 224 | 0 | double aamax=aa[0]; |
| 225 | 0 | for(int i=1; i<n; i++){ |
| 226 | 0 | if(aa[i]>aamax)aamax=aa[i]; |
| 227 | |
} |
| 228 | 0 | return aamax; |
| 229 | |
} |
| 230 | |
|
| 231 | |
|
| 232 | |
public static float maximum(float[] aa){ |
| 233 | 0 | int n = aa.length; |
| 234 | 0 | float aamax=aa[0]; |
| 235 | 0 | for(int i=1; i<n; i++){ |
| 236 | 0 | if(aa[i]>aamax)aamax=aa[i]; |
| 237 | |
} |
| 238 | 0 | return aamax; |
| 239 | |
} |
| 240 | |
|
| 241 | |
|
| 242 | |
public static int maximum(int[] aa){ |
| 243 | 0 | int n = aa.length; |
| 244 | 0 | int aamax=aa[0]; |
| 245 | 0 | for(int i=1; i<n; i++){ |
| 246 | 0 | if(aa[i]>aamax)aamax=aa[i]; |
| 247 | |
} |
| 248 | 0 | return aamax; |
| 249 | |
} |
| 250 | |
|
| 251 | |
|
| 252 | |
public static long maximum(long[] aa){ |
| 253 | 0 | long n = aa.length; |
| 254 | 0 | long aamax=aa[0]; |
| 255 | 0 | for(int i=1; i<n; i++){ |
| 256 | 0 | if(aa[i]>aamax)aamax=aa[i]; |
| 257 | |
} |
| 258 | 0 | return aamax; |
| 259 | |
} |
| 260 | |
|
| 261 | |
|
| 262 | |
public static double minimum(double[] aa){ |
| 263 | 0 | int n = aa.length; |
| 264 | 0 | double aamin=aa[0]; |
| 265 | 0 | for(int i=1; i<n; i++){ |
| 266 | 0 | if(aa[i]<aamin)aamin=aa[i]; |
| 267 | |
} |
| 268 | 0 | return aamin; |
| 269 | |
} |
| 270 | |
|
| 271 | |
|
| 272 | |
public static float minimum(float[] aa){ |
| 273 | 0 | int n = aa.length; |
| 274 | 0 | float aamin=aa[0]; |
| 275 | 0 | for(int i=1; i<n; i++){ |
| 276 | 0 | if(aa[i]<aamin)aamin=aa[i]; |
| 277 | |
} |
| 278 | 0 | return aamin; |
| 279 | |
} |
| 280 | |
|
| 281 | |
|
| 282 | |
public static int minimum(int[] aa){ |
| 283 | 0 | int n = aa.length; |
| 284 | 0 | int aamin=aa[0]; |
| 285 | 0 | for(int i=1; i<n; i++){ |
| 286 | 0 | if(aa[i]<aamin)aamin=aa[i]; |
| 287 | |
} |
| 288 | 0 | return aamin; |
| 289 | |
} |
| 290 | |
|
| 291 | |
|
| 292 | |
public static long minimum(long[] aa){ |
| 293 | 0 | long n = aa.length; |
| 294 | 0 | long aamin=aa[0]; |
| 295 | 0 | for(int i=1; i<n; i++){ |
| 296 | 0 | if(aa[i]<aamin)aamin=aa[i]; |
| 297 | |
} |
| 298 | 0 | return aamin; |
| 299 | |
} |
| 300 | |
|
| 301 | |
|
| 302 | |
public static double[] reverseArray(double[] aa){ |
| 303 | 0 | int n = aa.length; |
| 304 | 0 | double[] bb = new double[n]; |
| 305 | 0 | for(int i=0; i<n; i++){ |
| 306 | 0 | bb[i] = aa[n-1-i]; |
| 307 | |
} |
| 308 | 0 | return bb; |
| 309 | |
} |
| 310 | |
|
| 311 | |
|
| 312 | |
public static float[] reverseArray(float[] aa){ |
| 313 | 0 | int n = aa.length; |
| 314 | 0 | float[] bb = new float[n]; |
| 315 | 0 | for(int i=0; i<n; i++){ |
| 316 | 0 | bb[i] = aa[n-1-i]; |
| 317 | |
} |
| 318 | 0 | return bb; |
| 319 | |
} |
| 320 | |
|
| 321 | |
|
| 322 | |
public static int[] reverseArray(int[] aa){ |
| 323 | 0 | int n = aa.length; |
| 324 | 0 | int[] bb = new int[n]; |
| 325 | 0 | for(int i=0; i<n; i++){ |
| 326 | 0 | bb[i] = aa[n-1-i]; |
| 327 | |
} |
| 328 | 0 | return bb; |
| 329 | |
} |
| 330 | |
|
| 331 | |
|
| 332 | |
public static long[] reverseArray(long[] aa){ |
| 333 | 0 | int n = aa.length; |
| 334 | 0 | long[] bb = new long[n]; |
| 335 | 0 | for(int i=0; i<n; i++){ |
| 336 | 0 | bb[i] = aa[n-1-i]; |
| 337 | |
} |
| 338 | 0 | return bb; |
| 339 | |
} |
| 340 | |
|
| 341 | |
|
| 342 | |
public static char[] reverseArray(char[] aa){ |
| 343 | 0 | int n = aa.length; |
| 344 | 0 | char[] bb = new char[n]; |
| 345 | 0 | for(int i=0; i<n; i++){ |
| 346 | 0 | bb[i] = aa[n-1-i]; |
| 347 | |
} |
| 348 | 0 | return bb; |
| 349 | |
} |
| 350 | |
|
| 351 | |
|
| 352 | |
public static double[] arrayAbs(double[] aa){ |
| 353 | 0 | int n = aa.length; |
| 354 | 0 | double[] bb = new double[n]; |
| 355 | 0 | for(int i=0; i<n; i++){ |
| 356 | 0 | bb[i] = Math.abs(aa[i]); |
| 357 | |
} |
| 358 | 0 | return bb; |
| 359 | |
} |
| 360 | |
|
| 361 | |
|
| 362 | |
public static float[] arrayAbs(float[] aa){ |
| 363 | 0 | int n = aa.length; |
| 364 | 0 | float[] bb = new float[n]; |
| 365 | 0 | for(int i=0; i<n; i++){ |
| 366 | 0 | bb[i] = Math.abs(aa[i]); |
| 367 | |
} |
| 368 | 0 | return bb; |
| 369 | |
} |
| 370 | |
|
| 371 | |
|
| 372 | |
public static long[] arrayAbs(long[] aa){ |
| 373 | 0 | int n = aa.length; |
| 374 | 0 | long[] bb = new long[n]; |
| 375 | 0 | for(int i=0; i<n; i++){ |
| 376 | 0 | bb[i] = Math.abs(aa[i]); |
| 377 | |
} |
| 378 | 0 | return bb; |
| 379 | |
} |
| 380 | |
|
| 381 | |
|
| 382 | |
public static int[] arrayAbs(int[] aa){ |
| 383 | 0 | int n = aa.length; |
| 384 | 0 | int[] bb = new int[n]; |
| 385 | 0 | for(int i=0; i<n; i++){ |
| 386 | 0 | bb[i] = Math.abs(aa[i]); |
| 387 | |
} |
| 388 | 0 | return bb; |
| 389 | |
} |
| 390 | |
|
| 391 | |
|
| 392 | |
public static double[] arrayMultByConstant(double[] aa, double constant){ |
| 393 | 0 | int n = aa.length; |
| 394 | 0 | double[] bb = new double[n]; |
| 395 | 0 | for(int i=0; i<n; i++){ |
| 396 | 0 | bb[i] = aa[i]*constant; |
| 397 | |
} |
| 398 | 0 | return bb; |
| 399 | |
} |
| 400 | |
|
| 401 | |
|
| 402 | |
public static double[] arrayMultByConstant(int[] aa, double constant){ |
| 403 | 0 | int n = aa.length; |
| 404 | 0 | double[] bb = new double[n]; |
| 405 | 0 | for(int i=0; i<n; i++){ |
| 406 | 0 | bb[i] = (double)aa[i]*constant; |
| 407 | |
} |
| 408 | 0 | return bb; |
| 409 | |
} |
| 410 | |
|
| 411 | |
public static double[] arrayMultByConstant(double[] aa, int constant){ |
| 412 | 0 | int n = aa.length; |
| 413 | 0 | double[] bb = new double[n]; |
| 414 | 0 | for(int i=0; i<n; i++){ |
| 415 | 0 | bb[i] = aa[i]*(double)constant; |
| 416 | |
} |
| 417 | 0 | return bb; |
| 418 | |
} |
| 419 | |
|
| 420 | |
|
| 421 | |
public static double[] arrayMultByConstant(int[] aa, int constant){ |
| 422 | 0 | int n = aa.length; |
| 423 | 0 | double[] bb = new double[n]; |
| 424 | 0 | for(int i=0; i<n; i++){ |
| 425 | 0 | bb[i] = (double)(aa[i]*constant); |
| 426 | |
} |
| 427 | 0 | return bb; |
| 428 | |
} |
| 429 | |
|
| 430 | |
|
| 431 | |
public static double nearestElementValue(double[] array, double value){ |
| 432 | 0 | double diff = Math.abs(array[0] - value); |
| 433 | 0 | double nearest = array[0]; |
| 434 | 0 | for(int i=1; i<array.length; i++){ |
| 435 | 0 | if(Math.abs(array[i] - value)<diff){ |
| 436 | 0 | diff = Math.abs(array[i] - value); |
| 437 | 0 | nearest = array[i]; |
| 438 | |
} |
| 439 | |
} |
| 440 | 0 | return nearest; |
| 441 | |
} |
| 442 | |
|
| 443 | |
|
| 444 | |
public static int nearestElementIndex(double[] array, double value){ |
| 445 | 0 | double diff = Math.abs(array[0] - value); |
| 446 | 0 | int nearest = 0; |
| 447 | 0 | for(int i=1; i<array.length; i++){ |
| 448 | 0 | if(Math.abs(array[i] - value)<diff){ |
| 449 | 0 | diff = Math.abs(array[i] - value); |
| 450 | 0 | nearest = i; |
| 451 | |
} |
| 452 | |
} |
| 453 | 0 | return nearest; |
| 454 | |
} |
| 455 | |
|
| 456 | |
|
| 457 | |
public static double nearestLowerElementValue(double[] array, double value){ |
| 458 | 0 | double diff0 = 0.0D; |
| 459 | 0 | double diff1 = 0.0D; |
| 460 | 0 | double nearest = 0.0D; |
| 461 | 0 | int ii = 0; |
| 462 | 0 | boolean test = true; |
| 463 | 0 | double min = array[0]; |
| 464 | 0 | while(test){ |
| 465 | 0 | if(array[ii]<min)min = array[ii]; |
| 466 | 0 | if((value - array[ii])>=0.0D){ |
| 467 | 0 | diff0 = value - array[ii]; |
| 468 | 0 | nearest = array[ii]; |
| 469 | 0 | test = false; |
| 470 | |
} |
| 471 | |
else{ |
| 472 | 0 | ii++; |
| 473 | 0 | if(ii>array.length-1){ |
| 474 | 0 | nearest = min; |
| 475 | 0 | diff0 = min - value; |
| 476 | 0 | test = false; |
| 477 | |
} |
| 478 | |
} |
| 479 | |
} |
| 480 | 0 | for(int i=0; i<array.length; i++){ |
| 481 | 0 | diff1 = value - array[i]; |
| 482 | 0 | if(diff1>=0.0D && diff1<diff0 ){ |
| 483 | 0 | diff0 = diff1; |
| 484 | 0 | nearest = array[i]; |
| 485 | |
} |
| 486 | |
} |
| 487 | 0 | return nearest; |
| 488 | |
} |
| 489 | |
|
| 490 | |
|
| 491 | |
public static int nearestLowerElementIndex(double[] array, double value){ |
| 492 | 0 | double diff0 = 0.0D; |
| 493 | 0 | double diff1 = 0.0D; |
| 494 | 0 | int nearest = 0; |
| 495 | 0 | int ii = 0; |
| 496 | 0 | boolean test = true; |
| 497 | 0 | double min = array[0]; |
| 498 | 0 | int minI = 0; |
| 499 | 0 | while(test){ |
| 500 | 0 | if(array[ii]<min){ |
| 501 | 0 | min = array[ii]; |
| 502 | 0 | minI = ii; |
| 503 | |
} |
| 504 | 0 | if((value - array[ii])>=0.0D){ |
| 505 | 0 | diff0 = value - array[ii]; |
| 506 | 0 | nearest = ii; |
| 507 | 0 | test = false; |
| 508 | |
} |
| 509 | |
else{ |
| 510 | 0 | ii++; |
| 511 | 0 | if(ii>array.length-1){ |
| 512 | 0 | nearest = minI; |
| 513 | 0 | diff0 = min - value; |
| 514 | 0 | test = false; |
| 515 | |
} |
| 516 | |
} |
| 517 | |
} |
| 518 | 0 | for(int i=0; i<array.length; i++){ |
| 519 | 0 | diff1 = value - array[i]; |
| 520 | 0 | if(diff1>=0.0D && diff1<diff0 ){ |
| 521 | 0 | diff0 = diff1; |
| 522 | 0 | nearest = i; |
| 523 | |
} |
| 524 | |
} |
| 525 | 0 | return nearest; |
| 526 | |
} |
| 527 | |
|
| 528 | |
|
| 529 | |
public static double nearestHigherElementValue(double[] array, double value){ |
| 530 | 0 | double diff0 = 0.0D; |
| 531 | 0 | double diff1 = 0.0D; |
| 532 | 0 | double nearest = 0.0D; |
| 533 | 0 | int ii = 0; |
| 534 | 0 | boolean test = true; |
| 535 | 0 | double max = array[0]; |
| 536 | 0 | while(test){ |
| 537 | 0 | if(array[ii]>max)max = array[ii]; |
| 538 | 0 | if((array[ii] - value )>=0.0D){ |
| 539 | 0 | diff0 = value - array[ii]; |
| 540 | 0 | nearest = array[ii]; |
| 541 | 0 | test = false; |
| 542 | |
} |
| 543 | |
else{ |
| 544 | 0 | ii++; |
| 545 | 0 | if(ii>array.length-1){ |
| 546 | 0 | nearest = max; |
| 547 | 0 | diff0 = value - max; |
| 548 | 0 | test = false; |
| 549 | |
} |
| 550 | |
} |
| 551 | |
} |
| 552 | 0 | for(int i=0; i<array.length; i++){ |
| 553 | 0 | diff1 = array[i]- value; |
| 554 | 0 | if(diff1>=0.0D && diff1<diff0 ){ |
| 555 | 0 | diff0 = diff1; |
| 556 | 0 | nearest = array[i]; |
| 557 | |
} |
| 558 | |
} |
| 559 | 0 | return nearest; |
| 560 | |
} |
| 561 | |
|
| 562 | |
|
| 563 | |
public static int nearestHigherElementIndex(double[] array, double value){ |
| 564 | 0 | double diff0 = 0.0D; |
| 565 | 0 | double diff1 = 0.0D; |
| 566 | 0 | int nearest = 0; |
| 567 | 0 | int ii = 0; |
| 568 | 0 | boolean test = true; |
| 569 | 0 | double max = array[0]; |
| 570 | 0 | int maxI = 0; |
| 571 | 0 | while(test){ |
| 572 | 0 | if(array[ii]>max){ |
| 573 | 0 | max = array[ii]; |
| 574 | 0 | maxI = ii; |
| 575 | |
} |
| 576 | 0 | if((array[ii] - value )>=0.0D){ |
| 577 | 0 | diff0 = value - array[ii]; |
| 578 | 0 | nearest = ii; |
| 579 | 0 | test = false; |
| 580 | |
} |
| 581 | |
else{ |
| 582 | 0 | ii++; |
| 583 | 0 | if(ii>array.length-1){ |
| 584 | 0 | nearest = maxI; |
| 585 | 0 | diff0 = value - max; |
| 586 | 0 | test = false; |
| 587 | |
} |
| 588 | |
} |
| 589 | |
} |
| 590 | 0 | for(int i=0; i<array.length; i++){ |
| 591 | 0 | diff1 = array[i]- value; |
| 592 | 0 | if(diff1>=0.0D && diff1<diff0 ){ |
| 593 | 0 | diff0 = diff1; |
| 594 | 0 | nearest = i; |
| 595 | |
} |
| 596 | |
} |
| 597 | 0 | return nearest; |
| 598 | |
} |
| 599 | |
|
| 600 | |
|
| 601 | |
|
| 602 | |
public static int nearestElementValue(int[] array, int value){ |
| 603 | 0 | int diff = (int) Math.abs(array[0] - value); |
| 604 | 0 | int nearest = array[0]; |
| 605 | 0 | for(int i=1; i<array.length; i++){ |
| 606 | 0 | if((int) Math.abs(array[i] - value)<diff){ |
| 607 | 0 | diff = (int)Math.abs(array[i] - value); |
| 608 | 0 | nearest = array[i]; |
| 609 | |
} |
| 610 | |
} |
| 611 | 0 | return nearest; |
| 612 | |
} |
| 613 | |
|
| 614 | |
|
| 615 | |
public static int nearestElementIndex(int[] array, int value){ |
| 616 | 0 | int diff = (int) Math.abs(array[0] - value); |
| 617 | 0 | int nearest = 0; |
| 618 | 0 | for(int i=1; i<array.length; i++){ |
| 619 | 0 | if((int) Math.abs(array[i] - value)<diff){ |
| 620 | 0 | diff = (int)Math.abs(array[i] - value); |
| 621 | 0 | nearest = i; |
| 622 | |
} |
| 623 | |
} |
| 624 | 0 | return nearest; |
| 625 | |
} |
| 626 | |
|
| 627 | |
|
| 628 | |
public static int nearestLowerElementValue(int[] array, int value){ |
| 629 | 0 | int diff0 = 0; |
| 630 | 0 | int diff1 = 0; |
| 631 | 0 | int nearest = 0; |
| 632 | 0 | int ii = 0; |
| 633 | 0 | boolean test = true; |
| 634 | 0 | int min = array[0]; |
| 635 | 0 | while(test){ |
| 636 | 0 | if(array[ii]<min)min = array[ii]; |
| 637 | 0 | if((value - array[ii])>=0){ |
| 638 | 0 | diff0 = value - array[ii]; |
| 639 | 0 | nearest = array[ii]; |
| 640 | 0 | test = false; |
| 641 | |
} |
| 642 | |
else{ |
| 643 | 0 | ii++; |
| 644 | 0 | if(ii>array.length-1){ |
| 645 | 0 | nearest = min; |
| 646 | 0 | diff0 = min - value; |
| 647 | 0 | test = false; |
| 648 | |
} |
| 649 | |
} |
| 650 | |
} |
| 651 | 0 | for(int i=0; i<array.length; i++){ |
| 652 | 0 | diff1 = value - array[i]; |
| 653 | 0 | if(diff1>=0 && diff1<diff0 ){ |
| 654 | 0 | diff0 = diff1; |
| 655 | 0 | nearest = array[i]; |
| 656 | |
} |
| 657 | |
} |
| 658 | 0 | return nearest; |
| 659 | |
} |
| 660 | |
|
| 661 | |
|
| 662 | |
public static int nearestLowerElementIndex(int[] array, int value){ |
| 663 | 0 | int diff0 = 0; |
| 664 | 0 | int diff1 = 0; |
| 665 | 0 | int nearest = 0; |
| 666 | 0 | int ii = 0; |
| 667 | 0 | boolean test = true; |
| 668 | 0 | int min = array[0]; |
| 669 | 0 | int minI = 0; |
| 670 | 0 | while(test){ |
| 671 | 0 | if(array[ii]<min){ |
| 672 | 0 | min = array[ii]; |
| 673 | 0 | minI = ii; |
| 674 | |
} |
| 675 | 0 | if((value - array[ii])>=0){ |
| 676 | 0 | diff0 = value - array[ii]; |
| 677 | 0 | nearest = ii; |
| 678 | 0 | test = false; |
| 679 | |
} |
| 680 | |
else{ |
| 681 | 0 | ii++; |
| 682 | 0 | if(ii>array.length-1){ |
| 683 | 0 | nearest = minI; |
| 684 | 0 | diff0 = min - value; |
| 685 | 0 | test = false; |
| 686 | |
} |
| 687 | |
} |
| 688 | |
} |
| 689 | 0 | for(int i=0; i<array.length; i++){ |
| 690 | 0 | diff1 = value - array[i]; |
| 691 | 0 | if(diff1>=0 && diff1<diff0 ){ |
| 692 | 0 | diff0 = diff1; |
| 693 | 0 | nearest = i; |
| 694 | |
} |
| 695 | |
} |
| 696 | 0 | return nearest; |
| 697 | |
} |
| 698 | |
|
| 699 | |
|
| 700 | |
public static int nearestHigherElementValue(int[] array, int value){ |
| 701 | 0 | int diff0 = 0; |
| 702 | 0 | int diff1 = 0; |
| 703 | 0 | int nearest = 0; |
| 704 | 0 | int ii = 0; |
| 705 | 0 | boolean test = true; |
| 706 | 0 | int max = array[0]; |
| 707 | 0 | while(test){ |
| 708 | 0 | if(array[ii]>max)max = array[ii]; |
| 709 | 0 | if((array[ii] - value )>=0){ |
| 710 | 0 | diff0 = value - array[ii]; |
| 711 | 0 | nearest = array[ii]; |
| 712 | 0 | test = false; |
| 713 | |
} |
| 714 | |
else{ |
| 715 | 0 | ii++; |
| 716 | 0 | if(ii>array.length-1){ |
| 717 | 0 | nearest = max; |
| 718 | 0 | diff0 = value - max; |
| 719 | 0 | test = false; |
| 720 | |
} |
| 721 | |
} |
| 722 | |
} |
| 723 | 0 | for(int i=0; i<array.length; i++){ |
| 724 | 0 | diff1 = array[i]- value; |
| 725 | 0 | if(diff1>=0 && diff1<diff0 ){ |
| 726 | 0 | diff0 = diff1; |
| 727 | 0 | nearest = array[i]; |
| 728 | |
} |
| 729 | |
} |
| 730 | 0 | return nearest; |
| 731 | |
} |
| 732 | |
|
| 733 | |
|
| 734 | |
public static int nearestHigherElementIndex(int[] array, int value){ |
| 735 | 0 | int diff0 = 0; |
| 736 | 0 | int diff1 = 0; |
| 737 | 0 | int nearest = 0; |
| 738 | 0 | int ii = 0; |
| 739 | 0 | boolean test = true; |
| 740 | 0 | int max = array[0]; |
| 741 | 0 | int maxI = 0; |
| 742 | 0 | while(test){ |
| 743 | 0 | if(array[ii]>max){ |
| 744 | 0 | max = array[ii]; |
| 745 | 0 | maxI = ii; |
| 746 | |
} |
| 747 | 0 | if((array[ii] - value )>=0){ |
| 748 | 0 | diff0 = value - array[ii]; |
| 749 | 0 | nearest = ii; |
| 750 | 0 | test = false; |
| 751 | |
} |
| 752 | |
else{ |
| 753 | 0 | ii++; |
| 754 | 0 | if(ii>array.length-1){ |
| 755 | 0 | nearest = maxI; |
| 756 | 0 | diff0 = value - max; |
| 757 | 0 | test = false; |
| 758 | |
} |
| 759 | |
} |
| 760 | |
} |
| 761 | 0 | for(int i=0; i<array.length; i++){ |
| 762 | 0 | diff1 = array[i]- value; |
| 763 | 0 | if(diff1>=0 && diff1<diff0 ){ |
| 764 | 0 | diff0 = diff1; |
| 765 | 0 | nearest = i; |
| 766 | |
} |
| 767 | |
} |
| 768 | 0 | return nearest; |
| 769 | |
} |
| 770 | |
|
| 771 | |
|
| 772 | |
public static double arraySum(double[]array){ |
| 773 | 0 | double sum = 0.0D; |
| 774 | 0 | for(double i:array)sum += i; |
| 775 | 0 | return sum; |
| 776 | |
} |
| 777 | |
|
| 778 | |
|
| 779 | |
public static float arraySum(float[]array){ |
| 780 | 0 | float sum = 0.0F; |
| 781 | 0 | for(float i:array)sum += i; |
| 782 | 0 | return sum; |
| 783 | |
} |
| 784 | |
|
| 785 | |
|
| 786 | |
public static int arraySum(int[]array){ |
| 787 | 0 | int sum = 0; |
| 788 | 0 | for(int i:array)sum += i; |
| 789 | 0 | return sum; |
| 790 | |
} |
| 791 | |
|
| 792 | |
|
| 793 | |
public static long arraySum(long[]array){ |
| 794 | 0 | long sum = 0L; |
| 795 | 0 | for(long i:array)sum += i; |
| 796 | 0 | return sum; |
| 797 | |
} |
| 798 | |
|
| 799 | |
|
| 800 | |
public static double arrayProduct(double[]array){ |
| 801 | 0 | double product = 1.0D; |
| 802 | 0 | for(double i:array)product *= i; |
| 803 | 0 | return product; |
| 804 | |
} |
| 805 | |
|
| 806 | |
|
| 807 | |
public static float arrayProduct(float[]array){ |
| 808 | 0 | float product = 1.0F; |
| 809 | 0 | for(float i:array)product *= i; |
| 810 | 0 | return product; |
| 811 | |
} |
| 812 | |
|
| 813 | |
|
| 814 | |
public static int arrayProduct(int[]array){ |
| 815 | 0 | int product = 1; |
| 816 | 0 | for(int i:array)product *= i; |
| 817 | 0 | return product; |
| 818 | |
} |
| 819 | |
|
| 820 | |
|
| 821 | |
public static long arrayProduct(long[]array){ |
| 822 | 0 | long product = 1L; |
| 823 | 0 | for(long i:array)product *= i; |
| 824 | 0 | return product; |
| 825 | |
} |
| 826 | |
|
| 827 | |
|
| 828 | |
public static double[] concatenate(double[] aa, double[] bb){ |
| 829 | 0 | int aLen = aa.length; |
| 830 | 0 | int bLen = bb.length; |
| 831 | 0 | int cLen = aLen + bLen; |
| 832 | 0 | double[] cc = new double[cLen]; |
| 833 | 0 | for(int i=0; i<aLen; i++)cc[i] = aa[i]; |
| 834 | 0 | for(int i=0; i<bLen; i++)cc[i+aLen] = bb[i]; |
| 835 | |
|
| 836 | 0 | return cc; |
| 837 | |
} |
| 838 | |
|
| 839 | |
|
| 840 | |
public static float[] concatenate(float[] aa, float[] bb){ |
| 841 | 0 | int aLen = aa.length; |
| 842 | 0 | int bLen = bb.length; |
| 843 | 0 | int cLen = aLen + bLen; |
| 844 | 0 | float[] cc = new float[cLen]; |
| 845 | 0 | for(int i=0; i<aLen; i++)cc[i] = aa[i]; |
| 846 | 0 | for(int i=0; i<bLen; i++)cc[i+aLen] = bb[i]; |
| 847 | |
|
| 848 | 0 | return cc; |
| 849 | |
} |
| 850 | |
|
| 851 | |
|
| 852 | |
public static int[] concatenate(int[] aa, int[] bb){ |
| 853 | 0 | int aLen = aa.length; |
| 854 | 0 | int bLen = bb.length; |
| 855 | 0 | int cLen = aLen + bLen; |
| 856 | 0 | int[] cc = new int[cLen]; |
| 857 | 0 | for(int i=0; i<aLen; i++)cc[i] = aa[i]; |
| 858 | 0 | for(int i=0; i<bLen; i++)cc[i+aLen] = bb[i]; |
| 859 | |
|
| 860 | 0 | return cc; |
| 861 | |
} |
| 862 | |
|
| 863 | |
|
| 864 | |
public static long[] concatenate(long[] aa, long[] bb){ |
| 865 | 0 | int aLen = aa.length; |
| 866 | 0 | int bLen = bb.length; |
| 867 | 0 | int cLen = aLen + bLen; |
| 868 | 0 | long[] cc = new long[cLen]; |
| 869 | 0 | for(int i=0; i<aLen; i++)cc[i] = aa[i]; |
| 870 | 0 | for(int i=0; i<bLen; i++)cc[i+aLen] = bb[i]; |
| 871 | |
|
| 872 | 0 | return cc; |
| 873 | |
} |
| 874 | |
|
| 875 | |
|
| 876 | |
public static double[] floatTOdouble(float[] aa){ |
| 877 | 0 | int n = aa.length; |
| 878 | 0 | double[] bb = new double[n]; |
| 879 | 0 | for(int i=0; i<n; i++){ |
| 880 | 0 | bb[i] = (double)aa[i]; |
| 881 | |
} |
| 882 | 0 | return bb; |
| 883 | |
} |
| 884 | |
|
| 885 | |
|
| 886 | |
public static double[] intTOdouble(int[] aa){ |
| 887 | 0 | int n = aa.length; |
| 888 | 0 | double[] bb = new double[n]; |
| 889 | 0 | for(int i=0; i<n; i++){ |
| 890 | 0 | bb[i] = (double)aa[i]; |
| 891 | |
} |
| 892 | 0 | return bb; |
| 893 | |
} |
| 894 | |
|
| 895 | |
|
| 896 | |
public static float[] intTOfloat(int[] aa){ |
| 897 | 0 | int n = aa.length; |
| 898 | 0 | float[] bb = new float[n]; |
| 899 | 0 | for(int i=0; i<n; i++){ |
| 900 | 0 | bb[i] = (float)aa[i]; |
| 901 | |
} |
| 902 | 0 | return bb; |
| 903 | |
} |
| 904 | |
|
| 905 | |
|
| 906 | |
public static long[] intTOlong(int[] aa){ |
| 907 | 0 | int n = aa.length; |
| 908 | 0 | long[] bb = new long[n]; |
| 909 | 0 | for(int i=0; i<n; i++){ |
| 910 | 0 | bb[i] = (long)aa[i]; |
| 911 | |
} |
| 912 | 0 | return bb; |
| 913 | |
} |
| 914 | |
|
| 915 | |
|
| 916 | |
|
| 917 | |
public static double[] longTOdouble(long[] aa){ |
| 918 | 0 | int n = aa.length; |
| 919 | 0 | double[] bb = new double[n]; |
| 920 | 0 | for(int i=0; i<n; i++){ |
| 921 | 0 | bb[i] = (double)aa[i]; |
| 922 | |
} |
| 923 | 0 | return bb; |
| 924 | |
} |
| 925 | |
|
| 926 | |
|
| 927 | |
|
| 928 | |
public static float[] longTOfloat(long[] aa){ |
| 929 | 0 | int n = aa.length; |
| 930 | 0 | float[] bb = new float[n]; |
| 931 | 0 | for(int i=0; i<n; i++){ |
| 932 | 0 | bb[i] = (float)aa[i]; |
| 933 | |
} |
| 934 | 0 | return bb; |
| 935 | |
} |
| 936 | |
|
| 937 | |
|
| 938 | |
public static double[] shortTOdouble(short[] aa){ |
| 939 | 0 | int n = aa.length; |
| 940 | 0 | double[] bb = new double[n]; |
| 941 | 0 | for(int i=0; i<n; i++){ |
| 942 | 0 | bb[i] = (double)aa[i]; |
| 943 | |
} |
| 944 | 0 | return bb; |
| 945 | |
} |
| 946 | |
|
| 947 | |
|
| 948 | |
public static float[] shortTOfloat(short[] aa){ |
| 949 | 0 | int n = aa.length; |
| 950 | 0 | float[] bb = new float[n]; |
| 951 | 0 | for(int i=0; i<n; i++){ |
| 952 | 0 | bb[i] = (float)aa[i]; |
| 953 | |
} |
| 954 | 0 | return bb; |
| 955 | |
} |
| 956 | |
|
| 957 | |
|
| 958 | |
public static long[] shortTOlong(short[] aa){ |
| 959 | 0 | int n = aa.length; |
| 960 | 0 | long[] bb = new long[n]; |
| 961 | 0 | for(int i=0; i<n; i++){ |
| 962 | 0 | bb[i] = (long)aa[i]; |
| 963 | |
} |
| 964 | 0 | return bb; |
| 965 | |
} |
| 966 | |
|
| 967 | |
|
| 968 | |
public static int[] shortTOint(short[] aa){ |
| 969 | 0 | int n = aa.length; |
| 970 | 0 | int[] bb = new int[n]; |
| 971 | 0 | for(int i=0; i<n; i++){ |
| 972 | 0 | bb[i] = (int)aa[i]; |
| 973 | |
} |
| 974 | 0 | return bb; |
| 975 | |
} |
| 976 | |
|
| 977 | |
|
| 978 | |
public static double[] byteTOdouble(byte[] aa){ |
| 979 | 0 | int n = aa.length; |
| 980 | 0 | double[] bb = new double[n]; |
| 981 | 0 | for(int i=0; i<n; i++){ |
| 982 | 0 | bb[i] = (int)aa[i]; |
| 983 | |
} |
| 984 | 0 | return bb; |
| 985 | |
} |
| 986 | |
|
| 987 | |
|
| 988 | |
public static float[] byteTOfloat(byte[] aa){ |
| 989 | 0 | int n = aa.length; |
| 990 | 0 | float[] bb = new float[n]; |
| 991 | 0 | for(int i=0; i<n; i++){ |
| 992 | 0 | bb[i] = (float)aa[i]; |
| 993 | |
} |
| 994 | 0 | return bb; |
| 995 | |
} |
| 996 | |
|
| 997 | |
|
| 998 | |
public static long[] byteTOlong(byte[] aa){ |
| 999 | 0 | int n = aa.length; |
| 1000 | 0 | long[] bb = new long[n]; |
| 1001 | 0 | for(int i=0; i<n; i++){ |
| 1002 | 0 | bb[i] = (long)aa[i]; |
| 1003 | |
} |
| 1004 | 0 | return bb; |
| 1005 | |
} |
| 1006 | |
|
| 1007 | |
|
| 1008 | |
public static int[] byteTOint(byte[] aa){ |
| 1009 | 0 | int n = aa.length; |
| 1010 | 0 | int[] bb = new int[n]; |
| 1011 | 0 | for(int i=0; i<n; i++){ |
| 1012 | 0 | bb[i] = (int)aa[i]; |
| 1013 | |
} |
| 1014 | 0 | return bb; |
| 1015 | |
} |
| 1016 | |
|
| 1017 | |
|
| 1018 | |
public static short[] byteTOshort(byte[] aa){ |
| 1019 | 0 | int n = aa.length; |
| 1020 | 0 | short[] bb = new short[n]; |
| 1021 | 0 | for(int i=0; i<n; i++){ |
| 1022 | 0 | bb[i] = (short)aa[i]; |
| 1023 | |
} |
| 1024 | 0 | return bb; |
| 1025 | |
} |
| 1026 | |
|
| 1027 | |
|
| 1028 | |
|
| 1029 | |
public static int[] doubleTOint(double[] aa){ |
| 1030 | 0 | int n = aa.length; |
| 1031 | 0 | int[] bb = new int[n]; |
| 1032 | 0 | for(int i=0; i<n; i++){ |
| 1033 | 0 | bb[i] = (int)aa[i]; |
| 1034 | |
} |
| 1035 | 0 | return bb; |
| 1036 | |
} |
| 1037 | |
|
| 1038 | |
|
| 1039 | |
|
| 1040 | |
public static void print(double[] aa){ |
| 1041 | 0 | for(int i=0; i<aa.length; i++){ |
| 1042 | 0 | System.out.print(aa[i]+" "); |
| 1043 | |
} |
| 1044 | 0 | System.out.println(); |
| 1045 | 0 | } |
| 1046 | |
|
| 1047 | |
|
| 1048 | |
|
| 1049 | |
public static void println(double[] aa){ |
| 1050 | 0 | for(int i=0; i<aa.length; i++){ |
| 1051 | 0 | System.out.println(aa[i]+" "); |
| 1052 | |
} |
| 1053 | 0 | } |
| 1054 | |
|
| 1055 | |
|
| 1056 | |
|
| 1057 | |
public static void print(float[] aa){ |
| 1058 | 0 | for(int i=0; i<aa.length; i++){ |
| 1059 | 0 | System.out.print(aa[i]+" "); |
| 1060 | |
} |
| 1061 | 0 | System.out.println(); |
| 1062 | 0 | } |
| 1063 | |
|
| 1064 | |
|
| 1065 | |
|
| 1066 | |
public static void println(float[] aa){ |
| 1067 | 0 | for(int i=0; i<aa.length; i++){ |
| 1068 | 0 | System.out.println(aa[i]+" "); |
| 1069 | |
} |
| 1070 | 0 | } |
| 1071 | |
|
| 1072 | |
|
| 1073 | |
|
| 1074 | |
public static void print(int[] aa){ |
| 1075 | 0 | for(int i=0; i<aa.length; i++){ |
| 1076 | 0 | System.out.print(aa[i]+" "); |
| 1077 | |
} |
| 1078 | 0 | System.out.println(); |
| 1079 | 0 | } |
| 1080 | |
|
| 1081 | |
|
| 1082 | |
|
| 1083 | |
public static void println(int[] aa){ |
| 1084 | 0 | for(int i=0; i<aa.length; i++){ |
| 1085 | 0 | System.out.println(aa[i]+" "); |
| 1086 | |
} |
| 1087 | 0 | } |
| 1088 | |
|
| 1089 | |
|
| 1090 | |
|
| 1091 | |
public static void print(long[] aa){ |
| 1092 | 0 | for(int i=0; i<aa.length; i++){ |
| 1093 | 0 | System.out.print(aa[i]+" "); |
| 1094 | |
} |
| 1095 | 0 | System.out.println(); |
| 1096 | 0 | } |
| 1097 | |
|
| 1098 | |
|
| 1099 | |
|
| 1100 | |
public static void println(long[] aa){ |
| 1101 | 0 | for(int i=0; i<aa.length; i++){ |
| 1102 | 0 | System.out.println(aa[i]+" "); |
| 1103 | |
} |
| 1104 | 0 | } |
| 1105 | |
|
| 1106 | |
|
| 1107 | |
|
| 1108 | |
public static void print(char[] aa){ |
| 1109 | 0 | for(int i=0; i<aa.length; i++){ |
| 1110 | 0 | System.out.print(aa[i]+" "); |
| 1111 | |
} |
| 1112 | 0 | System.out.println(); |
| 1113 | 0 | } |
| 1114 | |
|
| 1115 | |
|
| 1116 | |
|
| 1117 | |
public static void println(char[] aa){ |
| 1118 | 0 | for(int i=0; i<aa.length; i++){ |
| 1119 | 0 | System.out.println(aa[i]+" "); |
| 1120 | |
} |
| 1121 | 0 | } |
| 1122 | |
|
| 1123 | |
|
| 1124 | |
|
| 1125 | |
public static void print(String[] aa){ |
| 1126 | 0 | for(int i=0; i<aa.length; i++){ |
| 1127 | 0 | System.out.print(aa[i]+" "); |
| 1128 | |
} |
| 1129 | 0 | System.out.println(); |
| 1130 | 0 | } |
| 1131 | |
|
| 1132 | |
|
| 1133 | |
|
| 1134 | |
public static void println(String[] aa){ |
| 1135 | 0 | for(int i=0; i<aa.length; i++){ |
| 1136 | 0 | System.out.println(aa[i]+" "); |
| 1137 | |
} |
| 1138 | 0 | } |
| 1139 | |
|
| 1140 | |
|
| 1141 | |
|
| 1142 | |
|
| 1143 | |
|
| 1144 | |
public static Vector<Object> selectSortVector(double[] aa){ |
| 1145 | 0 | int index = 0; |
| 1146 | 0 | int lastIndex = -1; |
| 1147 | 0 | int n = aa.length; |
| 1148 | 0 | double holdb = 0.0D; |
| 1149 | 0 | int holdi = 0; |
| 1150 | 0 | double[] bb = new double[n]; |
| 1151 | 0 | int[] indices = new int[n]; |
| 1152 | 0 | for(int i=0; i<n; i++){ |
| 1153 | 0 | bb[i]=aa[i]; |
| 1154 | 0 | indices[i]=i; |
| 1155 | |
} |
| 1156 | |
|
| 1157 | 0 | while(lastIndex != n-1){ |
| 1158 | 0 | index = lastIndex+1; |
| 1159 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1160 | 0 | if(bb[i]<bb[index]){ |
| 1161 | 0 | index=i; |
| 1162 | |
} |
| 1163 | |
} |
| 1164 | 0 | lastIndex++; |
| 1165 | 0 | holdb=bb[index]; |
| 1166 | 0 | bb[index]=bb[lastIndex]; |
| 1167 | 0 | bb[lastIndex]=holdb; |
| 1168 | 0 | holdi=indices[index]; |
| 1169 | 0 | indices[index]=indices[lastIndex]; |
| 1170 | 0 | indices[lastIndex]=holdi; |
| 1171 | |
} |
| 1172 | 0 | Vector<Object> vec = new Vector<Object>(); |
| 1173 | 0 | vec.addElement(aa); |
| 1174 | 0 | vec.addElement(bb); |
| 1175 | 0 | vec.addElement(indices); |
| 1176 | 0 | return vec; |
| 1177 | |
} |
| 1178 | |
|
| 1179 | |
|
| 1180 | |
|
| 1181 | |
public static double[] selectionSort(double[] aa){ |
| 1182 | 0 | int index = 0; |
| 1183 | 0 | int lastIndex = -1; |
| 1184 | 0 | int n = aa.length; |
| 1185 | 0 | double hold = 0.0D; |
| 1186 | 0 | double[] bb = new double[n]; |
| 1187 | 0 | for(int i=0; i<n; i++){ |
| 1188 | 0 | bb[i]=aa[i]; |
| 1189 | |
} |
| 1190 | |
|
| 1191 | 0 | while(lastIndex != n-1){ |
| 1192 | 0 | index = lastIndex+1; |
| 1193 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1194 | 0 | if(bb[i]<bb[index]){ |
| 1195 | 0 | index=i; |
| 1196 | |
} |
| 1197 | |
} |
| 1198 | 0 | lastIndex++; |
| 1199 | 0 | hold=bb[index]; |
| 1200 | 0 | bb[index]=bb[lastIndex]; |
| 1201 | 0 | bb[lastIndex]=hold; |
| 1202 | |
} |
| 1203 | 0 | return bb; |
| 1204 | |
} |
| 1205 | |
|
| 1206 | |
|
| 1207 | |
|
| 1208 | |
public static float[] selectionSort(float[] aa){ |
| 1209 | 0 | int index = 0; |
| 1210 | 0 | int lastIndex = -1; |
| 1211 | 0 | int n = aa.length; |
| 1212 | 0 | float hold = 0.0F; |
| 1213 | 0 | float[] bb = new float[n]; |
| 1214 | 0 | for(int i=0; i<n; i++){ |
| 1215 | 0 | bb[i]=aa[i]; |
| 1216 | |
} |
| 1217 | |
|
| 1218 | 0 | while(lastIndex != n-1){ |
| 1219 | 0 | index = lastIndex+1; |
| 1220 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1221 | 0 | if(bb[i]<bb[index]){ |
| 1222 | 0 | index=i; |
| 1223 | |
} |
| 1224 | |
} |
| 1225 | 0 | lastIndex++; |
| 1226 | 0 | hold=bb[index]; |
| 1227 | 0 | bb[index]=bb[lastIndex]; |
| 1228 | 0 | bb[lastIndex]=hold; |
| 1229 | |
} |
| 1230 | 0 | return bb; |
| 1231 | |
} |
| 1232 | |
|
| 1233 | |
|
| 1234 | |
|
| 1235 | |
public static int[] selectionSort(int[] aa){ |
| 1236 | 0 | int index = 0; |
| 1237 | 0 | int lastIndex = -1; |
| 1238 | 0 | int n = aa.length; |
| 1239 | 0 | int hold = 0; |
| 1240 | 0 | int[] bb = new int[n]; |
| 1241 | 0 | for(int i=0; i<n; i++){ |
| 1242 | 0 | bb[i]=aa[i]; |
| 1243 | |
} |
| 1244 | |
|
| 1245 | 0 | while(lastIndex != n-1){ |
| 1246 | 0 | index = lastIndex+1; |
| 1247 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1248 | 0 | if(bb[i]<bb[index]){ |
| 1249 | 0 | index=i; |
| 1250 | |
} |
| 1251 | |
} |
| 1252 | 0 | lastIndex++; |
| 1253 | 0 | hold=bb[index]; |
| 1254 | 0 | bb[index]=bb[lastIndex]; |
| 1255 | 0 | bb[lastIndex]=hold; |
| 1256 | |
} |
| 1257 | 0 | return bb; |
| 1258 | |
} |
| 1259 | |
|
| 1260 | |
|
| 1261 | |
|
| 1262 | |
public static long[] selectionSort(long[] aa){ |
| 1263 | 0 | int index = 0; |
| 1264 | 0 | int lastIndex = -1; |
| 1265 | 0 | int n = aa.length; |
| 1266 | 0 | long hold = 0L; |
| 1267 | 0 | long[] bb = new long[n]; |
| 1268 | 0 | for(int i=0; i<n; i++){ |
| 1269 | 0 | bb[i]=aa[i]; |
| 1270 | |
} |
| 1271 | |
|
| 1272 | 0 | while(lastIndex != n-1){ |
| 1273 | 0 | index = lastIndex+1; |
| 1274 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1275 | 0 | if(bb[i]<bb[index]){ |
| 1276 | 0 | index=i; |
| 1277 | |
} |
| 1278 | |
} |
| 1279 | 0 | lastIndex++; |
| 1280 | 0 | hold=bb[index]; |
| 1281 | 0 | bb[index]=bb[lastIndex]; |
| 1282 | 0 | bb[lastIndex]=hold; |
| 1283 | |
} |
| 1284 | 0 | return bb; |
| 1285 | |
} |
| 1286 | |
|
| 1287 | |
|
| 1288 | |
|
| 1289 | |
|
| 1290 | |
|
| 1291 | |
public static void selectionSort(double[] aa, double[] bb, int[] indices){ |
| 1292 | 0 | int index = 0; |
| 1293 | 0 | int lastIndex = -1; |
| 1294 | 0 | int n = aa.length; |
| 1295 | 0 | double holdb = 0.0D; |
| 1296 | 0 | int holdi = 0; |
| 1297 | 0 | for(int i=0; i<n; i++){ |
| 1298 | 0 | bb[i]=aa[i]; |
| 1299 | 0 | indices[i]=i; |
| 1300 | |
} |
| 1301 | |
|
| 1302 | 0 | while(lastIndex != n-1){ |
| 1303 | 0 | index = lastIndex+1; |
| 1304 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1305 | 0 | if(bb[i]<bb[index]){ |
| 1306 | 0 | index=i; |
| 1307 | |
} |
| 1308 | |
} |
| 1309 | 0 | lastIndex++; |
| 1310 | 0 | holdb=bb[index]; |
| 1311 | 0 | bb[index]=bb[lastIndex]; |
| 1312 | 0 | bb[lastIndex]=holdb; |
| 1313 | 0 | holdi=indices[index]; |
| 1314 | 0 | indices[index]=indices[lastIndex]; |
| 1315 | 0 | indices[lastIndex]=holdi; |
| 1316 | |
} |
| 1317 | 0 | } |
| 1318 | |
|
| 1319 | |
|
| 1320 | |
|
| 1321 | |
|
| 1322 | |
|
| 1323 | |
|
| 1324 | |
public static void selectionSort(double[] aa, double[] bb, double[] cc, double[] dd){ |
| 1325 | 0 | int index = 0; |
| 1326 | 0 | int lastIndex = -1; |
| 1327 | 0 | int n = aa.length; |
| 1328 | 0 | int m = bb.length; |
| 1329 | 0 | if(n!=m)throw new IllegalArgumentException("First argument array, aa, (length = " + n + ") and the second argument array, bb, (length = " + m + ") should be the same length"); |
| 1330 | 0 | int nn = cc.length; |
| 1331 | 0 | if(nn<n)throw new IllegalArgumentException("The third argument array, cc, (length = " + nn + ") should be at least as long as the first argument array, aa, (length = " + n + ")"); |
| 1332 | 0 | int mm = dd.length; |
| 1333 | 0 | if(mm<m)throw new IllegalArgumentException("The fourth argument array, dd, (length = " + mm + ") should be at least as long as the second argument array, bb, (length = " + m + ")"); |
| 1334 | |
|
| 1335 | 0 | double holdx = 0.0D; |
| 1336 | 0 | double holdy = 0.0D; |
| 1337 | |
|
| 1338 | |
|
| 1339 | 0 | for(int i=0; i<n; i++){ |
| 1340 | 0 | cc[i]=aa[i]; |
| 1341 | 0 | dd[i]=bb[i]; |
| 1342 | |
} |
| 1343 | |
|
| 1344 | 0 | while(lastIndex != n-1){ |
| 1345 | 0 | index = lastIndex+1; |
| 1346 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1347 | 0 | if(cc[i]<cc[index]){ |
| 1348 | 0 | index=i; |
| 1349 | |
} |
| 1350 | |
} |
| 1351 | 0 | lastIndex++; |
| 1352 | 0 | holdx=cc[index]; |
| 1353 | 0 | cc[index]=cc[lastIndex]; |
| 1354 | 0 | cc[lastIndex]=holdx; |
| 1355 | 0 | holdy=dd[index]; |
| 1356 | 0 | dd[index]=dd[lastIndex]; |
| 1357 | 0 | dd[lastIndex]=holdy; |
| 1358 | |
} |
| 1359 | 0 | } |
| 1360 | |
|
| 1361 | |
public static void selectionSort(float[] aa, float[] bb, float[] cc, float[] dd){ |
| 1362 | 0 | int index = 0; |
| 1363 | 0 | int lastIndex = -1; |
| 1364 | 0 | int n = aa.length; |
| 1365 | 0 | int m = bb.length; |
| 1366 | 0 | if(n!=m)throw new IllegalArgumentException("First argument array, aa, (length = " + n + ") and the second argument array, bb, (length = " + m + ") should be the same length"); |
| 1367 | 0 | int nn = cc.length; |
| 1368 | 0 | if(nn<n)throw new IllegalArgumentException("The third argument array, cc, (length = " + nn + ") should be at least as long as the first argument array, aa, (length = " + n + ")"); |
| 1369 | 0 | int mm = dd.length; |
| 1370 | 0 | if(mm<m)throw new IllegalArgumentException("The fourth argument array, dd, (length = " + mm + ") should be at least as long as the second argument array, bb, (length = " + m + ")"); |
| 1371 | |
|
| 1372 | 0 | float holdx = 0.0F; |
| 1373 | 0 | float holdy = 0.0F; |
| 1374 | |
|
| 1375 | |
|
| 1376 | 0 | for(int i=0; i<n; i++){ |
| 1377 | 0 | cc[i]=aa[i]; |
| 1378 | 0 | dd[i]=bb[i]; |
| 1379 | |
} |
| 1380 | |
|
| 1381 | 0 | while(lastIndex != n-1){ |
| 1382 | 0 | index = lastIndex+1; |
| 1383 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1384 | 0 | if(cc[i]<cc[index]){ |
| 1385 | 0 | index=i; |
| 1386 | |
} |
| 1387 | |
} |
| 1388 | 0 | lastIndex++; |
| 1389 | 0 | holdx=cc[index]; |
| 1390 | 0 | cc[index]=cc[lastIndex]; |
| 1391 | 0 | cc[lastIndex]=holdx; |
| 1392 | 0 | holdy=dd[index]; |
| 1393 | 0 | dd[index]=dd[lastIndex]; |
| 1394 | 0 | dd[lastIndex]=holdy; |
| 1395 | |
} |
| 1396 | 0 | } |
| 1397 | |
|
| 1398 | |
public static void selectionSort(long[] aa, long[] bb, long[] cc, long[] dd){ |
| 1399 | 0 | int index = 0; |
| 1400 | 0 | int lastIndex = -1; |
| 1401 | 0 | int n = aa.length; |
| 1402 | 0 | int m = bb.length; |
| 1403 | 0 | if(n!=m)throw new IllegalArgumentException("First argument array, aa, (length = " + n + ") and the second argument array, bb, (length = " + m + ") should be the same length"); |
| 1404 | 0 | int nn = cc.length; |
| 1405 | 0 | if(nn<n)throw new IllegalArgumentException("The third argument array, cc, (length = " + nn + ") should be at least as long as the first argument array, aa, (length = " + n + ")"); |
| 1406 | 0 | int mm = dd.length; |
| 1407 | 0 | if(mm<m)throw new IllegalArgumentException("The fourth argument array, dd, (length = " + mm + ") should be at least as long as the second argument array, bb, (length = " + m + ")"); |
| 1408 | |
|
| 1409 | 0 | long holdx = 0L; |
| 1410 | 0 | long holdy = 0L; |
| 1411 | |
|
| 1412 | |
|
| 1413 | 0 | for(int i=0; i<n; i++){ |
| 1414 | 0 | cc[i]=aa[i]; |
| 1415 | 0 | dd[i]=bb[i]; |
| 1416 | |
} |
| 1417 | |
|
| 1418 | 0 | while(lastIndex != n-1){ |
| 1419 | 0 | index = lastIndex+1; |
| 1420 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1421 | 0 | if(cc[i]<cc[index]){ |
| 1422 | 0 | index=i; |
| 1423 | |
} |
| 1424 | |
} |
| 1425 | 0 | lastIndex++; |
| 1426 | 0 | holdx=cc[index]; |
| 1427 | 0 | cc[index]=cc[lastIndex]; |
| 1428 | 0 | cc[lastIndex]=holdx; |
| 1429 | 0 | holdy=dd[index]; |
| 1430 | 0 | dd[index]=dd[lastIndex]; |
| 1431 | 0 | dd[lastIndex]=holdy; |
| 1432 | |
} |
| 1433 | 0 | } |
| 1434 | |
|
| 1435 | |
public static void selectionSort(int[] aa, int[] bb, int[] cc, int[] dd){ |
| 1436 | 0 | int index = 0; |
| 1437 | 0 | int lastIndex = -1; |
| 1438 | 0 | int n = aa.length; |
| 1439 | 0 | int m = bb.length; |
| 1440 | 0 | if(n!=m)throw new IllegalArgumentException("First argument array, aa, (length = " + n + ") and the second argument array, bb, (length = " + m + ") should be the same length"); |
| 1441 | 0 | int nn = cc.length; |
| 1442 | 0 | if(nn<n)throw new IllegalArgumentException("The third argument array, cc, (length = " + nn + ") should be at least as long as the first argument array, aa, (length = " + n + ")"); |
| 1443 | 0 | int mm = dd.length; |
| 1444 | 0 | if(mm<m)throw new IllegalArgumentException("The fourth argument array, dd, (length = " + mm + ") should be at least as long as the second argument array, bb, (length = " + m + ")"); |
| 1445 | |
|
| 1446 | 0 | int holdx = 0; |
| 1447 | 0 | int holdy = 0; |
| 1448 | |
|
| 1449 | |
|
| 1450 | 0 | for(int i=0; i<n; i++){ |
| 1451 | 0 | cc[i]=aa[i]; |
| 1452 | 0 | dd[i]=bb[i]; |
| 1453 | |
} |
| 1454 | |
|
| 1455 | 0 | while(lastIndex != n-1){ |
| 1456 | 0 | index = lastIndex+1; |
| 1457 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1458 | 0 | if(cc[i]<cc[index]){ |
| 1459 | 0 | index=i; |
| 1460 | |
} |
| 1461 | |
} |
| 1462 | 0 | lastIndex++; |
| 1463 | 0 | holdx=cc[index]; |
| 1464 | 0 | cc[index]=cc[lastIndex]; |
| 1465 | 0 | cc[lastIndex]=holdx; |
| 1466 | 0 | holdy=dd[index]; |
| 1467 | 0 | dd[index]=dd[lastIndex]; |
| 1468 | 0 | dd[lastIndex]=holdy; |
| 1469 | |
} |
| 1470 | 0 | } |
| 1471 | |
|
| 1472 | |
public static void selectionSort(double[] aa, long[] bb, double[] cc, long[] dd){ |
| 1473 | 0 | int index = 0; |
| 1474 | 0 | int lastIndex = -1; |
| 1475 | 0 | int n = aa.length; |
| 1476 | 0 | int m = bb.length; |
| 1477 | 0 | if(n!=m)throw new IllegalArgumentException("First argument array, aa, (length = " + n + ") and the second argument array, bb, (length = " + m + ") should be the same length"); |
| 1478 | 0 | int nn = cc.length; |
| 1479 | 0 | if(nn<n)throw new IllegalArgumentException("The third argument array, cc, (length = " + nn + ") should be at least as long as the first argument array, aa, (length = " + n + ")"); |
| 1480 | 0 | int mm = dd.length; |
| 1481 | 0 | if(mm<m)throw new IllegalArgumentException("The fourth argument array, dd, (length = " + mm + ") should be at least as long as the second argument array, bb, (length = " + m + ")"); |
| 1482 | |
|
| 1483 | 0 | double holdx = 0.0D; |
| 1484 | 0 | long holdy = 0L; |
| 1485 | |
|
| 1486 | |
|
| 1487 | 0 | for(int i=0; i<n; i++){ |
| 1488 | 0 | cc[i]=aa[i]; |
| 1489 | 0 | dd[i]=bb[i]; |
| 1490 | |
} |
| 1491 | |
|
| 1492 | 0 | while(lastIndex != n-1){ |
| 1493 | 0 | index = lastIndex+1; |
| 1494 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1495 | 0 | if(cc[i]<cc[index]){ |
| 1496 | 0 | index=i; |
| 1497 | |
} |
| 1498 | |
} |
| 1499 | 0 | lastIndex++; |
| 1500 | 0 | holdx=cc[index]; |
| 1501 | 0 | cc[index]=cc[lastIndex]; |
| 1502 | 0 | cc[lastIndex]=holdx; |
| 1503 | 0 | holdy=dd[index]; |
| 1504 | 0 | dd[index]=dd[lastIndex]; |
| 1505 | 0 | dd[lastIndex]=holdy; |
| 1506 | |
} |
| 1507 | 0 | } |
| 1508 | |
|
| 1509 | |
public static void selectionSort(long[] aa, double[] bb, long[] cc, double[] dd){ |
| 1510 | 0 | int index = 0; |
| 1511 | 0 | int lastIndex = -1; |
| 1512 | 0 | int n = aa.length; |
| 1513 | 0 | int m = bb.length; |
| 1514 | 0 | if(n!=m)throw new IllegalArgumentException("First argument array, aa, (length = " + n + ") and the second argument array, bb, (length = " + m + ") should be the same length"); |
| 1515 | 0 | int nn = cc.length; |
| 1516 | 0 | if(nn<n)throw new IllegalArgumentException("The third argument array, cc, (length = " + nn + ") should be at least as long as the first argument array, aa, (length = " + n + ")"); |
| 1517 | 0 | int mm = dd.length; |
| 1518 | 0 | if(mm<m)throw new IllegalArgumentException("The fourth argument array, dd, (length = " + mm + ") should be at least as long as the second argument array, bb, (length = " + m + ")"); |
| 1519 | |
|
| 1520 | 0 | long holdx = 0L; |
| 1521 | 0 | double holdy = 0.0D; |
| 1522 | |
|
| 1523 | |
|
| 1524 | 0 | for(int i=0; i<n; i++){ |
| 1525 | 0 | cc[i]=aa[i]; |
| 1526 | 0 | dd[i]=bb[i]; |
| 1527 | |
} |
| 1528 | |
|
| 1529 | 0 | while(lastIndex != n-1){ |
| 1530 | 0 | index = lastIndex+1; |
| 1531 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1532 | 0 | if(cc[i]<cc[index]){ |
| 1533 | 0 | index=i; |
| 1534 | |
} |
| 1535 | |
} |
| 1536 | 0 | lastIndex++; |
| 1537 | 0 | holdx=cc[index]; |
| 1538 | 0 | cc[index]=cc[lastIndex]; |
| 1539 | 0 | cc[lastIndex]=holdx; |
| 1540 | 0 | holdy=dd[index]; |
| 1541 | 0 | dd[index]=dd[lastIndex]; |
| 1542 | 0 | dd[lastIndex]=holdy; |
| 1543 | |
} |
| 1544 | 0 | } |
| 1545 | |
|
| 1546 | |
|
| 1547 | |
public static void selectionSort(double[] aa, int[] bb, double[] cc, int[] dd){ |
| 1548 | 0 | int index = 0; |
| 1549 | 0 | int lastIndex = -1; |
| 1550 | 0 | int n = aa.length; |
| 1551 | 0 | int m = bb.length; |
| 1552 | 0 | if(n!=m)throw new IllegalArgumentException("First argument array, aa, (length = " + n + ") and the second argument array, bb, (length = " + m + ") should be the same length"); |
| 1553 | 0 | int nn = cc.length; |
| 1554 | 0 | if(nn<n)throw new IllegalArgumentException("The third argument array, cc, (length = " + nn + ") should be at least as long as the first argument array, aa, (length = " + n + ")"); |
| 1555 | 0 | int mm = dd.length; |
| 1556 | 0 | if(mm<m)throw new IllegalArgumentException("The fourth argument array, dd, (length = " + mm + ") should be at least as long as the second argument array, bb, (length = " + m + ")"); |
| 1557 | |
|
| 1558 | 0 | double holdx = 0.0D; |
| 1559 | 0 | int holdy = 0; |
| 1560 | |
|
| 1561 | |
|
| 1562 | 0 | for(int i=0; i<n; i++){ |
| 1563 | 0 | cc[i]=aa[i]; |
| 1564 | 0 | dd[i]=bb[i]; |
| 1565 | |
} |
| 1566 | |
|
| 1567 | 0 | while(lastIndex != n-1){ |
| 1568 | 0 | index = lastIndex+1; |
| 1569 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1570 | 0 | if(cc[i]<cc[index]){ |
| 1571 | 0 | index=i; |
| 1572 | |
} |
| 1573 | |
} |
| 1574 | 0 | lastIndex++; |
| 1575 | 0 | holdx=cc[index]; |
| 1576 | 0 | cc[index]=cc[lastIndex]; |
| 1577 | 0 | cc[lastIndex]=holdx; |
| 1578 | 0 | holdy=dd[index]; |
| 1579 | 0 | dd[index]=dd[lastIndex]; |
| 1580 | 0 | dd[lastIndex]=holdy; |
| 1581 | |
} |
| 1582 | 0 | } |
| 1583 | |
|
| 1584 | |
public static void selectionSort(int[] aa, double[] bb, int[] cc, double[] dd){ |
| 1585 | 0 | int index = 0; |
| 1586 | 0 | int lastIndex = -1; |
| 1587 | 0 | int n = aa.length; |
| 1588 | 0 | int m = bb.length; |
| 1589 | 0 | if(n!=m)throw new IllegalArgumentException("First argument array, aa, (length = " + n + ") and the second argument array, bb, (length = " + m + ") should be the same length"); |
| 1590 | 0 | int nn = cc.length; |
| 1591 | 0 | if(nn<n)throw new IllegalArgumentException("The third argument array, cc, (length = " + nn + ") should be at least as long as the first argument array, aa, (length = " + n + ")"); |
| 1592 | 0 | int mm = dd.length; |
| 1593 | 0 | if(mm<m)throw new IllegalArgumentException("The fourth argument array, dd, (length = " + mm + ") should be at least as long as the second argument array, bb, (length = " + m + ")"); |
| 1594 | |
|
| 1595 | 0 | int holdx = 0; |
| 1596 | 0 | double holdy = 0.0D; |
| 1597 | |
|
| 1598 | |
|
| 1599 | 0 | for(int i=0; i<n; i++){ |
| 1600 | 0 | cc[i]=aa[i]; |
| 1601 | 0 | dd[i]=bb[i]; |
| 1602 | |
} |
| 1603 | |
|
| 1604 | 0 | while(lastIndex != n-1){ |
| 1605 | 0 | index = lastIndex+1; |
| 1606 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1607 | 0 | if(cc[i]<cc[index]){ |
| 1608 | 0 | index=i; |
| 1609 | |
} |
| 1610 | |
} |
| 1611 | 0 | lastIndex++; |
| 1612 | 0 | holdx=cc[index]; |
| 1613 | 0 | cc[index]=cc[lastIndex]; |
| 1614 | 0 | cc[lastIndex]=holdx; |
| 1615 | 0 | holdy=dd[index]; |
| 1616 | 0 | dd[index]=dd[lastIndex]; |
| 1617 | 0 | dd[lastIndex]=holdy; |
| 1618 | |
} |
| 1619 | 0 | } |
| 1620 | |
|
| 1621 | |
public static void selectionSort(long[] aa, int[] bb, long[] cc, int[] dd){ |
| 1622 | 0 | int index = 0; |
| 1623 | 0 | int lastIndex = -1; |
| 1624 | 0 | int n = aa.length; |
| 1625 | 0 | int m = bb.length; |
| 1626 | 0 | if(n!=m)throw new IllegalArgumentException("First argument array, aa, (length = " + n + ") and the second argument array, bb, (length = " + m + ") should be the same length"); |
| 1627 | 0 | int nn = cc.length; |
| 1628 | 0 | if(nn<n)throw new IllegalArgumentException("The third argument array, cc, (length = " + nn + ") should be at least as long as the first argument array, aa, (length = " + n + ")"); |
| 1629 | 0 | int mm = dd.length; |
| 1630 | 0 | if(mm<m)throw new IllegalArgumentException("The fourth argument array, dd, (length = " + mm + ") should be at least as long as the second argument array, bb, (length = " + m + ")"); |
| 1631 | |
|
| 1632 | 0 | long holdx = 0L; |
| 1633 | 0 | int holdy = 0; |
| 1634 | |
|
| 1635 | |
|
| 1636 | 0 | for(int i=0; i<n; i++){ |
| 1637 | 0 | cc[i]=aa[i]; |
| 1638 | 0 | dd[i]=bb[i]; |
| 1639 | |
} |
| 1640 | |
|
| 1641 | 0 | while(lastIndex != n-1){ |
| 1642 | 0 | index = lastIndex+1; |
| 1643 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1644 | 0 | if(cc[i]<cc[index]){ |
| 1645 | 0 | index=i; |
| 1646 | |
} |
| 1647 | |
} |
| 1648 | 0 | lastIndex++; |
| 1649 | 0 | holdx=cc[index]; |
| 1650 | 0 | cc[index]=cc[lastIndex]; |
| 1651 | 0 | cc[lastIndex]=holdx; |
| 1652 | 0 | holdy=dd[index]; |
| 1653 | 0 | dd[index]=dd[lastIndex]; |
| 1654 | 0 | dd[lastIndex]=holdy; |
| 1655 | |
} |
| 1656 | 0 | } |
| 1657 | |
|
| 1658 | |
public static void selectionSort(int[] aa, long[] bb, int[] cc, long[] dd){ |
| 1659 | 0 | int index = 0; |
| 1660 | 0 | int lastIndex = -1; |
| 1661 | 0 | int n = aa.length; |
| 1662 | 0 | int m = bb.length; |
| 1663 | 0 | if(n!=m)throw new IllegalArgumentException("First argument array, aa, (length = " + n + ") and the second argument array, bb, (length = " + m + ") should be the same length"); |
| 1664 | 0 | int nn = cc.length; |
| 1665 | 0 | if(nn<n)throw new IllegalArgumentException("The third argument array, cc, (length = " + nn + ") should be at least as long as the first argument array, aa, (length = " + n + ")"); |
| 1666 | 0 | int mm = dd.length; |
| 1667 | 0 | if(mm<m)throw new IllegalArgumentException("The fourth argument array, dd, (length = " + mm + ") should be at least as long as the second argument array, bb, (length = " + m + ")"); |
| 1668 | |
|
| 1669 | 0 | int holdx = 0; |
| 1670 | 0 | long holdy = 0L; |
| 1671 | |
|
| 1672 | |
|
| 1673 | 0 | for(int i=0; i<n; i++){ |
| 1674 | 0 | cc[i]=aa[i]; |
| 1675 | 0 | dd[i]=bb[i]; |
| 1676 | |
} |
| 1677 | |
|
| 1678 | 0 | while(lastIndex != n-1){ |
| 1679 | 0 | index = lastIndex+1; |
| 1680 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1681 | 0 | if(cc[i]<cc[index]){ |
| 1682 | 0 | index=i; |
| 1683 | |
} |
| 1684 | |
} |
| 1685 | 0 | lastIndex++; |
| 1686 | 0 | holdx=cc[index]; |
| 1687 | 0 | cc[index]=cc[lastIndex]; |
| 1688 | 0 | cc[lastIndex]=holdx; |
| 1689 | 0 | holdy=dd[index]; |
| 1690 | 0 | dd[index]=dd[lastIndex]; |
| 1691 | 0 | dd[lastIndex]=holdy; |
| 1692 | |
} |
| 1693 | 0 | } |
| 1694 | |
|
| 1695 | |
|
| 1696 | |
|
| 1697 | |
|
| 1698 | |
|
| 1699 | |
|
| 1700 | |
public static void selectSort(double[] aa, double[] bb, int[] indices){ |
| 1701 | 0 | int index = 0; |
| 1702 | 0 | int lastIndex = -1; |
| 1703 | 0 | int n = aa.length; |
| 1704 | 0 | int m = bb.length; |
| 1705 | 0 | if(m<n)throw new IllegalArgumentException("The second argument array, bb, (length = " + m + ") should be at least as long as the first argument array, aa, (length = " + n + ")"); |
| 1706 | 0 | int k = indices.length; |
| 1707 | 0 | if(m<n)throw new IllegalArgumentException("The third argument array, indices, (length = " + k + ") should be at least as long as the first argument array, aa, (length = " + n + ")"); |
| 1708 | |
|
| 1709 | 0 | double holdb = 0.0D; |
| 1710 | 0 | int holdi = 0; |
| 1711 | 0 | for(int i=0; i<n; i++){ |
| 1712 | 0 | bb[i]=aa[i]; |
| 1713 | 0 | indices[i]=i; |
| 1714 | |
} |
| 1715 | |
|
| 1716 | 0 | while(lastIndex != n-1){ |
| 1717 | 0 | index = lastIndex+1; |
| 1718 | 0 | for(int i=lastIndex+2; i<n; i++){ |
| 1719 | 0 | if(bb[i]<bb[index]){ |
| 1720 | 0 | index=i; |
| 1721 | |
} |
| 1722 | |
} |
| 1723 | 0 | lastIndex++; |
| 1724 | 0 | holdb=bb[index]; |
| 1725 | 0 | bb[index]=bb[lastIndex]; |
| 1726 | 0 | bb[lastIndex]=holdb; |
| 1727 | 0 | holdi=indices[index]; |
| 1728 | 0 | indices[index]=indices[lastIndex]; |
| 1729 | 0 | indices[lastIndex]=holdi; |
| 1730 | |
} |
| 1731 | 0 | } |
| 1732 | |
|
| 1733 | |
|
| 1734 | |
|
| 1735 | |
public static double sign(double x){ |
| 1736 | 0 | if (x<0.0){ |
| 1737 | 0 | return -1.0; |
| 1738 | |
} |
| 1739 | |
else{ |
| 1740 | 0 | return 1.0; |
| 1741 | |
} |
| 1742 | |
} |
| 1743 | |
|
| 1744 | |
|
| 1745 | |
|
| 1746 | |
public static float sign(float x){ |
| 1747 | 0 | if (x<0.0F){ |
| 1748 | 0 | return -1.0F; |
| 1749 | |
} |
| 1750 | |
else{ |
| 1751 | 0 | return 1.0F; |
| 1752 | |
} |
| 1753 | |
} |
| 1754 | |
|
| 1755 | |
|
| 1756 | |
|
| 1757 | |
public static int sign(int x){ |
| 1758 | 0 | if (x<0){ |
| 1759 | 0 | return -1; |
| 1760 | |
} |
| 1761 | |
else{ |
| 1762 | 0 | return 1; |
| 1763 | |
} |
| 1764 | |
} |
| 1765 | |
|
| 1766 | |
|
| 1767 | |
|
| 1768 | |
public static long sign(long x){ |
| 1769 | 0 | if (x<0){ |
| 1770 | 0 | return -1; |
| 1771 | |
} |
| 1772 | |
else{ |
| 1773 | 0 | return 1; |
| 1774 | |
} |
| 1775 | |
} |
| 1776 | |
|
| 1777 | |
|
| 1778 | |
|
| 1779 | |
|
| 1780 | |
public static double radToDeg(double rad){ |
| 1781 | 0 | return rad*180.0D/Math.PI; |
| 1782 | |
} |
| 1783 | |
|
| 1784 | |
|
| 1785 | |
public static double degToRad(double deg){ |
| 1786 | 0 | return deg*Math.PI/180.0D; |
| 1787 | |
} |
| 1788 | |
|
| 1789 | |
|
| 1790 | |
public static double evToNm(double ev){ |
| 1791 | 0 | return 1e+9*C_LIGHT/(-ev*Q_ELECTRON/H_PLANCK); |
| 1792 | |
} |
| 1793 | |
|
| 1794 | |
|
| 1795 | |
public static double nmToEv(double nm) |
| 1796 | |
{ |
| 1797 | 0 | return C_LIGHT/(-nm*1e-9)*H_PLANCK/Q_ELECTRON; |
| 1798 | |
} |
| 1799 | |
|
| 1800 | |
|
| 1801 | |
public static double molarToPercentWeightByVol(double molar, double molWeight){ |
| 1802 | 0 | return molar*molWeight/10.0D; |
| 1803 | |
} |
| 1804 | |
|
| 1805 | |
|
| 1806 | |
public static double percentWeightByVolToMolar(double perCent, double molWeight){ |
| 1807 | 0 | return perCent*10.0D/molWeight; |
| 1808 | |
} |
| 1809 | |
|
| 1810 | |
|
| 1811 | |
public static double celsiusToKelvin(double cels){ |
| 1812 | 0 | return cels-T_ABS; |
| 1813 | |
} |
| 1814 | |
|
| 1815 | |
|
| 1816 | |
public static double kelvinToCelsius(double kelv){ |
| 1817 | 0 | return kelv+T_ABS; |
| 1818 | |
} |
| 1819 | |
|
| 1820 | |
|
| 1821 | |
public static double celsiusToFahren(double cels){ |
| 1822 | 0 | return cels*(9.0/5.0)+32.0; |
| 1823 | |
} |
| 1824 | |
|
| 1825 | |
|
| 1826 | |
public static double fahrenToCelsius(double fahr){ |
| 1827 | 0 | return (fahr-32.0)*5.0/9.0; |
| 1828 | |
} |
| 1829 | |
|
| 1830 | |
|
| 1831 | |
public static double calorieToJoule(double cal){ |
| 1832 | 0 | return cal*4.1868; |
| 1833 | |
} |
| 1834 | |
|
| 1835 | |
|
| 1836 | |
public static double jouleToCalorie(double joule){ |
| 1837 | 0 | return joule*0.23884; |
| 1838 | |
} |
| 1839 | |
|
| 1840 | |
|
| 1841 | |
public static double gramToOunce(double gm){ |
| 1842 | 0 | return gm/28.3459; |
| 1843 | |
} |
| 1844 | |
|
| 1845 | |
|
| 1846 | |
public static double ounceToGram(double oz){ |
| 1847 | 0 | return oz*28.3459; |
| 1848 | |
} |
| 1849 | |
|
| 1850 | |
|
| 1851 | |
public static double kgToPound(double kg){ |
| 1852 | 0 | return kg/0.4536; |
| 1853 | |
} |
| 1854 | |
|
| 1855 | |
|
| 1856 | |
public static double poundToKg(double pds){ |
| 1857 | 0 | return pds*0.4536; |
| 1858 | |
} |
| 1859 | |
|
| 1860 | |
|
| 1861 | |
public static double kgToTon(double kg){ |
| 1862 | 0 | return kg/1016.05; |
| 1863 | |
} |
| 1864 | |
|
| 1865 | |
|
| 1866 | |
public static double tonToKg(double tons){ |
| 1867 | 0 | return tons*1016.05; |
| 1868 | |
} |
| 1869 | |
|
| 1870 | |
|
| 1871 | |
public static double millimetreToInch(double mm){ |
| 1872 | 0 | return mm/25.4; |
| 1873 | |
} |
| 1874 | |
|
| 1875 | |
|
| 1876 | |
public static double inchToMillimetre(double in){ |
| 1877 | 0 | return in*25.4; |
| 1878 | |
} |
| 1879 | |
|
| 1880 | |
|
| 1881 | |
public static double footToMetre(double ft){ |
| 1882 | 0 | return ft*0.3048; |
| 1883 | |
} |
| 1884 | |
|
| 1885 | |
|
| 1886 | |
public static double metreToFoot(double metre){ |
| 1887 | 0 | return metre/0.3048; |
| 1888 | |
} |
| 1889 | |
|
| 1890 | |
|
| 1891 | |
public static double yardToMetre(double yd){ |
| 1892 | 0 | return yd*0.9144; |
| 1893 | |
} |
| 1894 | |
|
| 1895 | |
|
| 1896 | |
public static double metreToYard(double metre){ |
| 1897 | 0 | return metre/0.9144; |
| 1898 | |
} |
| 1899 | |
|
| 1900 | |
|
| 1901 | |
public static double mileToKm(double mile){ |
| 1902 | 0 | return mile*1.6093; |
| 1903 | |
} |
| 1904 | |
|
| 1905 | |
|
| 1906 | |
public static double kmToMile(double km){ |
| 1907 | 0 | return km/1.6093; |
| 1908 | |
} |
| 1909 | |
|
| 1910 | |
|
| 1911 | |
public static double gallonToLitre(double gall){ |
| 1912 | 0 | return gall*4.546; |
| 1913 | |
} |
| 1914 | |
|
| 1915 | |
|
| 1916 | |
public static double litreToGallon(double litre){ |
| 1917 | 0 | return litre/4.546; |
| 1918 | |
} |
| 1919 | |
|
| 1920 | |
|
| 1921 | |
public static double quartToLitre(double quart){ |
| 1922 | 0 | return quart*1.137; |
| 1923 | |
} |
| 1924 | |
|
| 1925 | |
|
| 1926 | |
public static double litreToQuart(double litre){ |
| 1927 | 0 | return litre/1.137; |
| 1928 | |
} |
| 1929 | |
|
| 1930 | |
|
| 1931 | |
public static double pintToLitre(double pint){ |
| 1932 | 0 | return pint*0.568; |
| 1933 | |
} |
| 1934 | |
|
| 1935 | |
|
| 1936 | |
public static double litreToPint(double litre){ |
| 1937 | 0 | return litre/0.568; |
| 1938 | |
} |
| 1939 | |
|
| 1940 | |
|
| 1941 | |
public static double gallonPerMileToLitrePerKm(double gallPmile){ |
| 1942 | 0 | return gallPmile*2.825; |
| 1943 | |
} |
| 1944 | |
|
| 1945 | |
|
| 1946 | |
public static double litrePerKmToGallonPerMile(double litrePkm){ |
| 1947 | 0 | return litrePkm/2.825; |
| 1948 | |
} |
| 1949 | |
|
| 1950 | |
|
| 1951 | |
public static double milePerGallonToKmPerLitre(double milePgall){ |
| 1952 | 0 | return milePgall*0.354; |
| 1953 | |
} |
| 1954 | |
|
| 1955 | |
|
| 1956 | |
public static double kmPerLitreToMilePerGallon(double kmPlitre){ |
| 1957 | 0 | return kmPlitre/0.354; |
| 1958 | |
} |
| 1959 | |
|
| 1960 | |
|
| 1961 | |
public static double fluidOunceUKtoUS(double flOzUK){ |
| 1962 | 0 | return flOzUK*0.961; |
| 1963 | |
} |
| 1964 | |
|
| 1965 | |
|
| 1966 | |
public static double fluidOunceUStoUK(double flOzUS){ |
| 1967 | 0 | return flOzUS*1.041; |
| 1968 | |
} |
| 1969 | |
|
| 1970 | |
|
| 1971 | |
public static double pintUKtoUS(double pintUK){ |
| 1972 | 0 | return pintUK*1.201; |
| 1973 | |
} |
| 1974 | |
|
| 1975 | |
|
| 1976 | |
public static double pintUStoUK(double pintUS){ |
| 1977 | 0 | return pintUS*0.833; |
| 1978 | |
} |
| 1979 | |
|
| 1980 | |
|
| 1981 | |
public static double quartUKtoUS(double quartUK){ |
| 1982 | 0 | return quartUK*1.201; |
| 1983 | |
} |
| 1984 | |
|
| 1985 | |
|
| 1986 | |
public static double quartUStoUK(double quartUS){ |
| 1987 | 0 | return quartUS*0.833; |
| 1988 | |
} |
| 1989 | |
|
| 1990 | |
|
| 1991 | |
public static double gallonUKtoUS(double gallonUK){ |
| 1992 | 0 | return gallonUK*1.201; |
| 1993 | |
} |
| 1994 | |
|
| 1995 | |
|
| 1996 | |
public static double gallonUStoUK(double gallonUS){ |
| 1997 | 0 | return gallonUS*0.833; |
| 1998 | |
} |
| 1999 | |
|
| 2000 | |
|
| 2001 | |
public static double pintUKtoCupUS(double pintUK){ |
| 2002 | 0 | return pintUK/0.417; |
| 2003 | |
} |
| 2004 | |
|
| 2005 | |
|
| 2006 | |
public static double cupUStoPintUK(double cupUS){ |
| 2007 | 0 | return cupUS*0.417; |
| 2008 | |
} |
| 2009 | |
|
| 2010 | |
|
| 2011 | |
public static double calcBMImetric(double height, double weight){ |
| 2012 | 0 | return weight/(height*height); |
| 2013 | |
} |
| 2014 | |
|
| 2015 | |
|
| 2016 | |
public static double calcBMIimperial(double height, double weight){ |
| 2017 | 0 | height = Fmath.footToMetre(height); |
| 2018 | 0 | weight = Fmath.poundToKg(weight); |
| 2019 | 0 | return weight/(height*height); |
| 2020 | |
} |
| 2021 | |
|
| 2022 | |
|
| 2023 | |
public static double calcWeightFromBMImetric(double bmi, double height){ |
| 2024 | 0 | return bmi*height*height; |
| 2025 | |
} |
| 2026 | |
|
| 2027 | |
|
| 2028 | |
public static double calcWeightFromBMIimperial(double bmi, double height){ |
| 2029 | 0 | height = Fmath.footToMetre(height); |
| 2030 | 0 | double weight = bmi*height*height; |
| 2031 | 0 | weight = Fmath.kgToPound(weight); |
| 2032 | 0 | return weight; |
| 2033 | |
} |
| 2034 | |
|
| 2035 | |
|
| 2036 | |
|
| 2037 | |
|
| 2038 | |
|
| 2039 | |
|
| 2040 | |
|
| 2041 | |
public static double hypot(double aa, double bb){ |
| 2042 | 0 | double amod=Math.abs(aa); |
| 2043 | 0 | double bmod=Math.abs(bb); |
| 2044 | 0 | double cc = 0.0D, ratio = 0.0D; |
| 2045 | 0 | if(amod==0.0){ |
| 2046 | 0 | cc=bmod; |
| 2047 | |
} |
| 2048 | |
else{ |
| 2049 | 0 | if(bmod==0.0){ |
| 2050 | 0 | cc=amod; |
| 2051 | |
} |
| 2052 | |
else{ |
| 2053 | 0 | if(amod>=bmod){ |
| 2054 | 0 | ratio=bmod/amod; |
| 2055 | 0 | cc=amod*Math.sqrt(1.0 + ratio*ratio); |
| 2056 | |
} |
| 2057 | |
else{ |
| 2058 | 0 | ratio=amod/bmod; |
| 2059 | 0 | cc=bmod*Math.sqrt(1.0 + ratio*ratio); |
| 2060 | |
} |
| 2061 | |
} |
| 2062 | |
} |
| 2063 | 0 | return cc; |
| 2064 | |
} |
| 2065 | |
|
| 2066 | |
|
| 2067 | |
|
| 2068 | |
|
| 2069 | |
public static float hypot(float aa, float bb){ |
| 2070 | 0 | return (float) hypot((double) aa, (double) bb); |
| 2071 | |
} |
| 2072 | |
|
| 2073 | |
|
| 2074 | |
|
| 2075 | |
public static double angle(double xAtA, double yAtA, double xAtB, double yAtB, double xAtC, double yAtC){ |
| 2076 | |
|
| 2077 | 0 | double ccos = Fmath.cos(xAtA, yAtA, xAtB, yAtB, xAtC, yAtC); |
| 2078 | 0 | return Math.acos(ccos); |
| 2079 | |
} |
| 2080 | |
|
| 2081 | |
|
| 2082 | |
public static double angle(double sideAC, double sideBC, double sideAB){ |
| 2083 | |
|
| 2084 | 0 | double ccos = Fmath.cos(sideAC, sideBC, sideAB); |
| 2085 | 0 | return Math.acos(ccos); |
| 2086 | |
} |
| 2087 | |
|
| 2088 | |
|
| 2089 | |
|
| 2090 | |
public static double sin(double xAtA, double yAtA, double xAtB, double yAtB, double xAtC, double yAtC){ |
| 2091 | 0 | double angle = Fmath.angle(xAtA, yAtA, xAtB, yAtB, xAtC, yAtC); |
| 2092 | 0 | return Math.sin(angle); |
| 2093 | |
} |
| 2094 | |
|
| 2095 | |
|
| 2096 | |
public static double sin(double sideAC, double sideBC, double sideAB){ |
| 2097 | 0 | double angle = Fmath.angle(sideAC, sideBC, sideAB); |
| 2098 | 0 | return Math.sin(angle); |
| 2099 | |
} |
| 2100 | |
|
| 2101 | |
|
| 2102 | |
|
| 2103 | |
public static double sin(double arg){ |
| 2104 | 0 | return Math.sin(arg); |
| 2105 | |
} |
| 2106 | |
|
| 2107 | |
|
| 2108 | |
|
| 2109 | |
public static double asin(double a){ |
| 2110 | 0 | if(a<-1.0D && a>1.0D) throw new IllegalArgumentException("Fmath.asin argument (" + a + ") must be >= -1.0 and <= 1.0"); |
| 2111 | 0 | return Math.asin(a); |
| 2112 | |
} |
| 2113 | |
|
| 2114 | |
|
| 2115 | |
|
| 2116 | |
public static double cos(double xAtA, double yAtA, double xAtB, double yAtB, double xAtC, double yAtC){ |
| 2117 | 0 | double sideAC = Fmath.hypot(xAtA - xAtC, yAtA - yAtC); |
| 2118 | 0 | double sideBC = Fmath.hypot(xAtB - xAtC, yAtB - yAtC); |
| 2119 | 0 | double sideAB = Fmath.hypot(xAtA - xAtB, yAtA - yAtB); |
| 2120 | 0 | return Fmath.cos(sideAC, sideBC, sideAB); |
| 2121 | |
} |
| 2122 | |
|
| 2123 | |
|
| 2124 | |
public static double cos(double sideAC, double sideBC, double sideAB){ |
| 2125 | 0 | return 0.5D*(sideAC/sideBC + sideBC/sideAC - (sideAB/sideAC)*(sideAB/sideBC)); |
| 2126 | |
} |
| 2127 | |
|
| 2128 | |
|
| 2129 | |
|
| 2130 | |
public static double cos(double arg){ |
| 2131 | 0 | return Math.cos(arg); |
| 2132 | |
} |
| 2133 | |
|
| 2134 | |
|
| 2135 | |
|
| 2136 | |
public static double acos(double a){ |
| 2137 | 0 | if(a<-1.0D || a>1.0D) throw new IllegalArgumentException("Fmath.acos argument (" + a + ") must be >= -1.0 and <= 1.0"); |
| 2138 | 0 | return Math.acos(a); |
| 2139 | |
} |
| 2140 | |
|
| 2141 | |
|
| 2142 | |
|
| 2143 | |
public static double tan(double xAtA, double yAtA, double xAtB, double yAtB, double xAtC, double yAtC){ |
| 2144 | 0 | double angle = Fmath.angle(xAtA, yAtA, xAtB, yAtB, xAtC, yAtC); |
| 2145 | 0 | return Math.tan(angle); |
| 2146 | |
} |
| 2147 | |
|
| 2148 | |
|
| 2149 | |
public static double tan(double sideAC, double sideBC, double sideAB){ |
| 2150 | 0 | double angle = Fmath.angle(sideAC, sideBC, sideAB); |
| 2151 | 0 | return Math.tan(angle); |
| 2152 | |
} |
| 2153 | |
|
| 2154 | |
|
| 2155 | |
|
| 2156 | |
public static double tan(double arg){ |
| 2157 | 0 | return Math.tan(arg); |
| 2158 | |
} |
| 2159 | |
|
| 2160 | |
|
| 2161 | |
|
| 2162 | |
public static double atan(double a){ |
| 2163 | 0 | return Math.atan(a); |
| 2164 | |
} |
| 2165 | |
|
| 2166 | |
|
| 2167 | |
|
| 2168 | |
public static double atan2(double a, double b){ |
| 2169 | 0 | return Math.atan2(a, b); |
| 2170 | |
} |
| 2171 | |
|
| 2172 | |
|
| 2173 | |
public static double cot(double a){ |
| 2174 | 0 | return 1.0D/Math.tan(a); |
| 2175 | |
} |
| 2176 | |
|
| 2177 | |
|
| 2178 | |
public static double acot(double a){ |
| 2179 | 0 | return Math.atan(1.0D/a); |
| 2180 | |
} |
| 2181 | |
|
| 2182 | |
|
| 2183 | |
public static double acot2(double a, double b){ |
| 2184 | 0 | return Math.atan2(b, a); |
| 2185 | |
} |
| 2186 | |
|
| 2187 | |
|
| 2188 | |
public static double sec(double a){ |
| 2189 | 0 | return 1.0/Math.cos(a); |
| 2190 | |
} |
| 2191 | |
|
| 2192 | |
|
| 2193 | |
public static double asec(double a){ |
| 2194 | 0 | if(a<1.0D && a>-1.0D) throw new IllegalArgumentException("asec argument (" + a + ") must be >= 1 or <= -1"); |
| 2195 | 0 | return Math.acos(1.0/a); |
| 2196 | |
} |
| 2197 | |
|
| 2198 | |
|
| 2199 | |
public static double csc(double a){ |
| 2200 | 0 | return 1.0D/Math.sin(a); |
| 2201 | |
} |
| 2202 | |
|
| 2203 | |
|
| 2204 | |
public static double acsc(double a){ |
| 2205 | 0 | if(a<1.0D && a>-1.0D) throw new IllegalArgumentException("acsc argument (" + a + ") must be >= 1 or <= -1"); |
| 2206 | 0 | return Math.asin(1.0/a); |
| 2207 | |
} |
| 2208 | |
|
| 2209 | |
|
| 2210 | |
public static double exsec(double a){ |
| 2211 | 0 | return (1.0/Math.cos(a)-1.0D); |
| 2212 | |
} |
| 2213 | |
|
| 2214 | |
|
| 2215 | |
public static double aexsec(double a){ |
| 2216 | 0 | if(a<0.0D && a>-2.0D) throw new IllegalArgumentException("aexsec argument (" + a + ") must be >= 0.0 and <= -2"); |
| 2217 | 0 | return Math.asin(1.0D/(1.0D + a)); |
| 2218 | |
} |
| 2219 | |
|
| 2220 | |
|
| 2221 | |
public static double vers(double a){ |
| 2222 | 0 | return (1.0D - Math.cos(a)); |
| 2223 | |
} |
| 2224 | |
|
| 2225 | |
|
| 2226 | |
public static double avers(double a){ |
| 2227 | 0 | if(a<0.0D && a>2.0D) throw new IllegalArgumentException("avers argument (" + a + ") must be <= 2 and >= 0"); |
| 2228 | 0 | return Math.acos(1.0D - a); |
| 2229 | |
} |
| 2230 | |
|
| 2231 | |
|
| 2232 | |
public static double covers(double a){ |
| 2233 | 0 | return (1.0D - Math.sin(a)); |
| 2234 | |
} |
| 2235 | |
|
| 2236 | |
|
| 2237 | |
public static double acovers(double a){ |
| 2238 | 0 | if(a<0.0D && a>2.0D) throw new IllegalArgumentException("acovers argument (" + a + ") must be <= 2 and >= 0"); |
| 2239 | 0 | return Math.asin(1.0D - a); |
| 2240 | |
} |
| 2241 | |
|
| 2242 | |
|
| 2243 | |
public static double hav(double a){ |
| 2244 | 0 | return 0.5D*Fmath.vers(a); |
| 2245 | |
} |
| 2246 | |
|
| 2247 | |
|
| 2248 | |
public static double ahav(double a){ |
| 2249 | 0 | if(a<0.0D && a>1.0D) throw new IllegalArgumentException("ahav argument (" + a + ") must be >= 0 and <= 1"); |
| 2250 | 0 | return 0.5D*Fmath.vers(a); |
| 2251 | |
} |
| 2252 | |
|
| 2253 | |
|
| 2254 | |
public static double sinc(double a){ |
| 2255 | 0 | if(Math.abs(a)<1e-40){ |
| 2256 | 0 | return 1.0D; |
| 2257 | |
} |
| 2258 | |
else{ |
| 2259 | 0 | return Math.sin(a)/a; |
| 2260 | |
} |
| 2261 | |
} |
| 2262 | |
|
| 2263 | |
|
| 2264 | |
public static double sinh(double a){ |
| 2265 | 0 | return 0.5D*(Math.exp(a)-Math.exp(-a)); |
| 2266 | |
} |
| 2267 | |
|
| 2268 | |
|
| 2269 | |
public static double asinh(double a){ |
| 2270 | 0 | double sgn = 1.0D; |
| 2271 | 0 | if(a<0.0D){ |
| 2272 | 0 | sgn = -1.0D; |
| 2273 | 0 | a = -a; |
| 2274 | |
} |
| 2275 | 0 | return sgn*Math.log(a+Math.sqrt(a*a+1.0D)); |
| 2276 | |
} |
| 2277 | |
|
| 2278 | |
|
| 2279 | |
public static double cosh(double a){ |
| 2280 | 0 | return 0.5D*(Math.exp(a)+Math.exp(-a)); |
| 2281 | |
} |
| 2282 | |
|
| 2283 | |
|
| 2284 | |
public static double acosh(double a){ |
| 2285 | 0 | if(a<1.0D) throw new IllegalArgumentException("acosh real number argument (" + a + ") must be >= 1"); |
| 2286 | 0 | return Math.log(a+Math.sqrt(a*a-1.0D)); |
| 2287 | |
} |
| 2288 | |
|
| 2289 | |
|
| 2290 | |
public static double tanh(double a){ |
| 2291 | 0 | return sinh(a)/cosh(a); |
| 2292 | |
} |
| 2293 | |
|
| 2294 | |
|
| 2295 | |
public static double atanh(double a){ |
| 2296 | 0 | double sgn = 1.0D; |
| 2297 | 0 | if(a<0.0D){ |
| 2298 | 0 | sgn = -1.0D; |
| 2299 | 0 | a = -a; |
| 2300 | |
} |
| 2301 | 0 | if(a>1.0D) throw new IllegalArgumentException("atanh real number argument (" + sgn*a + ") must be >= -1 and <= 1"); |
| 2302 | 0 | return 0.5D*sgn*(Math.log(1.0D + a)-Math.log(1.0D - a)); |
| 2303 | |
} |
| 2304 | |
|
| 2305 | |
|
| 2306 | |
public static double coth(double a){ |
| 2307 | 0 | return 1.0D/tanh(a); |
| 2308 | |
} |
| 2309 | |
|
| 2310 | |
|
| 2311 | |
public static double acoth(double a){ |
| 2312 | 0 | double sgn = 1.0D; |
| 2313 | 0 | if(a<0.0D){ |
| 2314 | 0 | sgn = -1.0D; |
| 2315 | 0 | a = -a; |
| 2316 | |
} |
| 2317 | 0 | if(a<1.0D) throw new IllegalArgumentException("acoth real number argument (" + sgn*a + ") must be <= -1 or >= 1"); |
| 2318 | 0 | return 0.5D*sgn*(Math.log(1.0D + a)-Math.log(a - 1.0D)); |
| 2319 | |
} |
| 2320 | |
|
| 2321 | |
|
| 2322 | |
public static double sech(double a){ |
| 2323 | 0 | return 1.0D/cosh(a); |
| 2324 | |
} |
| 2325 | |
|
| 2326 | |
|
| 2327 | |
public static double asech(double a){ |
| 2328 | 0 | if(a>1.0D || a<0.0D) throw new IllegalArgumentException("asech real number argument (" + a + ") must be >= 0 and <= 1"); |
| 2329 | 0 | return 0.5D*(Math.log(1.0D/a + Math.sqrt(1.0D/(a*a) - 1.0D))); |
| 2330 | |
} |
| 2331 | |
|
| 2332 | |
|
| 2333 | |
public static double csch(double a){ |
| 2334 | 0 | return 1.0D/sinh(a); |
| 2335 | |
} |
| 2336 | |
|
| 2337 | |
|
| 2338 | |
public static double acsch(double a){ |
| 2339 | 0 | double sgn = 1.0D; |
| 2340 | 0 | if(a<0.0D){ |
| 2341 | 0 | sgn = -1.0D; |
| 2342 | 0 | a = -a; |
| 2343 | |
} |
| 2344 | 0 | return 0.5D*sgn*(Math.log(1.0/a + Math.sqrt(1.0D/(a*a) + 1.0D))); |
| 2345 | |
} |
| 2346 | |
|
| 2347 | |
|
| 2348 | |
|
| 2349 | |
public static double truncate(double x, int prec){ |
| 2350 | |
|
| 2351 | 0 | if(prec<0)throw new IllegalArgumentException("precision less than zero places"); |
| 2352 | |
|
| 2353 | 0 | if(x==0.0D)return x; |
| 2354 | 0 | if(Fmath.isNaN(x))return x; |
| 2355 | 0 | if(Fmath.isPlusInfinity(x))return x; |
| 2356 | 0 | if(Fmath.isMinusInfinity(x))return x; |
| 2357 | |
|
| 2358 | 0 | char sign = ' '; |
| 2359 | 0 | if(x<0.0D){ |
| 2360 | 0 | sign = '-'; |
| 2361 | 0 | x = -x; |
| 2362 | |
} |
| 2363 | |
|
| 2364 | 0 | Double xx = new Double(x); |
| 2365 | 0 | String xString = xx.toString(); |
| 2366 | 0 | String newXstring = stringRound(xString.trim(), prec, sign); |
| 2367 | |
|
| 2368 | 0 | return Double.parseDouble(newXstring); |
| 2369 | |
} |
| 2370 | |
|
| 2371 | |
|
| 2372 | |
public static float truncate(float x, int prec){ |
| 2373 | |
|
| 2374 | 0 | if(prec<0)throw new IllegalArgumentException("precision less than zero places"); |
| 2375 | |
|
| 2376 | 0 | if(x==0.0D)return x; |
| 2377 | 0 | if(Fmath.isNaN(x))return x; |
| 2378 | 0 | if(Fmath.isPlusInfinity(x))return x; |
| 2379 | 0 | if(Fmath.isMinusInfinity(x))return x; |
| 2380 | |
|
| 2381 | 0 | char sign = ' '; |
| 2382 | 0 | if(x<0.0D){ |
| 2383 | 0 | sign = '-'; |
| 2384 | 0 | x = -x; |
| 2385 | |
} |
| 2386 | |
|
| 2387 | 0 | Float xx = new Float(x); |
| 2388 | 0 | String xString = xx.toString(); |
| 2389 | 0 | String newXstring = stringRound(xString.trim(), prec, sign); |
| 2390 | 0 | return Float.parseFloat(newXstring); |
| 2391 | |
} |
| 2392 | |
|
| 2393 | |
|
| 2394 | |
private static String stringRound(String ss, int prec, char sign){ |
| 2395 | |
|
| 2396 | 0 | String returnString = null; |
| 2397 | 0 | int posEnd = ss.length()-1; |
| 2398 | 0 | int posE = ss.indexOf('E'); |
| 2399 | 0 | int posDot = ss.indexOf('.'); |
| 2400 | |
|
| 2401 | 0 | String decPlaces = null; |
| 2402 | 0 | String exponent = null; |
| 2403 | 0 | String prePoint = ss.substring(0, posDot); |
| 2404 | 0 | int ppLen = prePoint.length(); |
| 2405 | |
|
| 2406 | 0 | if(posE==-1){ |
| 2407 | 0 | decPlaces = ss.substring(posDot+1); |
| 2408 | |
} |
| 2409 | |
else{ |
| 2410 | 0 | decPlaces = ss.substring(posDot+1, posE); |
| 2411 | 0 | exponent = ss.substring(posE+1); |
| 2412 | |
} |
| 2413 | 0 | int dpLen = decPlaces.length(); |
| 2414 | |
|
| 2415 | |
|
| 2416 | 0 | if(prec==0){ |
| 2417 | 0 | returnString = prePoint + ".0"; |
| 2418 | 0 | if(exponent!=null)returnString = returnString + "E" + exponent; |
| 2419 | 0 | if(sign=='-')returnString = "-" + returnString; |
| 2420 | 0 | return returnString; |
| 2421 | |
} |
| 2422 | |
|
| 2423 | |
|
| 2424 | 0 | if(dpLen<=prec){ |
| 2425 | 0 | returnString = ss; |
| 2426 | 0 | if(sign=='-')returnString = "-" + ss; |
| 2427 | 0 | return returnString; |
| 2428 | |
} |
| 2429 | |
|
| 2430 | |
|
| 2431 | 0 | boolean test9 = true; |
| 2432 | 0 | boolean test9end=false; |
| 2433 | 0 | if(posE==-1){ |
| 2434 | 0 | if(ss.charAt(0)!='0'){ |
| 2435 | 0 | test9=false; |
| 2436 | |
} |
| 2437 | |
else{ |
| 2438 | 0 | if(ss.charAt(1)!='.'){ |
| 2439 | 0 | test9=false; |
| 2440 | |
} |
| 2441 | |
else{ |
| 2442 | 0 | for(int i=2; i<2+prec; i++){ |
| 2443 | 0 | if(ss.charAt(i)!='9'){ |
| 2444 | 0 | test9 = false; |
| 2445 | |
} |
| 2446 | 0 | if(!test9)break; |
| 2447 | |
} |
| 2448 | 0 | if(test9 && ss.charAt(prec+2)>'4')test9end=true; |
| 2449 | |
} |
| 2450 | |
} |
| 2451 | 0 | if(test9){ |
| 2452 | 0 | if(test9end){ |
| 2453 | 0 | returnString = "1."; |
| 2454 | 0 | for(int i = 1; i<=prec; i++)returnString += '0'; |
| 2455 | 0 | if(sign=='-')returnString = "-" + returnString; |
| 2456 | 0 | return returnString; |
| 2457 | |
} |
| 2458 | |
else{ |
| 2459 | 0 | returnString = "0."; |
| 2460 | 0 | for(int i = 1; i<=prec; i++)returnString += '9'; |
| 2461 | 0 | if(sign=='-')returnString = "-" + returnString; |
| 2462 | 0 | return returnString; |
| 2463 | |
} |
| 2464 | |
} |
| 2465 | |
} |
| 2466 | |
|
| 2467 | |
|
| 2468 | 0 | int[] iss = new int[dpLen]; |
| 2469 | 0 | int carry = 0; |
| 2470 | 0 | for(int i=dpLen-1; i>=prec; i--){ |
| 2471 | 0 | iss[i] = (int)decPlaces.charAt(i) + carry; |
| 2472 | 0 | if(iss[i]<53){ |
| 2473 | 0 | carry = 0; |
| 2474 | |
} |
| 2475 | |
else{ |
| 2476 | 0 | carry = 1; |
| 2477 | |
} |
| 2478 | 0 | iss[i] = 48; |
| 2479 | |
} |
| 2480 | 0 | boolean test = true; |
| 2481 | 0 | int ii = prec - 1; |
| 2482 | 0 | while(test){ |
| 2483 | 0 | iss[ii] = (int)decPlaces.charAt(ii) + carry; |
| 2484 | 0 | if(iss[ii]<58){ |
| 2485 | 0 | test=false; |
| 2486 | 0 | for(int i = 0; i<ii; i++){ |
| 2487 | 0 | iss[i] = (int)decPlaces.charAt(i); |
| 2488 | |
} |
| 2489 | 0 | carry = 0; |
| 2490 | |
} |
| 2491 | |
else{ |
| 2492 | 0 | iss[ii] = 48; |
| 2493 | 0 | carry = 1; |
| 2494 | 0 | ii--; |
| 2495 | 0 | if(ii<0)test=false; |
| 2496 | |
} |
| 2497 | |
} |
| 2498 | |
|
| 2499 | 0 | test = true; |
| 2500 | 0 | if(carry==0)test = false; |
| 2501 | 0 | ii = posDot - 1; |
| 2502 | 0 | while(test){ |
| 2503 | 0 | iss[ii] = (int)prePoint.charAt(ii) + carry; |
| 2504 | 0 | if(iss[ii]<58){ |
| 2505 | 0 | test=false; |
| 2506 | 0 | for(int i = 0; i<ii; i++){ |
| 2507 | 0 | iss[i] = (int)prePoint.charAt(i); |
| 2508 | |
} |
| 2509 | 0 | carry = 0; |
| 2510 | |
} |
| 2511 | |
else{ |
| 2512 | 0 | iss[ii] = 48; |
| 2513 | 0 | carry = 1; |
| 2514 | 0 | ii--; |
| 2515 | 0 | if(ii<0)test=false; |
| 2516 | |
} |
| 2517 | |
} |
| 2518 | |
|
| 2519 | 0 | if(carry==1){ |
| 2520 | 0 | prePoint = "1"; |
| 2521 | 0 | for(int i=0; i<ppLen; i++)prePoint = prePoint + "0"; |
| 2522 | 0 | returnString = prePoint + ".0"; |
| 2523 | |
|
| 2524 | |
} |
| 2525 | |
else{ |
| 2526 | 0 | returnString = prePoint + "."; |
| 2527 | 0 | StringBuffer strbuff = new StringBuffer(); |
| 2528 | 0 | for(int k=0; k<prec; k++){ |
| 2529 | 0 | strbuff.append((char)iss[k]); |
| 2530 | |
} |
| 2531 | 0 | returnString = returnString + strbuff.toString(); |
| 2532 | |
} |
| 2533 | |
|
| 2534 | 0 | if(exponent!=null)returnString = returnString + "E" + exponent; |
| 2535 | 0 | if(sign=='-')returnString = "-" + returnString; |
| 2536 | |
|
| 2537 | 0 | return returnString; |
| 2538 | |
} |
| 2539 | |
|
| 2540 | |
|
| 2541 | |
|
| 2542 | |
|
| 2543 | |
|
| 2544 | |
public static boolean isInfinity(double x){ |
| 2545 | 0 | boolean test=false; |
| 2546 | 0 | if(x==Double.POSITIVE_INFINITY || x==Double.NEGATIVE_INFINITY)test=true; |
| 2547 | 0 | return test; |
| 2548 | |
} |
| 2549 | |
|
| 2550 | |
|
| 2551 | |
|
| 2552 | |
public static boolean isInfinity(float x){ |
| 2553 | 0 | boolean test=false; |
| 2554 | 0 | if(x==Float.POSITIVE_INFINITY || x==Float.NEGATIVE_INFINITY)test=true; |
| 2555 | 0 | return test; |
| 2556 | |
} |
| 2557 | |
|
| 2558 | |
|
| 2559 | |
|
| 2560 | |
public static boolean isPlusInfinity(double x){ |
| 2561 | 0 | boolean test=false; |
| 2562 | 0 | if(x==Double.POSITIVE_INFINITY)test=true; |
| 2563 | 0 | return test; |
| 2564 | |
} |
| 2565 | |
|
| 2566 | |
|
| 2567 | |
|
| 2568 | |
public static boolean isPlusInfinity(float x){ |
| 2569 | 0 | boolean test=false; |
| 2570 | 0 | if(x==Float.POSITIVE_INFINITY)test=true; |
| 2571 | 0 | return test; |
| 2572 | |
} |
| 2573 | |
|
| 2574 | |
|
| 2575 | |
|
| 2576 | |
public static boolean isMinusInfinity(double x){ |
| 2577 | 0 | boolean test=false; |
| 2578 | 0 | if(x==Double.NEGATIVE_INFINITY)test=true; |
| 2579 | 0 | return test; |
| 2580 | |
} |
| 2581 | |
|
| 2582 | |
|
| 2583 | |
|
| 2584 | |
public static boolean isMinusInfinity(float x){ |
| 2585 | 0 | boolean test=false; |
| 2586 | 0 | if(x==Float.NEGATIVE_INFINITY)test=true; |
| 2587 | 0 | return test; |
| 2588 | |
} |
| 2589 | |
|
| 2590 | |
|
| 2591 | |
|
| 2592 | |
|
| 2593 | |
public static boolean isNaN(double x){ |
| 2594 | 0 | boolean test=false; |
| 2595 | 0 | if(x!=x)test=true; |
| 2596 | 0 | return test; |
| 2597 | |
} |
| 2598 | |
|
| 2599 | |
|
| 2600 | |
|
| 2601 | |
public static boolean isNaN(float x){ |
| 2602 | 0 | boolean test=false; |
| 2603 | 0 | if(x!=x)test=true; |
| 2604 | 0 | return test; |
| 2605 | |
} |
| 2606 | |
|
| 2607 | |
|
| 2608 | |
|
| 2609 | |
|
| 2610 | |
|
| 2611 | |
public static boolean isEqual(double x, double y){ |
| 2612 | 0 | boolean test=false; |
| 2613 | 0 | if(Fmath.isNaN(x)){ |
| 2614 | 0 | if(Fmath.isNaN(y))test=true; |
| 2615 | |
} |
| 2616 | |
else{ |
| 2617 | 0 | if(Fmath.isPlusInfinity(x)){ |
| 2618 | 0 | if(Fmath.isPlusInfinity(y))test=true; |
| 2619 | |
} |
| 2620 | |
else{ |
| 2621 | 0 | if(Fmath.isMinusInfinity(x)){ |
| 2622 | 0 | if(Fmath.isMinusInfinity(y))test=true; |
| 2623 | |
} |
| 2624 | |
else{ |
| 2625 | 0 | if(x==y)test=true; |
| 2626 | |
} |
| 2627 | |
} |
| 2628 | |
} |
| 2629 | 0 | return test; |
| 2630 | |
} |
| 2631 | |
|
| 2632 | |
|
| 2633 | |
|
| 2634 | |
|
| 2635 | |
|
| 2636 | |
public static boolean isEqual(float x, float y){ |
| 2637 | 0 | boolean test=false; |
| 2638 | 0 | if(Fmath.isNaN(x)){ |
| 2639 | 0 | if(Fmath.isNaN(y))test=true; |
| 2640 | |
} |
| 2641 | |
else{ |
| 2642 | 0 | if(Fmath.isPlusInfinity(x)){ |
| 2643 | 0 | if(Fmath.isPlusInfinity(y))test=true; |
| 2644 | |
} |
| 2645 | |
else{ |
| 2646 | 0 | if(Fmath.isMinusInfinity(x)){ |
| 2647 | 0 | if(Fmath.isMinusInfinity(y))test=true; |
| 2648 | |
} |
| 2649 | |
else{ |
| 2650 | 0 | if(x==y)test=true; |
| 2651 | |
} |
| 2652 | |
} |
| 2653 | |
} |
| 2654 | 0 | return test; |
| 2655 | |
} |
| 2656 | |
|
| 2657 | |
|
| 2658 | |
|
| 2659 | |
public static boolean isEqual(int x, int y){ |
| 2660 | 0 | boolean test=false; |
| 2661 | 0 | if(x==y)test=true; |
| 2662 | 0 | return test; |
| 2663 | |
} |
| 2664 | |
|
| 2665 | |
|
| 2666 | |
|
| 2667 | |
public static boolean isEqual(char x, char y){ |
| 2668 | 0 | boolean test=false; |
| 2669 | 0 | if(x==y)test=true; |
| 2670 | 0 | return test; |
| 2671 | |
} |
| 2672 | |
|
| 2673 | |
|
| 2674 | |
|
| 2675 | |
public static boolean isEqual(String x, String y){ |
| 2676 | 0 | boolean test=false; |
| 2677 | 0 | if(x.equals(y))test=true; |
| 2678 | 0 | return test; |
| 2679 | |
} |
| 2680 | |
|
| 2681 | |
|
| 2682 | |
|
| 2683 | |
public static boolean isEven(int x){ |
| 2684 | 0 | boolean test=false; |
| 2685 | 0 | if(x%2 == 0.0D)test=true; |
| 2686 | 0 | return test; |
| 2687 | |
} |
| 2688 | |
|
| 2689 | |
|
| 2690 | |
|
| 2691 | |
|
| 2692 | |
|
| 2693 | |
public static int compare(double x, double y){ |
| 2694 | 0 | Double X = new Double(x); |
| 2695 | 0 | Double Y = new Double(y); |
| 2696 | 0 | return X.compareTo(Y); |
| 2697 | |
} |
| 2698 | |
|
| 2699 | |
|
| 2700 | |
|
| 2701 | |
|
| 2702 | |
|
| 2703 | |
public static int compare(int x, int y){ |
| 2704 | 0 | Integer X = new Integer(x); |
| 2705 | 0 | Integer Y = new Integer(y); |
| 2706 | 0 | return X.compareTo(Y); |
| 2707 | |
} |
| 2708 | |
|
| 2709 | |
|
| 2710 | |
|
| 2711 | |
|
| 2712 | |
|
| 2713 | |
public static int compare(long x, long y){ |
| 2714 | 0 | Long X = new Long(x); |
| 2715 | 0 | Long Y = new Long(y); |
| 2716 | 0 | return X.compareTo(Y); |
| 2717 | |
} |
| 2718 | |
|
| 2719 | |
|
| 2720 | |
|
| 2721 | |
|
| 2722 | |
|
| 2723 | |
public static int compare(float x, float y){ |
| 2724 | 0 | Float X = new Float(x); |
| 2725 | 0 | Float Y = new Float(y); |
| 2726 | 0 | return X.compareTo(Y); |
| 2727 | |
} |
| 2728 | |
|
| 2729 | |
|
| 2730 | |
|
| 2731 | |
|
| 2732 | |
|
| 2733 | |
public static int compare(byte x, byte y){ |
| 2734 | 0 | Byte X = new Byte(x); |
| 2735 | 0 | Byte Y = new Byte(y); |
| 2736 | 0 | return X.compareTo(Y); |
| 2737 | |
} |
| 2738 | |
|
| 2739 | |
|
| 2740 | |
|
| 2741 | |
|
| 2742 | |
|
| 2743 | |
public static int compare(short x, short y){ |
| 2744 | 0 | Short X = new Short(x); |
| 2745 | 0 | Short Y = new Short(y); |
| 2746 | 0 | return X.compareTo(Y); |
| 2747 | |
} |
| 2748 | |
|
| 2749 | |
|
| 2750 | |
|
| 2751 | |
public static boolean isEven(float x){ |
| 2752 | 0 | double y=Math.floor(x); |
| 2753 | 0 | if(((double)x - y)!= 0.0D)throw new IllegalArgumentException("the argument is not an integer"); |
| 2754 | 0 | boolean test=false; |
| 2755 | 0 | y=Math.floor(x/2.0F); |
| 2756 | 0 | if(((double)(x/2.0F)-y) == 0.0D)test=true; |
| 2757 | 0 | return test; |
| 2758 | |
} |
| 2759 | |
|
| 2760 | |
|
| 2761 | |
|
| 2762 | |
public static boolean isEven(double x){ |
| 2763 | 0 | double y=Math.floor(x); |
| 2764 | 0 | if((x - y)!= 0.0D)throw new IllegalArgumentException("the argument is not an integer"); |
| 2765 | 0 | boolean test=false; |
| 2766 | 0 | y=Math.floor(x/2.0F); |
| 2767 | 0 | if((x/2.0D-y) == 0.0D)test=true; |
| 2768 | 0 | return test; |
| 2769 | |
} |
| 2770 | |
|
| 2771 | |
|
| 2772 | |
|
| 2773 | |
public static boolean isOdd(int x){ |
| 2774 | 0 | boolean test=true; |
| 2775 | 0 | if(x%2 == 0.0D)test=false; |
| 2776 | 0 | return test; |
| 2777 | |
} |
| 2778 | |
|
| 2779 | |
|
| 2780 | |
|
| 2781 | |
public static boolean isOdd(float x){ |
| 2782 | 0 | double y=Math.floor(x); |
| 2783 | 0 | if(((double)x - y)!= 0.0D)throw new IllegalArgumentException("the argument is not an integer"); |
| 2784 | 0 | boolean test=true; |
| 2785 | 0 | y=Math.floor(x/2.0F); |
| 2786 | 0 | if(((double)(x/2.0F)-y) == 0.0D)test=false; |
| 2787 | 0 | return test; |
| 2788 | |
} |
| 2789 | |
|
| 2790 | |
|
| 2791 | |
|
| 2792 | |
public static boolean isOdd(double x){ |
| 2793 | 0 | double y=Math.floor(x); |
| 2794 | 0 | if((x - y)!= 0.0D)throw new IllegalArgumentException("the argument is not an integer"); |
| 2795 | 0 | boolean test=true; |
| 2796 | 0 | y=Math.floor(x/2.0F); |
| 2797 | 0 | if((x/2.0D-y) == 0.0D)test=false; |
| 2798 | 0 | return test; |
| 2799 | |
} |
| 2800 | |
|
| 2801 | |
|
| 2802 | |
public static boolean leapYear(int year){ |
| 2803 | 0 | boolean test = false; |
| 2804 | |
|
| 2805 | 0 | if(year%4 != 0){ |
| 2806 | 0 | test = false; |
| 2807 | |
} |
| 2808 | |
else{ |
| 2809 | 0 | if(year%400 == 0){ |
| 2810 | 0 | test=true; |
| 2811 | |
} |
| 2812 | |
else{ |
| 2813 | 0 | if(year%100 == 0){ |
| 2814 | 0 | test=false; |
| 2815 | |
} |
| 2816 | |
else{ |
| 2817 | 0 | test=true; |
| 2818 | |
} |
| 2819 | |
} |
| 2820 | |
} |
| 2821 | 0 | return test; |
| 2822 | |
} |
| 2823 | |
|
| 2824 | |
|
| 2825 | |
public static long dateToJavaMilliS(int year, int month, int day, int hour, int min, int sec){ |
| 2826 | |
|
| 2827 | 0 | long[] monthDays = {0L, 31L, 28L, 31L, 30L, 31L, 30L, 31L, 31L, 30L, 31L, 30L, 31L}; |
| 2828 | 0 | long ms = 0L; |
| 2829 | |
|
| 2830 | 0 | long yearDiff = 0L; |
| 2831 | 0 | int yearTest = year-1; |
| 2832 | 0 | while(yearTest>=1970){ |
| 2833 | 0 | yearDiff += 365; |
| 2834 | 0 | if(Fmath.leapYear(yearTest))yearDiff++; |
| 2835 | 0 | yearTest--; |
| 2836 | |
} |
| 2837 | 0 | yearDiff *= 24L*60L*60L*1000L; |
| 2838 | |
|
| 2839 | 0 | long monthDiff = 0L; |
| 2840 | 0 | int monthTest = month -1; |
| 2841 | 0 | while(monthTest>0){ |
| 2842 | 0 | monthDiff += monthDays[monthTest]; |
| 2843 | 0 | if(Fmath.leapYear(year))monthDiff++; |
| 2844 | 0 | monthTest--; |
| 2845 | |
} |
| 2846 | |
|
| 2847 | 0 | monthDiff *= 24L*60L*60L*1000L; |
| 2848 | |
|
| 2849 | 0 | ms = yearDiff + monthDiff + day*24L*60L*60L*1000L + hour*60L*60L*1000L + min*60L*1000L + sec*1000L; |
| 2850 | |
|
| 2851 | 0 | return ms; |
| 2852 | |
} |
| 2853 | |
|
| 2854 | |
} |