Mercurial > lasercutter
comparison src/clojure/lang/Numbers.java @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:35cf337adfcf | 10:ef7dbbd6452c |
---|---|
1 /** | |
2 * Copyright (c) Rich Hickey. All rights reserved. | |
3 * The use and distribution terms for this software are covered by the | |
4 * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
5 * which can be found in the file epl-v10.html at the root of this distribution. | |
6 * By using this software in any fashion, you are agreeing to be bound by | |
7 * the terms of this license. | |
8 * You must not remove this notice, or any other, from this software. | |
9 **/ | |
10 | |
11 /* rich Mar 31, 2008 */ | |
12 | |
13 package clojure.lang; | |
14 | |
15 import java.math.BigInteger; | |
16 import java.math.BigDecimal; | |
17 import java.math.MathContext; | |
18 | |
19 public class Numbers{ | |
20 | |
21 static interface Ops{ | |
22 Ops combine(Ops y); | |
23 | |
24 Ops opsWith(IntegerOps x); | |
25 | |
26 Ops opsWith(LongOps x); | |
27 | |
28 Ops opsWith(FloatOps x); | |
29 | |
30 Ops opsWith(DoubleOps x); | |
31 | |
32 Ops opsWith(RatioOps x); | |
33 | |
34 Ops opsWith(BigIntegerOps x); | |
35 | |
36 Ops opsWith(BigDecimalOps x); | |
37 | |
38 public boolean isZero(Number x); | |
39 | |
40 public boolean isPos(Number x); | |
41 | |
42 public boolean isNeg(Number x); | |
43 | |
44 public Number add(Number x, Number y); | |
45 | |
46 public Number multiply(Number x, Number y); | |
47 | |
48 public Number divide(Number x, Number y); | |
49 | |
50 public Number quotient(Number x, Number y); | |
51 | |
52 public Number remainder(Number x, Number y); | |
53 | |
54 public boolean equiv(Number x, Number y); | |
55 | |
56 public boolean lt(Number x, Number y); | |
57 | |
58 public Number negate(Number x); | |
59 | |
60 public Number inc(Number x); | |
61 | |
62 public Number dec(Number x); | |
63 } | |
64 | |
65 static interface BitOps{ | |
66 BitOps combine(BitOps y); | |
67 | |
68 BitOps bitOpsWith(IntegerBitOps x); | |
69 | |
70 BitOps bitOpsWith(LongBitOps x); | |
71 | |
72 BitOps bitOpsWith(BigIntegerBitOps x); | |
73 | |
74 public Number not(Number x); | |
75 | |
76 public Number and(Number x, Number y); | |
77 | |
78 public Number or(Number x, Number y); | |
79 | |
80 public Number xor(Number x, Number y); | |
81 | |
82 public Number andNot(Number x, Number y); | |
83 | |
84 public Number clearBit(Number x, int n); | |
85 | |
86 public Number setBit(Number x, int n); | |
87 | |
88 public Number flipBit(Number x, int n); | |
89 | |
90 public boolean testBit(Number x, int n); | |
91 | |
92 public Number shiftLeft(Number x, int n); | |
93 | |
94 public Number shiftRight(Number x, int n); | |
95 } | |
96 | |
97 | |
98 static public boolean isZero(Object x){ | |
99 return ops(x).isZero((Number)x); | |
100 } | |
101 | |
102 static public boolean isPos(Object x){ | |
103 return ops(x).isPos((Number)x); | |
104 } | |
105 | |
106 static public boolean isNeg(Object x){ | |
107 return ops(x).isNeg((Number)x); | |
108 } | |
109 | |
110 static public Number minus(Object x){ | |
111 return ops(x).negate((Number)x); | |
112 } | |
113 | |
114 static public Number inc(Object x){ | |
115 return ops(x).inc((Number)x); | |
116 } | |
117 | |
118 static public Number dec(Object x){ | |
119 return ops(x).dec((Number)x); | |
120 } | |
121 | |
122 static public Number add(Object x, Object y){ | |
123 return ops(x).combine(ops(y)).add((Number)x, (Number)y); | |
124 } | |
125 | |
126 static public Number minus(Object x, Object y){ | |
127 Ops yops = ops(y); | |
128 return ops(x).combine(yops).add((Number)x, yops.negate((Number)y)); | |
129 } | |
130 | |
131 static public Number multiply(Object x, Object y){ | |
132 return ops(x).combine(ops(y)).multiply((Number)x, (Number)y); | |
133 } | |
134 | |
135 static public Number divide(Object x, Object y){ | |
136 Ops yops = ops(y); | |
137 if(yops.isZero((Number)y)) | |
138 throw new ArithmeticException("Divide by zero"); | |
139 return ops(x).combine(yops).divide((Number)x, (Number)y); | |
140 } | |
141 | |
142 static public Number quotient(Number x, Number y){ | |
143 Ops yops = ops(y); | |
144 if(yops.isZero(y)) | |
145 throw new ArithmeticException("Divide by zero"); | |
146 return reduce(ops(x).combine(yops).quotient(x, y)); | |
147 } | |
148 | |
149 static public Number remainder(Number x, Number y){ | |
150 Ops yops = ops(y); | |
151 if(yops.isZero(y)) | |
152 throw new ArithmeticException("Divide by zero"); | |
153 return reduce(ops(x).combine(yops).remainder(x, y)); | |
154 } | |
155 | |
156 static Number quotient(double n, double d){ | |
157 double q = n / d; | |
158 if(q <= Integer.MAX_VALUE && q >= Integer.MIN_VALUE) | |
159 { | |
160 return (int) q; | |
161 } | |
162 else | |
163 { //bigint quotient | |
164 return reduce(new BigDecimal(q).toBigInteger()); | |
165 } | |
166 } | |
167 | |
168 static Number remainder(double n, double d){ | |
169 double q = n / d; | |
170 if(q <= Integer.MAX_VALUE && q >= Integer.MIN_VALUE) | |
171 { | |
172 return (n - ((int) q) * d); | |
173 } | |
174 else | |
175 { //bigint quotient | |
176 Number bq = reduce(new BigDecimal(q).toBigInteger()); | |
177 return (n - bq.doubleValue() * d); | |
178 } | |
179 } | |
180 | |
181 static public boolean equiv(Object x, Object y){ | |
182 return equiv((Number) x, (Number) y); | |
183 } | |
184 | |
185 static public boolean equiv(Number x, Number y){ | |
186 return ops(x).combine(ops(y)).equiv(x, y); | |
187 } | |
188 | |
189 static public boolean lt(Object x, Object y){ | |
190 return ops(x).combine(ops(y)).lt((Number)x, (Number)y); | |
191 } | |
192 | |
193 static public boolean lte(Object x, Object y){ | |
194 return !ops(x).combine(ops(y)).lt((Number)y, (Number)x); | |
195 } | |
196 | |
197 static public boolean gt(Object x, Object y){ | |
198 return ops(x).combine(ops(y)).lt((Number)y, (Number)x); | |
199 } | |
200 | |
201 static public boolean gte(Object x, Object y){ | |
202 return !ops(x).combine(ops(y)).lt((Number)x, (Number)y); | |
203 } | |
204 | |
205 static public int compare(Number x, Number y){ | |
206 Ops ops = ops(x).combine(ops(y)); | |
207 if(ops.lt(x, y)) | |
208 return -1; | |
209 else if(ops.lt(y, x)) | |
210 return 1; | |
211 return 0; | |
212 } | |
213 | |
214 static BigInteger toBigInteger(Object x){ | |
215 if(x instanceof BigInteger) | |
216 return (BigInteger) x; | |
217 else | |
218 return BigInteger.valueOf(((Number) x).longValue()); | |
219 } | |
220 | |
221 static BigDecimal toBigDecimal(Object x){ | |
222 if(x instanceof BigDecimal) | |
223 return (BigDecimal) x; | |
224 else if(x instanceof BigInteger) | |
225 return new BigDecimal((BigInteger) x); | |
226 else | |
227 return BigDecimal.valueOf(((Number) x).longValue()); | |
228 } | |
229 | |
230 static Ratio toRatio(Object x){ | |
231 if(x instanceof Ratio) | |
232 return (Ratio) x; | |
233 else if(x instanceof BigDecimal) | |
234 { | |
235 BigDecimal bx = (BigDecimal) x; | |
236 BigInteger bv = bx.unscaledValue(); | |
237 int scale = bx.scale(); | |
238 if(scale < 0) | |
239 return new Ratio(bv.multiply(BigInteger.TEN.pow(-scale)), BigInteger.ONE); | |
240 else | |
241 return new Ratio(bv, BigInteger.TEN.pow(scale)); | |
242 } | |
243 return new Ratio(toBigInteger(x), BigInteger.ONE); | |
244 } | |
245 | |
246 static public Number rationalize(Number x){ | |
247 if(x instanceof Float || x instanceof Double) | |
248 return rationalize(BigDecimal.valueOf(x.doubleValue())); | |
249 else if(x instanceof BigDecimal) | |
250 { | |
251 BigDecimal bx = (BigDecimal) x; | |
252 BigInteger bv = bx.unscaledValue(); | |
253 int scale = bx.scale(); | |
254 if(scale < 0) | |
255 return bv.multiply(BigInteger.TEN.pow(-scale)); | |
256 else | |
257 return divide(bv, BigInteger.TEN.pow(scale)); | |
258 } | |
259 return x; | |
260 } | |
261 | |
262 static public Number reduce(Number val){ | |
263 if(val instanceof Long) | |
264 return reduce(val.longValue()); | |
265 else if (val instanceof BigInteger) | |
266 return reduce((BigInteger) val); | |
267 return val; | |
268 } | |
269 | |
270 static public Number reduce(BigInteger val){ | |
271 int bitLength = val.bitLength(); | |
272 if(bitLength < 32) | |
273 return val.intValue(); | |
274 else if(bitLength < 64) | |
275 return val.longValue(); | |
276 else | |
277 return val; | |
278 } | |
279 | |
280 static public Number reduce(long val){ | |
281 if(val >= Integer.MIN_VALUE && val <= Integer.MAX_VALUE) | |
282 return (int) val; | |
283 else | |
284 return val; | |
285 } | |
286 | |
287 static public Number divide(BigInteger n, BigInteger d){ | |
288 if(d.equals(BigInteger.ZERO)) | |
289 throw new ArithmeticException("Divide by zero"); | |
290 BigInteger gcd = n.gcd(d); | |
291 if(gcd.equals(BigInteger.ZERO)) | |
292 return 0; | |
293 n = n.divide(gcd); | |
294 d = d.divide(gcd); | |
295 if(d.equals(BigInteger.ONE)) | |
296 return reduce(n); | |
297 else if(d.equals(BigInteger.ONE.negate())) | |
298 return reduce(n.negate()); | |
299 return new Ratio((d.signum() < 0 ? n.negate() : n), | |
300 (d.signum() < 0 ? d.negate() : d)); | |
301 } | |
302 | |
303 static public Number not(Object x){ | |
304 return bitOps(x).not((Number)x); | |
305 } | |
306 | |
307 | |
308 static public Number and(Object x, Object y){ | |
309 return bitOps(x).combine(bitOps(y)).and((Number)x, (Number)y); | |
310 } | |
311 | |
312 static public Number or(Object x, Object y){ | |
313 return bitOps(x).combine(bitOps(y)).or((Number)x, (Number)y); | |
314 } | |
315 | |
316 static public Number xor(Object x, Object y){ | |
317 return bitOps(x).combine(bitOps(y)).xor((Number)x, (Number)y); | |
318 } | |
319 | |
320 static public Number andNot(Number x, Number y){ | |
321 return bitOps(x).combine(bitOps(y)).andNot(x, y); | |
322 } | |
323 | |
324 static public Number clearBit(Number x, int n){ | |
325 if(n < 0) | |
326 throw new ArithmeticException("Negative bit index"); | |
327 return bitOps(x).clearBit(x, n); | |
328 } | |
329 | |
330 static public Number setBit(Number x, int n){ | |
331 if(n < 0) | |
332 throw new ArithmeticException("Negative bit index"); | |
333 return bitOps(x).setBit(x, n); | |
334 } | |
335 | |
336 static public Number flipBit(Number x, int n){ | |
337 if(n < 0) | |
338 throw new ArithmeticException("Negative bit index"); | |
339 return bitOps(x).flipBit(x, n); | |
340 } | |
341 | |
342 static public boolean testBit(Number x, int n){ | |
343 if(n < 0) | |
344 throw new ArithmeticException("Negative bit index"); | |
345 return bitOps(x).testBit(x, n); | |
346 } | |
347 | |
348 static public Number shiftLeft(Object x, Object n){ | |
349 return bitOps(x).shiftLeft((Number)x, ((Number)n).intValue()); | |
350 } | |
351 | |
352 static public int shiftLeft(int x, int n){ | |
353 return x << n; | |
354 } | |
355 | |
356 static public Number shiftRight(Object x, Object n){ | |
357 return bitOps(x).shiftRight((Number)x, ((Number)n).intValue()); | |
358 } | |
359 | |
360 static public int shiftRight(int x, int n){ | |
361 return x >> n; | |
362 } | |
363 | |
364 final static class IntegerOps implements Ops{ | |
365 public Ops combine(Ops y){ | |
366 return y.opsWith(this); | |
367 } | |
368 | |
369 final public Ops opsWith(IntegerOps x){ | |
370 return this; | |
371 } | |
372 | |
373 final public Ops opsWith(LongOps x){ | |
374 return LONG_OPS; | |
375 } | |
376 | |
377 final public Ops opsWith(FloatOps x){ | |
378 return FLOAT_OPS; | |
379 } | |
380 | |
381 final public Ops opsWith(DoubleOps x){ | |
382 return DOUBLE_OPS; | |
383 } | |
384 | |
385 final public Ops opsWith(RatioOps x){ | |
386 return RATIO_OPS; | |
387 } | |
388 | |
389 final public Ops opsWith(BigIntegerOps x){ | |
390 return BIGINTEGER_OPS; | |
391 } | |
392 | |
393 final public Ops opsWith(BigDecimalOps x){ | |
394 return BIGDECIMAL_OPS; | |
395 } | |
396 | |
397 public boolean isZero(Number x){ | |
398 return x.intValue() == 0; | |
399 } | |
400 | |
401 public boolean isPos(Number x){ | |
402 return x.intValue() > 0; | |
403 } | |
404 | |
405 public boolean isNeg(Number x){ | |
406 return x.intValue() < 0; | |
407 } | |
408 | |
409 final public Number add(Number x, Number y){ | |
410 long ret = x.longValue() + y.longValue(); | |
411 if(ret <= Integer.MAX_VALUE && ret >= Integer.MIN_VALUE) | |
412 return (int) ret; | |
413 return ret; | |
414 } | |
415 | |
416 final public Number multiply(Number x, Number y){ | |
417 long ret = x.longValue() * y.longValue(); | |
418 if(ret <= Integer.MAX_VALUE && ret >= Integer.MIN_VALUE) | |
419 return (int) ret; | |
420 return ret; | |
421 } | |
422 | |
423 static int gcd(int u, int v){ | |
424 while(v != 0) | |
425 { | |
426 int r = u % v; | |
427 u = v; | |
428 v = r; | |
429 } | |
430 return u; | |
431 } | |
432 | |
433 public Number divide(Number x, Number y){ | |
434 int n = x.intValue(); | |
435 int val = y.intValue(); | |
436 int gcd = gcd(n, val); | |
437 if(gcd == 0) | |
438 return 0; | |
439 | |
440 n = n / gcd; | |
441 int d = val / gcd; | |
442 if(d == 1) | |
443 return n; | |
444 if(d < 0) | |
445 { | |
446 n = -n; | |
447 d = -d; | |
448 } | |
449 return new Ratio(BigInteger.valueOf(n), BigInteger.valueOf(d)); | |
450 } | |
451 | |
452 public Number quotient(Number x, Number y){ | |
453 return x.intValue() / y.intValue(); | |
454 } | |
455 | |
456 public Number remainder(Number x, Number y){ | |
457 return x.intValue() % y.intValue(); | |
458 } | |
459 | |
460 public boolean equiv(Number x, Number y){ | |
461 return x.intValue() == y.intValue(); | |
462 } | |
463 | |
464 public boolean lt(Number x, Number y){ | |
465 return x.intValue() < y.intValue(); | |
466 } | |
467 | |
468 //public Number subtract(Number x, Number y); | |
469 final public Number negate(Number x){ | |
470 int val = x.intValue(); | |
471 if(val > Integer.MIN_VALUE) | |
472 return -val; | |
473 return -((long) val); | |
474 } | |
475 | |
476 public Number inc(Number x){ | |
477 int val = x.intValue(); | |
478 if(val < Integer.MAX_VALUE) | |
479 return val + 1; | |
480 return (long) val + 1; | |
481 } | |
482 | |
483 public Number dec(Number x){ | |
484 int val = x.intValue(); | |
485 if(val > Integer.MIN_VALUE) | |
486 return val - 1; | |
487 return (long) val - 1; | |
488 } | |
489 } | |
490 | |
491 final static class LongOps implements Ops{ | |
492 public Ops combine(Ops y){ | |
493 return y.opsWith(this); | |
494 } | |
495 | |
496 final public Ops opsWith(IntegerOps x){ | |
497 return this; | |
498 } | |
499 | |
500 final public Ops opsWith(LongOps x){ | |
501 return this; | |
502 } | |
503 | |
504 final public Ops opsWith(FloatOps x){ | |
505 return FLOAT_OPS; | |
506 } | |
507 | |
508 final public Ops opsWith(DoubleOps x){ | |
509 return DOUBLE_OPS; | |
510 } | |
511 | |
512 final public Ops opsWith(RatioOps x){ | |
513 return RATIO_OPS; | |
514 } | |
515 | |
516 final public Ops opsWith(BigIntegerOps x){ | |
517 return BIGINTEGER_OPS; | |
518 } | |
519 | |
520 final public Ops opsWith(BigDecimalOps x){ | |
521 return BIGDECIMAL_OPS; | |
522 } | |
523 | |
524 public boolean isZero(Number x){ | |
525 return x.longValue() == 0; | |
526 } | |
527 | |
528 public boolean isPos(Number x){ | |
529 return x.longValue() > 0; | |
530 } | |
531 | |
532 public boolean isNeg(Number x){ | |
533 return x.longValue() < 0; | |
534 } | |
535 | |
536 final public Number add(Number x, Number y){ | |
537 long lx = x.longValue(), ly = y.longValue(); | |
538 long ret = lx + ly; | |
539 if ((ret ^ lx) < 0 && (ret ^ ly) < 0) | |
540 return BIGINTEGER_OPS.add(x, y); | |
541 return ret; | |
542 } | |
543 | |
544 final public Number multiply(Number x, Number y){ | |
545 long lx = x.longValue(), ly = y.longValue(); | |
546 long ret = lx * ly; | |
547 if (ly != 0 && ret/ly != lx) | |
548 return BIGINTEGER_OPS.multiply(x, y); | |
549 return ret; | |
550 } | |
551 | |
552 static long gcd(long u, long v){ | |
553 while(v != 0) | |
554 { | |
555 long r = u % v; | |
556 u = v; | |
557 v = r; | |
558 } | |
559 return u; | |
560 } | |
561 | |
562 public Number divide(Number x, Number y){ | |
563 long n = x.longValue(); | |
564 long val = y.longValue(); | |
565 long gcd = gcd(n, val); | |
566 if(gcd == 0) | |
567 return 0; | |
568 | |
569 n = n / gcd; | |
570 long d = val / gcd; | |
571 if(d == 1) | |
572 return n; | |
573 if(d < 0) | |
574 { | |
575 n = -n; | |
576 d = -d; | |
577 } | |
578 return new Ratio(BigInteger.valueOf(n), BigInteger.valueOf(d)); | |
579 } | |
580 | |
581 public Number quotient(Number x, Number y){ | |
582 return x.longValue() / y.longValue(); | |
583 } | |
584 | |
585 public Number remainder(Number x, Number y){ | |
586 return x.longValue() % y.longValue(); | |
587 } | |
588 | |
589 public boolean equiv(Number x, Number y){ | |
590 return x.longValue() == y.longValue(); | |
591 } | |
592 | |
593 public boolean lt(Number x, Number y){ | |
594 return x.longValue() < y.longValue(); | |
595 } | |
596 | |
597 //public Number subtract(Number x, Number y); | |
598 final public Number negate(Number x){ | |
599 long val = x.longValue(); | |
600 if(val > Long.MIN_VALUE) | |
601 return -val; | |
602 return BigInteger.valueOf(val).negate(); | |
603 } | |
604 | |
605 public Number inc(Number x){ | |
606 long val = x.longValue(); | |
607 if(val < Long.MAX_VALUE) | |
608 return val + 1; | |
609 return BIGINTEGER_OPS.inc(x); | |
610 } | |
611 | |
612 public Number dec(Number x){ | |
613 long val = x.longValue(); | |
614 if(val > Long.MIN_VALUE) | |
615 return val - 1; | |
616 return BIGINTEGER_OPS.dec(x); | |
617 } | |
618 } | |
619 | |
620 final static class FloatOps implements Ops{ | |
621 public Ops combine(Ops y){ | |
622 return y.opsWith(this); | |
623 } | |
624 | |
625 final public Ops opsWith(IntegerOps x){ | |
626 return this; | |
627 } | |
628 | |
629 final public Ops opsWith(LongOps x){ | |
630 return this; | |
631 } | |
632 | |
633 final public Ops opsWith(FloatOps x){ | |
634 return this; | |
635 } | |
636 | |
637 final public Ops opsWith(DoubleOps x){ | |
638 return DOUBLE_OPS; | |
639 } | |
640 | |
641 final public Ops opsWith(RatioOps x){ | |
642 return this; | |
643 } | |
644 | |
645 final public Ops opsWith(BigIntegerOps x){ | |
646 return this; | |
647 } | |
648 | |
649 final public Ops opsWith(BigDecimalOps x){ | |
650 return this; | |
651 } | |
652 | |
653 public boolean isZero(Number x){ | |
654 return x.floatValue() == 0; | |
655 } | |
656 | |
657 public boolean isPos(Number x){ | |
658 return x.floatValue() > 0; | |
659 } | |
660 | |
661 public boolean isNeg(Number x){ | |
662 return x.floatValue() < 0; | |
663 } | |
664 | |
665 final public Number add(Number x, Number y){ | |
666 return x.floatValue() + y.floatValue(); | |
667 } | |
668 | |
669 final public Number multiply(Number x, Number y){ | |
670 return x.floatValue() * y.floatValue(); | |
671 } | |
672 | |
673 public Number divide(Number x, Number y){ | |
674 return x.floatValue() / y.floatValue(); | |
675 } | |
676 | |
677 public Number quotient(Number x, Number y){ | |
678 return Numbers.quotient(x.doubleValue(), y.doubleValue()); | |
679 } | |
680 | |
681 public Number remainder(Number x, Number y){ | |
682 return Numbers.remainder(x.doubleValue(), y.doubleValue()); | |
683 } | |
684 | |
685 public boolean equiv(Number x, Number y){ | |
686 return x.floatValue() == y.floatValue(); | |
687 } | |
688 | |
689 public boolean lt(Number x, Number y){ | |
690 return x.floatValue() < y.floatValue(); | |
691 } | |
692 | |
693 //public Number subtract(Number x, Number y); | |
694 final public Number negate(Number x){ | |
695 return -x.floatValue(); | |
696 } | |
697 | |
698 public Number inc(Number x){ | |
699 return x.floatValue() + 1; | |
700 } | |
701 | |
702 public Number dec(Number x){ | |
703 return x.floatValue() - 1; | |
704 } | |
705 } | |
706 | |
707 final static class DoubleOps implements Ops{ | |
708 public Ops combine(Ops y){ | |
709 return y.opsWith(this); | |
710 } | |
711 | |
712 final public Ops opsWith(IntegerOps x){ | |
713 return this; | |
714 } | |
715 | |
716 final public Ops opsWith(LongOps x){ | |
717 return this; | |
718 } | |
719 | |
720 final public Ops opsWith(FloatOps x){ | |
721 return this; | |
722 } | |
723 | |
724 final public Ops opsWith(DoubleOps x){ | |
725 return this; | |
726 } | |
727 | |
728 final public Ops opsWith(RatioOps x){ | |
729 return this; | |
730 } | |
731 | |
732 final public Ops opsWith(BigIntegerOps x){ | |
733 return this; | |
734 } | |
735 | |
736 final public Ops opsWith(BigDecimalOps x){ | |
737 return this; | |
738 } | |
739 | |
740 public boolean isZero(Number x){ | |
741 return x.doubleValue() == 0; | |
742 } | |
743 | |
744 public boolean isPos(Number x){ | |
745 return x.doubleValue() > 0; | |
746 } | |
747 | |
748 public boolean isNeg(Number x){ | |
749 return x.doubleValue() < 0; | |
750 } | |
751 | |
752 final public Number add(Number x, Number y){ | |
753 return x.doubleValue() + y.doubleValue(); | |
754 } | |
755 | |
756 final public Number multiply(Number x, Number y){ | |
757 return x.doubleValue() * y.doubleValue(); | |
758 } | |
759 | |
760 public Number divide(Number x, Number y){ | |
761 return x.doubleValue() / y.doubleValue(); | |
762 } | |
763 | |
764 public Number quotient(Number x, Number y){ | |
765 return Numbers.quotient(x.doubleValue(), y.doubleValue()); | |
766 } | |
767 | |
768 public Number remainder(Number x, Number y){ | |
769 return Numbers.remainder(x.doubleValue(), y.doubleValue()); | |
770 } | |
771 | |
772 public boolean equiv(Number x, Number y){ | |
773 return x.doubleValue() == y.doubleValue(); | |
774 } | |
775 | |
776 public boolean lt(Number x, Number y){ | |
777 return x.doubleValue() < y.doubleValue(); | |
778 } | |
779 | |
780 //public Number subtract(Number x, Number y); | |
781 final public Number negate(Number x){ | |
782 return -x.doubleValue(); | |
783 } | |
784 | |
785 public Number inc(Number x){ | |
786 return x.doubleValue() + 1; | |
787 } | |
788 | |
789 public Number dec(Number x){ | |
790 return x.doubleValue() - 1; | |
791 } | |
792 } | |
793 | |
794 final static class RatioOps implements Ops{ | |
795 public Ops combine(Ops y){ | |
796 return y.opsWith(this); | |
797 } | |
798 | |
799 final public Ops opsWith(IntegerOps x){ | |
800 return this; | |
801 } | |
802 | |
803 final public Ops opsWith(LongOps x){ | |
804 return this; | |
805 } | |
806 | |
807 final public Ops opsWith(FloatOps x){ | |
808 return FLOAT_OPS; | |
809 } | |
810 | |
811 final public Ops opsWith(DoubleOps x){ | |
812 return DOUBLE_OPS; | |
813 } | |
814 | |
815 final public Ops opsWith(RatioOps x){ | |
816 return this; | |
817 } | |
818 | |
819 final public Ops opsWith(BigIntegerOps x){ | |
820 return this; | |
821 } | |
822 | |
823 final public Ops opsWith(BigDecimalOps x){ | |
824 return this; | |
825 } | |
826 | |
827 public boolean isZero(Number x){ | |
828 Ratio r = (Ratio) x; | |
829 return r.numerator.signum() == 0; | |
830 } | |
831 | |
832 public boolean isPos(Number x){ | |
833 Ratio r = (Ratio) x; | |
834 return r.numerator.signum() > 0; | |
835 } | |
836 | |
837 public boolean isNeg(Number x){ | |
838 Ratio r = (Ratio) x; | |
839 return r.numerator.signum() < 0; | |
840 } | |
841 | |
842 final public Number add(Number x, Number y){ | |
843 Ratio rx = toRatio(x); | |
844 Ratio ry = toRatio(y); | |
845 return divide(ry.numerator.multiply(rx.denominator) | |
846 .add(rx.numerator.multiply(ry.denominator)) | |
847 , ry.denominator.multiply(rx.denominator)); | |
848 } | |
849 | |
850 final public Number multiply(Number x, Number y){ | |
851 Ratio rx = toRatio(x); | |
852 Ratio ry = toRatio(y); | |
853 return Numbers.divide(ry.numerator.multiply(rx.numerator) | |
854 , ry.denominator.multiply(rx.denominator)); | |
855 } | |
856 | |
857 public Number divide(Number x, Number y){ | |
858 Ratio rx = toRatio(x); | |
859 Ratio ry = toRatio(y); | |
860 return Numbers.divide(ry.denominator.multiply(rx.numerator) | |
861 , ry.numerator.multiply(rx.denominator)); | |
862 } | |
863 | |
864 public Number quotient(Number x, Number y){ | |
865 Ratio rx = toRatio(x); | |
866 Ratio ry = toRatio(y); | |
867 BigInteger q = rx.numerator.multiply(ry.denominator).divide( | |
868 rx.denominator.multiply(ry.numerator)); | |
869 return reduce(q); | |
870 } | |
871 | |
872 public Number remainder(Number x, Number y){ | |
873 Ratio rx = toRatio(x); | |
874 Ratio ry = toRatio(y); | |
875 BigInteger q = rx.numerator.multiply(ry.denominator).divide( | |
876 rx.denominator.multiply(ry.numerator)); | |
877 return Numbers.minus(x, Numbers.multiply(q, y)); | |
878 } | |
879 | |
880 public boolean equiv(Number x, Number y){ | |
881 Ratio rx = toRatio(x); | |
882 Ratio ry = toRatio(y); | |
883 return rx.numerator.equals(ry.numerator) | |
884 && rx.denominator.equals(ry.denominator); | |
885 } | |
886 | |
887 public boolean lt(Number x, Number y){ | |
888 Ratio rx = toRatio(x); | |
889 Ratio ry = toRatio(y); | |
890 return Numbers.lt(rx.numerator.multiply(ry.denominator), ry.numerator.multiply(rx.denominator)); | |
891 } | |
892 | |
893 //public Number subtract(Number x, Number y); | |
894 final public Number negate(Number x){ | |
895 Ratio r = (Ratio) x; | |
896 return new Ratio(r.numerator.negate(), r.denominator); | |
897 } | |
898 | |
899 public Number inc(Number x){ | |
900 return Numbers.add(x, 1); | |
901 } | |
902 | |
903 public Number dec(Number x){ | |
904 return Numbers.add(x, -1); | |
905 } | |
906 | |
907 } | |
908 | |
909 final static class BigIntegerOps implements Ops{ | |
910 public Ops combine(Ops y){ | |
911 return y.opsWith(this); | |
912 } | |
913 | |
914 final public Ops opsWith(IntegerOps x){ | |
915 return this; | |
916 } | |
917 | |
918 final public Ops opsWith(LongOps x){ | |
919 return this; | |
920 } | |
921 | |
922 final public Ops opsWith(FloatOps x){ | |
923 return FLOAT_OPS; | |
924 } | |
925 | |
926 final public Ops opsWith(DoubleOps x){ | |
927 return DOUBLE_OPS; | |
928 } | |
929 | |
930 final public Ops opsWith(RatioOps x){ | |
931 return RATIO_OPS; | |
932 } | |
933 | |
934 final public Ops opsWith(BigIntegerOps x){ | |
935 return this; | |
936 } | |
937 | |
938 final public Ops opsWith(BigDecimalOps x){ | |
939 return BIGDECIMAL_OPS; | |
940 } | |
941 | |
942 public boolean isZero(Number x){ | |
943 BigInteger bx = toBigInteger(x); | |
944 return bx.signum() == 0; | |
945 } | |
946 | |
947 public boolean isPos(Number x){ | |
948 BigInteger bx = toBigInteger(x); | |
949 return bx.signum() > 0; | |
950 } | |
951 | |
952 public boolean isNeg(Number x){ | |
953 BigInteger bx = toBigInteger(x); | |
954 return bx.signum() < 0; | |
955 } | |
956 | |
957 final public Number add(Number x, Number y){ | |
958 return reduce(toBigInteger(x).add(toBigInteger(y))); | |
959 } | |
960 | |
961 final public Number multiply(Number x, Number y){ | |
962 return reduce(toBigInteger(x).multiply(toBigInteger(y))); | |
963 } | |
964 | |
965 public Number divide(Number x, Number y){ | |
966 return Numbers.divide(toBigInteger(x), toBigInteger(y)); | |
967 } | |
968 | |
969 public Number quotient(Number x, Number y){ | |
970 return toBigInteger(x).divide(toBigInteger(y)); | |
971 } | |
972 | |
973 public Number remainder(Number x, Number y){ | |
974 return toBigInteger(x).remainder(toBigInteger(y)); | |
975 } | |
976 | |
977 public boolean equiv(Number x, Number y){ | |
978 return toBigInteger(x).equals(toBigInteger(y)); | |
979 } | |
980 | |
981 public boolean lt(Number x, Number y){ | |
982 return toBigInteger(x).compareTo(toBigInteger(y)) < 0; | |
983 } | |
984 | |
985 //public Number subtract(Number x, Number y); | |
986 final public Number negate(Number x){ | |
987 return toBigInteger(x).negate(); | |
988 } | |
989 | |
990 public Number inc(Number x){ | |
991 BigInteger bx = toBigInteger(x); | |
992 return reduce(bx.add(BigInteger.ONE)); | |
993 } | |
994 | |
995 public Number dec(Number x){ | |
996 BigInteger bx = toBigInteger(x); | |
997 return reduce(bx.subtract(BigInteger.ONE)); | |
998 } | |
999 } | |
1000 | |
1001 final static class BigDecimalOps implements Ops{ | |
1002 final static Var MATH_CONTEXT = RT.MATH_CONTEXT; | |
1003 | |
1004 public Ops combine(Ops y){ | |
1005 return y.opsWith(this); | |
1006 } | |
1007 | |
1008 final public Ops opsWith(IntegerOps x){ | |
1009 return this; | |
1010 } | |
1011 | |
1012 final public Ops opsWith(LongOps x){ | |
1013 return this; | |
1014 } | |
1015 | |
1016 final public Ops opsWith(FloatOps x){ | |
1017 return FLOAT_OPS; | |
1018 } | |
1019 | |
1020 final public Ops opsWith(DoubleOps x){ | |
1021 return DOUBLE_OPS; | |
1022 } | |
1023 | |
1024 final public Ops opsWith(RatioOps x){ | |
1025 return RATIO_OPS; | |
1026 } | |
1027 | |
1028 final public Ops opsWith(BigIntegerOps x){ | |
1029 return this; | |
1030 } | |
1031 | |
1032 final public Ops opsWith(BigDecimalOps x){ | |
1033 return this; | |
1034 } | |
1035 | |
1036 public boolean isZero(Number x){ | |
1037 BigDecimal bx = (BigDecimal) x; | |
1038 return bx.signum() == 0; | |
1039 } | |
1040 | |
1041 public boolean isPos(Number x){ | |
1042 BigDecimal bx = (BigDecimal) x; | |
1043 return bx.signum() > 0; | |
1044 } | |
1045 | |
1046 public boolean isNeg(Number x){ | |
1047 BigDecimal bx = (BigDecimal) x; | |
1048 return bx.signum() < 0; | |
1049 } | |
1050 | |
1051 final public Number add(Number x, Number y){ | |
1052 MathContext mc = (MathContext) MATH_CONTEXT.deref(); | |
1053 return mc == null | |
1054 ? toBigDecimal(x).add(toBigDecimal(y)) | |
1055 : toBigDecimal(x).add(toBigDecimal(y), mc); | |
1056 } | |
1057 | |
1058 final public Number multiply(Number x, Number y){ | |
1059 MathContext mc = (MathContext) MATH_CONTEXT.deref(); | |
1060 return mc == null | |
1061 ? toBigDecimal(x).multiply(toBigDecimal(y)) | |
1062 : toBigDecimal(x).multiply(toBigDecimal(y), mc); | |
1063 } | |
1064 | |
1065 public Number divide(Number x, Number y){ | |
1066 MathContext mc = (MathContext) MATH_CONTEXT.deref(); | |
1067 return mc == null | |
1068 ? toBigDecimal(x).divide(toBigDecimal(y)) | |
1069 : toBigDecimal(x).divide(toBigDecimal(y), mc); | |
1070 } | |
1071 | |
1072 public Number quotient(Number x, Number y){ | |
1073 MathContext mc = (MathContext) MATH_CONTEXT.deref(); | |
1074 return mc == null | |
1075 ? toBigDecimal(x).divideToIntegralValue(toBigDecimal(y)) | |
1076 : toBigDecimal(x).divideToIntegralValue(toBigDecimal(y), mc); | |
1077 } | |
1078 | |
1079 public Number remainder(Number x, Number y){ | |
1080 MathContext mc = (MathContext) MATH_CONTEXT.deref(); | |
1081 return mc == null | |
1082 ? toBigDecimal(x).remainder(toBigDecimal(y)) | |
1083 : toBigDecimal(x).remainder(toBigDecimal(y), mc); | |
1084 } | |
1085 | |
1086 public boolean equiv(Number x, Number y){ | |
1087 return toBigDecimal(x).equals(toBigDecimal(y)); | |
1088 } | |
1089 | |
1090 public boolean lt(Number x, Number y){ | |
1091 return toBigDecimal(x).compareTo(toBigDecimal(y)) < 0; | |
1092 } | |
1093 | |
1094 //public Number subtract(Number x, Number y); | |
1095 final public Number negate(Number x){ | |
1096 MathContext mc = (MathContext) MATH_CONTEXT.deref(); | |
1097 return mc == null | |
1098 ? ((BigDecimal) x).negate() | |
1099 : ((BigDecimal) x).negate(mc); | |
1100 } | |
1101 | |
1102 public Number inc(Number x){ | |
1103 MathContext mc = (MathContext) MATH_CONTEXT.deref(); | |
1104 BigDecimal bx = (BigDecimal) x; | |
1105 return mc == null | |
1106 ? bx.add(BigDecimal.ONE) | |
1107 : bx.add(BigDecimal.ONE, mc); | |
1108 } | |
1109 | |
1110 public Number dec(Number x){ | |
1111 MathContext mc = (MathContext) MATH_CONTEXT.deref(); | |
1112 BigDecimal bx = (BigDecimal) x; | |
1113 return mc == null | |
1114 ? bx.subtract(BigDecimal.ONE) | |
1115 : bx.subtract(BigDecimal.ONE, mc); | |
1116 } | |
1117 } | |
1118 | |
1119 final static class IntegerBitOps implements BitOps{ | |
1120 public BitOps combine(BitOps y){ | |
1121 return y.bitOpsWith(this); | |
1122 } | |
1123 | |
1124 final public BitOps bitOpsWith(IntegerBitOps x){ | |
1125 return this; | |
1126 } | |
1127 | |
1128 final public BitOps bitOpsWith(LongBitOps x){ | |
1129 return LONG_BITOPS; | |
1130 } | |
1131 | |
1132 final public BitOps bitOpsWith(BigIntegerBitOps x){ | |
1133 return BIGINTEGER_BITOPS; | |
1134 } | |
1135 | |
1136 | |
1137 public Number not(Number x){ | |
1138 return ~x.intValue(); | |
1139 } | |
1140 | |
1141 public Number and(Number x, Number y){ | |
1142 return x.intValue() & y.intValue(); | |
1143 } | |
1144 | |
1145 public Number or(Number x, Number y){ | |
1146 return x.intValue() | y.intValue(); | |
1147 } | |
1148 | |
1149 public Number xor(Number x, Number y){ | |
1150 return x.intValue() ^ y.intValue(); | |
1151 } | |
1152 | |
1153 public Number andNot(Number x, Number y){ | |
1154 return x.intValue() & ~y.intValue(); | |
1155 } | |
1156 | |
1157 public Number clearBit(Number x, int n){ | |
1158 if(n < 31) | |
1159 return x.intValue() & ~(1 << n); | |
1160 else if(n < 63) | |
1161 return x.longValue() & ~(1L << n); | |
1162 else | |
1163 return toBigInteger(x).clearBit(n); | |
1164 } | |
1165 | |
1166 public Number setBit(Number x, int n){ | |
1167 if(n < 31) | |
1168 return x.intValue() | (1 << n); | |
1169 else if(n < 63) | |
1170 return x.longValue() | (1L << n); | |
1171 else | |
1172 return toBigInteger(x).setBit(n); | |
1173 } | |
1174 | |
1175 public Number flipBit(Number x, int n){ | |
1176 if(n < 31) | |
1177 return x.intValue() ^ (1 << n); | |
1178 else if(n < 63) | |
1179 return x.longValue() ^ (1L << n); | |
1180 else | |
1181 return toBigInteger(x).flipBit(n); | |
1182 } | |
1183 | |
1184 public boolean testBit(Number x, int n){ | |
1185 if(n < 32) | |
1186 return (x.intValue() & (1 << n)) != 0; | |
1187 else if(n < 64) | |
1188 return (x.longValue() & (1L << n)) != 0; | |
1189 else | |
1190 return toBigInteger(x).testBit(n); | |
1191 } | |
1192 | |
1193 public Number shiftLeft(Number x, int n){ | |
1194 if(n < 32) | |
1195 { | |
1196 if(n < 0) | |
1197 return shiftRight(x, -n); | |
1198 return reduce(x.longValue() << n); | |
1199 } | |
1200 else | |
1201 return reduce(toBigInteger(x).shiftLeft(n)); | |
1202 } | |
1203 | |
1204 public Number shiftRight(Number x, int n){ | |
1205 if(n < 0) | |
1206 return shiftLeft(x, -n); | |
1207 return x.intValue() >> n; | |
1208 } | |
1209 } | |
1210 | |
1211 final static class LongBitOps implements BitOps{ | |
1212 public BitOps combine(BitOps y){ | |
1213 return y.bitOpsWith(this); | |
1214 } | |
1215 | |
1216 final public BitOps bitOpsWith(IntegerBitOps x){ | |
1217 return this; | |
1218 } | |
1219 | |
1220 final public BitOps bitOpsWith(LongBitOps x){ | |
1221 return this; | |
1222 } | |
1223 | |
1224 final public BitOps bitOpsWith(BigIntegerBitOps x){ | |
1225 return BIGINTEGER_BITOPS; | |
1226 } | |
1227 | |
1228 public Number not(Number x){ | |
1229 return ~x.longValue(); | |
1230 } | |
1231 | |
1232 public Number and(Number x, Number y){ | |
1233 return x.longValue() & y.longValue(); | |
1234 } | |
1235 | |
1236 public Number or(Number x, Number y){ | |
1237 return x.longValue() | y.longValue(); | |
1238 } | |
1239 | |
1240 public Number xor(Number x, Number y){ | |
1241 return x.longValue() ^ y.longValue(); | |
1242 } | |
1243 | |
1244 public Number andNot(Number x, Number y){ | |
1245 return x.longValue() & ~y.longValue(); | |
1246 } | |
1247 | |
1248 public Number clearBit(Number x, int n){ | |
1249 if(n < 63) | |
1250 return x.longValue() & ~(1L << n); | |
1251 else | |
1252 return toBigInteger(x).clearBit(n); | |
1253 } | |
1254 | |
1255 public Number setBit(Number x, int n){ | |
1256 if(n < 63) | |
1257 return x.longValue() | (1L << n); | |
1258 else | |
1259 return toBigInteger(x).setBit(n); | |
1260 } | |
1261 | |
1262 public Number flipBit(Number x, int n){ | |
1263 if(n < 63) | |
1264 return x.longValue() ^ (1L << n); | |
1265 else | |
1266 return toBigInteger(x).flipBit(n); | |
1267 } | |
1268 | |
1269 public boolean testBit(Number x, int n){ | |
1270 if(n < 64) | |
1271 return (x.longValue() & (1L << n)) != 0; | |
1272 else | |
1273 return toBigInteger(x).testBit(n); | |
1274 } | |
1275 | |
1276 public Number shiftLeft(Number x, int n){ | |
1277 if(n < 0) | |
1278 return shiftRight(x, -n); | |
1279 return reduce(toBigInteger(x).shiftLeft(n)); | |
1280 } | |
1281 | |
1282 public Number shiftRight(Number x, int n){ | |
1283 if(n < 0) | |
1284 return shiftLeft(x, -n); | |
1285 return x.longValue() >> n; | |
1286 } | |
1287 } | |
1288 | |
1289 final static class BigIntegerBitOps implements BitOps{ | |
1290 public BitOps combine(BitOps y){ | |
1291 return y.bitOpsWith(this); | |
1292 } | |
1293 | |
1294 final public BitOps bitOpsWith(IntegerBitOps x){ | |
1295 return this; | |
1296 } | |
1297 | |
1298 final public BitOps bitOpsWith(LongBitOps x){ | |
1299 return this; | |
1300 } | |
1301 | |
1302 final public BitOps bitOpsWith(BigIntegerBitOps x){ | |
1303 return this; | |
1304 } | |
1305 | |
1306 public Number not(Number x){ | |
1307 return toBigInteger(x).not(); | |
1308 } | |
1309 | |
1310 public Number and(Number x, Number y){ | |
1311 return toBigInteger(x).and(toBigInteger(y)); | |
1312 } | |
1313 | |
1314 public Number or(Number x, Number y){ | |
1315 return toBigInteger(x).or(toBigInteger(y)); | |
1316 } | |
1317 | |
1318 public Number xor(Number x, Number y){ | |
1319 return toBigInteger(x).xor(toBigInteger(y)); | |
1320 } | |
1321 | |
1322 public Number andNot(Number x, Number y){ | |
1323 return toBigInteger(x).andNot(toBigInteger(y)); | |
1324 } | |
1325 | |
1326 public Number clearBit(Number x, int n){ | |
1327 return toBigInteger(x).clearBit(n); | |
1328 } | |
1329 | |
1330 public Number setBit(Number x, int n){ | |
1331 return toBigInteger(x).setBit(n); | |
1332 } | |
1333 | |
1334 public Number flipBit(Number x, int n){ | |
1335 return toBigInteger(x).flipBit(n); | |
1336 } | |
1337 | |
1338 public boolean testBit(Number x, int n){ | |
1339 return toBigInteger(x).testBit(n); | |
1340 } | |
1341 | |
1342 public Number shiftLeft(Number x, int n){ | |
1343 return toBigInteger(x).shiftLeft(n); | |
1344 } | |
1345 | |
1346 public Number shiftRight(Number x, int n){ | |
1347 return toBigInteger(x).shiftRight(n); | |
1348 } | |
1349 } | |
1350 | |
1351 static final IntegerOps INTEGER_OPS = new IntegerOps(); | |
1352 static final LongOps LONG_OPS = new LongOps(); | |
1353 static final FloatOps FLOAT_OPS = new FloatOps(); | |
1354 static final DoubleOps DOUBLE_OPS = new DoubleOps(); | |
1355 static final RatioOps RATIO_OPS = new RatioOps(); | |
1356 static final BigIntegerOps BIGINTEGER_OPS = new BigIntegerOps(); | |
1357 static final BigDecimalOps BIGDECIMAL_OPS = new BigDecimalOps(); | |
1358 | |
1359 static final IntegerBitOps INTEGER_BITOPS = new IntegerBitOps(); | |
1360 static final LongBitOps LONG_BITOPS = new LongBitOps(); | |
1361 static final BigIntegerBitOps BIGINTEGER_BITOPS = new BigIntegerBitOps(); | |
1362 | |
1363 static Ops ops(Object x){ | |
1364 Class xc = x.getClass(); | |
1365 | |
1366 if(xc == Integer.class) | |
1367 return INTEGER_OPS; | |
1368 else if(xc == Double.class) | |
1369 return DOUBLE_OPS; | |
1370 else if(xc == Float.class) | |
1371 return FLOAT_OPS; | |
1372 else if(xc == BigInteger.class) | |
1373 return BIGINTEGER_OPS; | |
1374 else if(xc == Long.class) | |
1375 return LONG_OPS; | |
1376 else if(xc == Ratio.class) | |
1377 return RATIO_OPS; | |
1378 else if(xc == BigDecimal.class) | |
1379 return BIGDECIMAL_OPS; | |
1380 else | |
1381 return INTEGER_OPS; | |
1382 } | |
1383 | |
1384 static BitOps bitOps(Object x){ | |
1385 Class xc = x.getClass(); | |
1386 | |
1387 if(xc == Integer.class) | |
1388 return INTEGER_BITOPS; | |
1389 else if(xc == Long.class) | |
1390 return LONG_BITOPS; | |
1391 else if(xc == BigInteger.class) | |
1392 return BIGINTEGER_BITOPS; | |
1393 else if(xc == Double.class || xc == Float.class || xc == BigDecimalOps.class || xc == Ratio.class) | |
1394 throw new ArithmeticException("bit operation on non integer type: " + xc); | |
1395 else | |
1396 return INTEGER_BITOPS; | |
1397 } | |
1398 | |
1399 //final static ExecutorService executor = Executors.newCachedThreadPool(); | |
1400 //static public int minChunk = 100; | |
1401 //static int chunkSize(int alength){ | |
1402 // return Math.max(alength / Runtime.getRuntime().availableProcessors(), minChunk); | |
1403 //} | |
1404 | |
1405 // } | |
1406 // else | |
1407 // { | |
1408 // LinkedList<Callable<Float>> ops = new LinkedList<Callable<Float>>(); | |
1409 // for(int offset = 0;offset < xs.length;offset+=chunk) | |
1410 // { | |
1411 // final int start = offset; | |
1412 // final int end = Math.min(xs.length, start + chunk); | |
1413 // ops.add(new Callable<Float>(){ | |
1414 // public Float call() throws Exception{ | |
1415 // for(int i=start;i<end;i++) | |
1416 // xs[i] += ys[i]; | |
1417 // return null; | |
1418 // }}); | |
1419 // } | |
1420 // executor.invokeAll(ops); | |
1421 // } | |
1422 | |
1423 | |
1424 static public float[] float_array(int size, Object init){ | |
1425 float[] ret = new float[size]; | |
1426 if(init instanceof Number) | |
1427 { | |
1428 float f = ((Number) init).floatValue(); | |
1429 for(int i = 0; i < ret.length; i++) | |
1430 ret[i] = f; | |
1431 } | |
1432 else | |
1433 { | |
1434 ISeq s = RT.seq(init); | |
1435 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1436 ret[i] = ((Number) s.first()).floatValue(); | |
1437 } | |
1438 return ret; | |
1439 } | |
1440 | |
1441 static public float[] float_array(Object sizeOrSeq){ | |
1442 if(sizeOrSeq instanceof Number) | |
1443 return new float[((Number) sizeOrSeq).intValue()]; | |
1444 else | |
1445 { | |
1446 ISeq s = RT.seq(sizeOrSeq); | |
1447 int size = RT.count(s); | |
1448 float[] ret = new float[size]; | |
1449 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1450 ret[i] = ((Number) s.first()).floatValue(); | |
1451 return ret; | |
1452 } | |
1453 } | |
1454 | |
1455 static public double[] double_array(int size, Object init){ | |
1456 double[] ret = new double[size]; | |
1457 if(init instanceof Number) | |
1458 { | |
1459 double f = ((Number) init).doubleValue(); | |
1460 for(int i = 0; i < ret.length; i++) | |
1461 ret[i] = f; | |
1462 } | |
1463 else | |
1464 { | |
1465 ISeq s = RT.seq(init); | |
1466 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1467 ret[i] = ((Number) s.first()).doubleValue(); | |
1468 } | |
1469 return ret; | |
1470 } | |
1471 | |
1472 static public double[] double_array(Object sizeOrSeq){ | |
1473 if(sizeOrSeq instanceof Number) | |
1474 return new double[((Number) sizeOrSeq).intValue()]; | |
1475 else | |
1476 { | |
1477 ISeq s = RT.seq(sizeOrSeq); | |
1478 int size = RT.count(s); | |
1479 double[] ret = new double[size]; | |
1480 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1481 ret[i] = ((Number) s.first()).doubleValue(); | |
1482 return ret; | |
1483 } | |
1484 } | |
1485 | |
1486 static public int[] int_array(int size, Object init){ | |
1487 int[] ret = new int[size]; | |
1488 if(init instanceof Number) | |
1489 { | |
1490 int f = ((Number) init).intValue(); | |
1491 for(int i = 0; i < ret.length; i++) | |
1492 ret[i] = f; | |
1493 } | |
1494 else | |
1495 { | |
1496 ISeq s = RT.seq(init); | |
1497 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1498 ret[i] = ((Number) s.first()).intValue(); | |
1499 } | |
1500 return ret; | |
1501 } | |
1502 | |
1503 static public int[] int_array(Object sizeOrSeq){ | |
1504 if(sizeOrSeq instanceof Number) | |
1505 return new int[((Number) sizeOrSeq).intValue()]; | |
1506 else | |
1507 { | |
1508 ISeq s = RT.seq(sizeOrSeq); | |
1509 int size = RT.count(s); | |
1510 int[] ret = new int[size]; | |
1511 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1512 ret[i] = ((Number) s.first()).intValue(); | |
1513 return ret; | |
1514 } | |
1515 } | |
1516 | |
1517 static public long[] long_array(int size, Object init){ | |
1518 long[] ret = new long[size]; | |
1519 if(init instanceof Number) | |
1520 { | |
1521 long f = ((Number) init).longValue(); | |
1522 for(int i = 0; i < ret.length; i++) | |
1523 ret[i] = f; | |
1524 } | |
1525 else | |
1526 { | |
1527 ISeq s = RT.seq(init); | |
1528 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1529 ret[i] = ((Number) s.first()).longValue(); | |
1530 } | |
1531 return ret; | |
1532 } | |
1533 | |
1534 static public long[] long_array(Object sizeOrSeq){ | |
1535 if(sizeOrSeq instanceof Number) | |
1536 return new long[((Number) sizeOrSeq).intValue()]; | |
1537 else | |
1538 { | |
1539 ISeq s = RT.seq(sizeOrSeq); | |
1540 int size = RT.count(s); | |
1541 long[] ret = new long[size]; | |
1542 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1543 ret[i] = ((Number) s.first()).longValue(); | |
1544 return ret; | |
1545 } | |
1546 } | |
1547 | |
1548 static public short[] short_array(int size, Object init){ | |
1549 short[] ret = new short[size]; | |
1550 if(init instanceof Short) | |
1551 { | |
1552 short s = (Short) init; | |
1553 for(int i = 0; i < ret.length; i++) | |
1554 ret[i] = s; | |
1555 } | |
1556 else | |
1557 { | |
1558 ISeq s = RT.seq(init); | |
1559 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1560 ret[i] = (Short) s.first(); | |
1561 } | |
1562 return ret; | |
1563 } | |
1564 | |
1565 static public short[] short_array(Object sizeOrSeq){ | |
1566 if(sizeOrSeq instanceof Number) | |
1567 return new short[((Number) sizeOrSeq).intValue()]; | |
1568 else | |
1569 { | |
1570 ISeq s = RT.seq(sizeOrSeq); | |
1571 int size = RT.count(s); | |
1572 short[] ret = new short[size]; | |
1573 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1574 ret[i] = (Short) s.first(); | |
1575 return ret; | |
1576 } | |
1577 } | |
1578 | |
1579 static public char[] char_array(int size, Object init){ | |
1580 char[] ret = new char[size]; | |
1581 if(init instanceof Character) | |
1582 { | |
1583 char c = (Character) init; | |
1584 for(int i = 0; i < ret.length; i++) | |
1585 ret[i] = c; | |
1586 } | |
1587 else | |
1588 { | |
1589 ISeq s = RT.seq(init); | |
1590 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1591 ret[i] = (Character) s.first(); | |
1592 } | |
1593 return ret; | |
1594 } | |
1595 | |
1596 static public char[] char_array(Object sizeOrSeq){ | |
1597 if(sizeOrSeq instanceof Number) | |
1598 return new char[((Number) sizeOrSeq).intValue()]; | |
1599 else | |
1600 { | |
1601 ISeq s = RT.seq(sizeOrSeq); | |
1602 int size = RT.count(s); | |
1603 char[] ret = new char[size]; | |
1604 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1605 ret[i] = (Character) s.first(); | |
1606 return ret; | |
1607 } | |
1608 } | |
1609 | |
1610 static public byte[] byte_array(int size, Object init){ | |
1611 byte[] ret = new byte[size]; | |
1612 if(init instanceof Byte) | |
1613 { | |
1614 byte b = (Byte) init; | |
1615 for(int i = 0; i < ret.length; i++) | |
1616 ret[i] = b; | |
1617 } | |
1618 else | |
1619 { | |
1620 ISeq s = RT.seq(init); | |
1621 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1622 ret[i] = (Byte) s.first(); | |
1623 } | |
1624 return ret; | |
1625 } | |
1626 | |
1627 static public byte[] byte_array(Object sizeOrSeq){ | |
1628 if(sizeOrSeq instanceof Number) | |
1629 return new byte[((Number) sizeOrSeq).intValue()]; | |
1630 else | |
1631 { | |
1632 ISeq s = RT.seq(sizeOrSeq); | |
1633 int size = RT.count(s); | |
1634 byte[] ret = new byte[size]; | |
1635 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1636 ret[i] = (Byte)s.first(); | |
1637 return ret; | |
1638 } | |
1639 } | |
1640 | |
1641 static public boolean[] boolean_array(int size, Object init){ | |
1642 boolean[] ret = new boolean[size]; | |
1643 if(init instanceof Boolean) | |
1644 { | |
1645 boolean b = (Boolean) init; | |
1646 for(int i = 0; i < ret.length; i++) | |
1647 ret[i] = b; | |
1648 } | |
1649 else | |
1650 { | |
1651 ISeq s = RT.seq(init); | |
1652 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1653 ret[i] = (Boolean)s.first(); | |
1654 } | |
1655 return ret; | |
1656 } | |
1657 | |
1658 static public boolean[] boolean_array(Object sizeOrSeq){ | |
1659 if(sizeOrSeq instanceof Number) | |
1660 return new boolean[((Number) sizeOrSeq).intValue()]; | |
1661 else | |
1662 { | |
1663 ISeq s = RT.seq(sizeOrSeq); | |
1664 int size = RT.count(s); | |
1665 boolean[] ret = new boolean[size]; | |
1666 for(int i = 0; i < size && s != null; i++, s = s.next()) | |
1667 ret[i] = (Boolean)s.first(); | |
1668 return ret; | |
1669 } | |
1670 } | |
1671 | |
1672 static public boolean[] booleans(Object array){ | |
1673 return (boolean[]) array; | |
1674 } | |
1675 | |
1676 static public byte[] bytes(Object array){ | |
1677 return (byte[]) array; | |
1678 } | |
1679 | |
1680 static public char[] chars(Object array){ | |
1681 return (char[]) array; | |
1682 } | |
1683 | |
1684 static public short[] shorts(Object array){ | |
1685 return (short[]) array; | |
1686 } | |
1687 | |
1688 static public float[] floats(Object array){ | |
1689 return (float[]) array; | |
1690 } | |
1691 | |
1692 static public double[] doubles(Object array){ | |
1693 return (double[]) array; | |
1694 } | |
1695 | |
1696 static public int[] ints(Object array){ | |
1697 return (int[]) array; | |
1698 } | |
1699 | |
1700 static public long[] longs(Object array){ | |
1701 return (long[]) array; | |
1702 } | |
1703 | |
1704 static public Number num(Object x){ | |
1705 return (Number) x; | |
1706 } | |
1707 | |
1708 static public Number num(float x){ | |
1709 return x; | |
1710 } | |
1711 | |
1712 static public float add(float x, float y){ | |
1713 return x + y; | |
1714 } | |
1715 | |
1716 static public float minus(float x, float y){ | |
1717 return x - y; | |
1718 } | |
1719 | |
1720 static public float minus(float x){ | |
1721 return -x; | |
1722 } | |
1723 | |
1724 static public float inc(float x){ | |
1725 return x + 1; | |
1726 } | |
1727 | |
1728 static public float dec(float x){ | |
1729 return x - 1; | |
1730 } | |
1731 | |
1732 static public float multiply(float x, float y){ | |
1733 return x * y; | |
1734 } | |
1735 | |
1736 static public float divide(float x, float y){ | |
1737 return x / y; | |
1738 } | |
1739 | |
1740 static public boolean equiv(float x, float y){ | |
1741 return x == y; | |
1742 } | |
1743 | |
1744 static public boolean lt(float x, float y){ | |
1745 return x < y; | |
1746 } | |
1747 | |
1748 static public boolean lte(float x, float y){ | |
1749 return x <= y; | |
1750 } | |
1751 | |
1752 static public boolean gt(float x, float y){ | |
1753 return x > y; | |
1754 } | |
1755 | |
1756 static public boolean gte(float x, float y){ | |
1757 return x >= y; | |
1758 } | |
1759 | |
1760 static public boolean isPos(float x){ | |
1761 return x > 0; | |
1762 } | |
1763 | |
1764 static public boolean isNeg(float x){ | |
1765 return x < 0; | |
1766 } | |
1767 | |
1768 static public boolean isZero(float x){ | |
1769 return x == 0; | |
1770 } | |
1771 | |
1772 static public Number num(double x){ | |
1773 return x; | |
1774 } | |
1775 | |
1776 static public double add(double x, double y){ | |
1777 return x + y; | |
1778 } | |
1779 | |
1780 static public double minus(double x, double y){ | |
1781 return x - y; | |
1782 } | |
1783 | |
1784 static public double minus(double x){ | |
1785 return -x; | |
1786 } | |
1787 | |
1788 static public double inc(double x){ | |
1789 return x + 1; | |
1790 } | |
1791 | |
1792 static public double dec(double x){ | |
1793 return x - 1; | |
1794 } | |
1795 | |
1796 static public double multiply(double x, double y){ | |
1797 return x * y; | |
1798 } | |
1799 | |
1800 static public double divide(double x, double y){ | |
1801 return x / y; | |
1802 } | |
1803 | |
1804 static public boolean equiv(double x, double y){ | |
1805 return x == y; | |
1806 } | |
1807 | |
1808 static public boolean lt(double x, double y){ | |
1809 return x < y; | |
1810 } | |
1811 | |
1812 static public boolean lte(double x, double y){ | |
1813 return x <= y; | |
1814 } | |
1815 | |
1816 static public boolean gt(double x, double y){ | |
1817 return x > y; | |
1818 } | |
1819 | |
1820 static public boolean gte(double x, double y){ | |
1821 return x >= y; | |
1822 } | |
1823 | |
1824 static public boolean isPos(double x){ | |
1825 return x > 0; | |
1826 } | |
1827 | |
1828 static public boolean isNeg(double x){ | |
1829 return x < 0; | |
1830 } | |
1831 | |
1832 static public boolean isZero(double x){ | |
1833 return x == 0; | |
1834 } | |
1835 | |
1836 static int throwIntOverflow(){ | |
1837 throw new ArithmeticException("integer overflow"); | |
1838 } | |
1839 | |
1840 static public Number num(int x){ | |
1841 return x; | |
1842 } | |
1843 | |
1844 static public int unchecked_add(int x, int y){ | |
1845 return x + y; | |
1846 } | |
1847 | |
1848 static public int unchecked_subtract(int x, int y){ | |
1849 return x - y; | |
1850 } | |
1851 | |
1852 static public int unchecked_negate(int x){ | |
1853 return -x; | |
1854 } | |
1855 | |
1856 static public int unchecked_inc(int x){ | |
1857 return x + 1; | |
1858 } | |
1859 | |
1860 static public int unchecked_dec(int x){ | |
1861 return x - 1; | |
1862 } | |
1863 | |
1864 static public int unchecked_multiply(int x, int y){ | |
1865 return x * y; | |
1866 } | |
1867 | |
1868 static public int add(int x, int y){ | |
1869 int ret = x + y; | |
1870 if ((ret ^ x) < 0 && (ret ^ y) < 0) | |
1871 return throwIntOverflow(); | |
1872 return ret; | |
1873 } | |
1874 | |
1875 static public int not(int x){ | |
1876 return ~x; | |
1877 } | |
1878 | |
1879 static public int and(int x, int y){ | |
1880 return x & y; | |
1881 } | |
1882 | |
1883 static public int or(int x, int y){ | |
1884 return x | y; | |
1885 } | |
1886 | |
1887 static public int xor(int x, int y){ | |
1888 return x ^ y; | |
1889 } | |
1890 | |
1891 static public int minus(int x, int y){ | |
1892 int ret = x - y; | |
1893 if (((ret ^ x) < 0 && (ret ^ ~y) < 0)) | |
1894 return throwIntOverflow(); | |
1895 return ret; | |
1896 } | |
1897 | |
1898 static public int minus(int x){ | |
1899 if(x == Integer.MIN_VALUE) | |
1900 return throwIntOverflow(); | |
1901 return -x; | |
1902 } | |
1903 | |
1904 static public int inc(int x){ | |
1905 if(x == Integer.MAX_VALUE) | |
1906 return throwIntOverflow(); | |
1907 return x + 1; | |
1908 } | |
1909 | |
1910 static public int dec(int x){ | |
1911 if(x == Integer.MIN_VALUE) | |
1912 return throwIntOverflow(); | |
1913 return x - 1; | |
1914 } | |
1915 | |
1916 static public int multiply(int x, int y){ | |
1917 int ret = x * y; | |
1918 if (y != 0 && ret/y != x) | |
1919 return throwIntOverflow(); | |
1920 return ret; | |
1921 } | |
1922 | |
1923 static public int unchecked_divide(int x, int y){ | |
1924 return x / y; | |
1925 } | |
1926 | |
1927 static public int unchecked_remainder(int x, int y){ | |
1928 return x % y; | |
1929 } | |
1930 | |
1931 static public boolean equiv(int x, int y){ | |
1932 return x == y; | |
1933 } | |
1934 | |
1935 static public boolean lt(int x, int y){ | |
1936 return x < y; | |
1937 } | |
1938 | |
1939 static public boolean lte(int x, int y){ | |
1940 return x <= y; | |
1941 } | |
1942 | |
1943 static public boolean gt(int x, int y){ | |
1944 return x > y; | |
1945 } | |
1946 | |
1947 static public boolean gte(int x, int y){ | |
1948 return x >= y; | |
1949 } | |
1950 | |
1951 static public boolean isPos(int x){ | |
1952 return x > 0; | |
1953 } | |
1954 | |
1955 static public boolean isNeg(int x){ | |
1956 return x < 0; | |
1957 } | |
1958 | |
1959 static public boolean isZero(int x){ | |
1960 return x == 0; | |
1961 } | |
1962 | |
1963 static public Number num(long x){ | |
1964 return x; | |
1965 } | |
1966 | |
1967 static public long unchecked_add(long x, long y){ | |
1968 return x + y; | |
1969 } | |
1970 | |
1971 static public long unchecked_subtract(long x, long y){ | |
1972 return x - y; | |
1973 } | |
1974 | |
1975 static public long unchecked_negate(long x){ | |
1976 return -x; | |
1977 } | |
1978 | |
1979 static public long unchecked_inc(long x){ | |
1980 return x + 1; | |
1981 } | |
1982 | |
1983 static public long unchecked_dec(long x){ | |
1984 return x - 1; | |
1985 } | |
1986 | |
1987 static public long unchecked_multiply(long x, long y){ | |
1988 return x * y; | |
1989 } | |
1990 | |
1991 static public long add(long x, long y){ | |
1992 long ret = x + y; | |
1993 if ((ret ^ x) < 0 && (ret ^ y) < 0) | |
1994 return throwIntOverflow(); | |
1995 return ret; | |
1996 } | |
1997 | |
1998 static public long minus(long x, long y){ | |
1999 long ret = x - y; | |
2000 if (((ret ^ x) < 0 && (ret ^ ~y) < 0)) | |
2001 return throwIntOverflow(); | |
2002 return ret; | |
2003 } | |
2004 | |
2005 static public long minus(long x){ | |
2006 if(x == Long.MIN_VALUE) | |
2007 return throwIntOverflow(); | |
2008 return -x; | |
2009 } | |
2010 | |
2011 static public long inc(long x){ | |
2012 if(x == Long.MAX_VALUE) | |
2013 return throwIntOverflow(); | |
2014 return x + 1; | |
2015 } | |
2016 | |
2017 static public long dec(long x){ | |
2018 if(x == Long.MIN_VALUE) | |
2019 return throwIntOverflow(); | |
2020 return x - 1; | |
2021 } | |
2022 | |
2023 static public long multiply(long x, long y){ | |
2024 long ret = x * y; | |
2025 if (y != 0 && ret/y != x) | |
2026 return throwIntOverflow(); | |
2027 return ret; | |
2028 } | |
2029 | |
2030 static public long unchecked_divide(long x, long y){ | |
2031 return x / y; | |
2032 } | |
2033 | |
2034 static public long unchecked_remainder(long x, long y){ | |
2035 return x % y; | |
2036 } | |
2037 | |
2038 static public boolean equiv(long x, long y){ | |
2039 return x == y; | |
2040 } | |
2041 | |
2042 static public boolean lt(long x, long y){ | |
2043 return x < y; | |
2044 } | |
2045 | |
2046 static public boolean lte(long x, long y){ | |
2047 return x <= y; | |
2048 } | |
2049 | |
2050 static public boolean gt(long x, long y){ | |
2051 return x > y; | |
2052 } | |
2053 | |
2054 static public boolean gte(long x, long y){ | |
2055 return x >= y; | |
2056 } | |
2057 | |
2058 static public boolean isPos(long x){ | |
2059 return x > 0; | |
2060 } | |
2061 | |
2062 static public boolean isNeg(long x){ | |
2063 return x < 0; | |
2064 } | |
2065 | |
2066 static public boolean isZero(long x){ | |
2067 return x == 0; | |
2068 } | |
2069 | |
2070 /* | |
2071 static public class F{ | |
2072 static public float add(float x, float y){ | |
2073 return x + y; | |
2074 } | |
2075 | |
2076 static public float subtract(float x, float y){ | |
2077 return x - y; | |
2078 } | |
2079 | |
2080 static public float negate(float x){ | |
2081 return -x; | |
2082 } | |
2083 | |
2084 static public float inc(float x){ | |
2085 return x + 1; | |
2086 } | |
2087 | |
2088 static public float dec(float x){ | |
2089 return x - 1; | |
2090 } | |
2091 | |
2092 static public float multiply(float x, float y){ | |
2093 return x * y; | |
2094 } | |
2095 | |
2096 static public float divide(float x, float y){ | |
2097 return x / y; | |
2098 } | |
2099 | |
2100 static public boolean equiv(float x, float y){ | |
2101 return x == y; | |
2102 } | |
2103 | |
2104 static public boolean lt(float x, float y){ | |
2105 return x < y; | |
2106 } | |
2107 | |
2108 static public boolean lte(float x, float y){ | |
2109 return x <= y; | |
2110 } | |
2111 | |
2112 static public boolean gt(float x, float y){ | |
2113 return x > y; | |
2114 } | |
2115 | |
2116 static public boolean gte(float x, float y){ | |
2117 return x >= y; | |
2118 } | |
2119 | |
2120 static public boolean pos(float x){ | |
2121 return x > 0; | |
2122 } | |
2123 | |
2124 static public boolean neg(float x){ | |
2125 return x < 0; | |
2126 } | |
2127 | |
2128 static public boolean zero(float x){ | |
2129 return x == 0; | |
2130 } | |
2131 | |
2132 static public float aget(float[] xs, int i){ | |
2133 return xs[i]; | |
2134 } | |
2135 | |
2136 static public float aset(float[] xs, int i, float v){ | |
2137 xs[i] = v; | |
2138 return v; | |
2139 } | |
2140 | |
2141 static public int alength(float[] xs){ | |
2142 return xs.length; | |
2143 } | |
2144 | |
2145 static public float[] aclone(float[] xs){ | |
2146 return xs.clone(); | |
2147 } | |
2148 | |
2149 static public float[] vec(int size, Object init){ | |
2150 float[] ret = new float[size]; | |
2151 if(init instanceof Number) | |
2152 { | |
2153 float f = ((Number) init).floatValue(); | |
2154 for(int i = 0; i < ret.length; i++) | |
2155 ret[i] = f; | |
2156 } | |
2157 else | |
2158 { | |
2159 ISeq s = RT.seq(init); | |
2160 for(int i = 0; i < size && s != null; i++, s = s.rest()) | |
2161 ret[i] = ((Number) s.first()).floatValue(); | |
2162 } | |
2163 return ret; | |
2164 } | |
2165 | |
2166 static public float[] vec(Object sizeOrSeq){ | |
2167 if(sizeOrSeq instanceof Number) | |
2168 return new float[((Number) sizeOrSeq).intValue()]; | |
2169 else | |
2170 { | |
2171 ISeq s = RT.seq(sizeOrSeq); | |
2172 int size = s.count(); | |
2173 float[] ret = new float[size]; | |
2174 for(int i = 0; i < size && s != null; i++, s = s.rest()) | |
2175 ret[i] = ((Number) s.first()).intValue(); | |
2176 return ret; | |
2177 } | |
2178 } | |
2179 | |
2180 | |
2181 static public float[] vsadd(float[] x, float y){ | |
2182 final float[] xs = x.clone(); | |
2183 for(int i = 0; i < xs.length; i++) | |
2184 xs[i] += y; | |
2185 return xs; | |
2186 } | |
2187 | |
2188 static public float[] vssub(float[] x, float y){ | |
2189 final float[] xs = x.clone(); | |
2190 for(int i = 0; i < xs.length; i++) | |
2191 xs[i] -= y; | |
2192 return xs; | |
2193 } | |
2194 | |
2195 static public float[] vsdiv(float[] x, float y){ | |
2196 final float[] xs = x.clone(); | |
2197 for(int i = 0; i < xs.length; i++) | |
2198 xs[i] /= y; | |
2199 return xs; | |
2200 } | |
2201 | |
2202 static public float[] vsmul(float[] x, float y){ | |
2203 final float[] xs = x.clone(); | |
2204 for(int i = 0; i < xs.length; i++) | |
2205 xs[i] *= y; | |
2206 return xs; | |
2207 } | |
2208 | |
2209 static public float[] svdiv(float y, float[] x){ | |
2210 final float[] xs = x.clone(); | |
2211 for(int i = 0; i < xs.length; i++) | |
2212 xs[i] = y / xs[i]; | |
2213 return xs; | |
2214 } | |
2215 | |
2216 static public float[] vsmuladd(float[] x, float y, float[] zs){ | |
2217 final float[] xs = x.clone(); | |
2218 for(int i = 0; i < xs.length; i++) | |
2219 xs[i] = xs[i] * y + zs[i]; | |
2220 return xs; | |
2221 } | |
2222 | |
2223 static public float[] vsmulsub(float[] x, float y, float[] zs){ | |
2224 final float[] xs = x.clone(); | |
2225 for(int i = 0; i < xs.length; i++) | |
2226 xs[i] = xs[i] * y - zs[i]; | |
2227 return xs; | |
2228 } | |
2229 | |
2230 static public float[] vsmulsadd(float[] x, float y, float z){ | |
2231 final float[] xs = x.clone(); | |
2232 for(int i = 0; i < xs.length; i++) | |
2233 xs[i] = xs[i] * y + z; | |
2234 return xs; | |
2235 } | |
2236 | |
2237 static public float[] vsmulssub(float[] x, float y, float z){ | |
2238 final float[] xs = x.clone(); | |
2239 for(int i = 0; i < xs.length; i++) | |
2240 xs[i] = xs[i] * y - z; | |
2241 return xs; | |
2242 } | |
2243 | |
2244 static public float[] vabs(float[] x){ | |
2245 final float[] xs = x.clone(); | |
2246 for(int i = 0; i < xs.length; i++) | |
2247 xs[i] = Math.abs(xs[i]); | |
2248 return xs; | |
2249 } | |
2250 | |
2251 static public float[] vnegabs(float[] x){ | |
2252 final float[] xs = x.clone(); | |
2253 for(int i = 0; i < xs.length; i++) | |
2254 xs[i] = -Math.abs(xs[i]); | |
2255 return xs; | |
2256 } | |
2257 | |
2258 static public float[] vneg(float[] x){ | |
2259 final float[] xs = x.clone(); | |
2260 for(int i = 0; i < xs.length; i++) | |
2261 xs[i] = -xs[i]; | |
2262 return xs; | |
2263 } | |
2264 | |
2265 static public float[] vsqr(float[] x){ | |
2266 final float[] xs = x.clone(); | |
2267 for(int i = 0; i < xs.length; i++) | |
2268 xs[i] *= xs[i]; | |
2269 return xs; | |
2270 } | |
2271 | |
2272 static public float[] vsignedsqr(float[] x){ | |
2273 final float[] xs = x.clone(); | |
2274 for(int i = 0; i < xs.length; i++) | |
2275 xs[i] *= Math.abs(xs[i]); | |
2276 return xs; | |
2277 } | |
2278 | |
2279 static public float[] vclip(float[] x, float low, float high){ | |
2280 final float[] xs = x.clone(); | |
2281 for(int i = 0; i < xs.length; i++) | |
2282 { | |
2283 if(xs[i] < low) | |
2284 xs[i] = low; | |
2285 else if(xs[i] > high) | |
2286 xs[i] = high; | |
2287 } | |
2288 return xs; | |
2289 } | |
2290 | |
2291 static public IPersistentVector vclipcounts(float[] x, float low, float high){ | |
2292 final float[] xs = x.clone(); | |
2293 int lowc = 0; | |
2294 int highc = 0; | |
2295 | |
2296 for(int i = 0; i < xs.length; i++) | |
2297 { | |
2298 if(xs[i] < low) | |
2299 { | |
2300 ++lowc; | |
2301 xs[i] = low; | |
2302 } | |
2303 else if(xs[i] > high) | |
2304 { | |
2305 ++highc; | |
2306 xs[i] = high; | |
2307 } | |
2308 } | |
2309 return RT.vector(xs, lowc, highc); | |
2310 } | |
2311 | |
2312 static public float[] vthresh(float[] x, float thresh, float otherwise){ | |
2313 final float[] xs = x.clone(); | |
2314 for(int i = 0; i < xs.length; i++) | |
2315 { | |
2316 if(xs[i] < thresh) | |
2317 xs[i] = otherwise; | |
2318 } | |
2319 return xs; | |
2320 } | |
2321 | |
2322 static public float[] vreverse(float[] x){ | |
2323 final float[] xs = x.clone(); | |
2324 for(int i = 0; i < xs.length; i++) | |
2325 xs[i] = xs[xs.length - i - 1]; | |
2326 return xs; | |
2327 } | |
2328 | |
2329 static public float[] vrunningsum(float[] x){ | |
2330 final float[] xs = x.clone(); | |
2331 for(int i = 1; i < xs.length; i++) | |
2332 xs[i] = xs[i - 1] + xs[i]; | |
2333 return xs; | |
2334 } | |
2335 | |
2336 static public float[] vsort(float[] x){ | |
2337 final float[] xs = x.clone(); | |
2338 Arrays.sort(xs); | |
2339 return xs; | |
2340 } | |
2341 | |
2342 static public float vdot(float[] xs, float[] ys){ | |
2343 float ret = 0; | |
2344 for(int i = 0; i < xs.length; i++) | |
2345 ret += xs[i] * ys[i]; | |
2346 return ret; | |
2347 } | |
2348 | |
2349 static public float vmax(float[] xs){ | |
2350 if(xs.length == 0) | |
2351 return 0; | |
2352 float ret = xs[0]; | |
2353 for(int i = 0; i < xs.length; i++) | |
2354 ret = Math.max(ret, xs[i]); | |
2355 return ret; | |
2356 } | |
2357 | |
2358 static public float vmin(float[] xs){ | |
2359 if(xs.length == 0) | |
2360 return 0; | |
2361 float ret = xs[0]; | |
2362 for(int i = 0; i < xs.length; i++) | |
2363 ret = Math.min(ret, xs[i]); | |
2364 return ret; | |
2365 } | |
2366 | |
2367 static public float vmean(float[] xs){ | |
2368 if(xs.length == 0) | |
2369 return 0; | |
2370 return vsum(xs) / xs.length; | |
2371 } | |
2372 | |
2373 static public double vrms(float[] xs){ | |
2374 if(xs.length == 0) | |
2375 return 0; | |
2376 float ret = 0; | |
2377 for(int i = 0; i < xs.length; i++) | |
2378 ret += xs[i] * xs[i]; | |
2379 return Math.sqrt(ret / xs.length); | |
2380 } | |
2381 | |
2382 static public float vsum(float[] xs){ | |
2383 float ret = 0; | |
2384 for(int i = 0; i < xs.length; i++) | |
2385 ret += xs[i]; | |
2386 return ret; | |
2387 } | |
2388 | |
2389 static public boolean vequiv(float[] xs, float[] ys){ | |
2390 return Arrays.equals(xs, ys); | |
2391 } | |
2392 | |
2393 static public float[] vadd(float[] x, float[] ys){ | |
2394 final float[] xs = x.clone(); | |
2395 for(int i = 0; i < xs.length; i++) | |
2396 xs[i] += ys[i]; | |
2397 return xs; | |
2398 } | |
2399 | |
2400 static public float[] vsub(float[] x, float[] ys){ | |
2401 final float[] xs = x.clone(); | |
2402 for(int i = 0; i < xs.length; i++) | |
2403 xs[i] -= ys[i]; | |
2404 return xs; | |
2405 } | |
2406 | |
2407 static public float[] vaddmul(float[] x, float[] ys, float[] zs){ | |
2408 final float[] xs = x.clone(); | |
2409 for(int i = 0; i < xs.length; i++) | |
2410 xs[i] = (xs[i] + ys[i]) * zs[i]; | |
2411 return xs; | |
2412 } | |
2413 | |
2414 static public float[] vsubmul(float[] x, float[] ys, float[] zs){ | |
2415 final float[] xs = x.clone(); | |
2416 for(int i = 0; i < xs.length; i++) | |
2417 xs[i] = (xs[i] - ys[i]) * zs[i]; | |
2418 return xs; | |
2419 } | |
2420 | |
2421 static public float[] vaddsmul(float[] x, float[] ys, float z){ | |
2422 final float[] xs = x.clone(); | |
2423 for(int i = 0; i < xs.length; i++) | |
2424 xs[i] = (xs[i] + ys[i]) * z; | |
2425 return xs; | |
2426 } | |
2427 | |
2428 static public float[] vsubsmul(float[] x, float[] ys, float z){ | |
2429 final float[] xs = x.clone(); | |
2430 for(int i = 0; i < xs.length; i++) | |
2431 xs[i] = (xs[i] - ys[i]) * z; | |
2432 return xs; | |
2433 } | |
2434 | |
2435 static public float[] vmulsadd(float[] x, float[] ys, float z){ | |
2436 final float[] xs = x.clone(); | |
2437 for(int i = 0; i < xs.length; i++) | |
2438 xs[i] = (xs[i] * ys[i]) + z; | |
2439 return xs; | |
2440 } | |
2441 | |
2442 static public float[] vdiv(float[] x, float[] ys){ | |
2443 final float[] xs = x.clone(); | |
2444 for(int i = 0; i < xs.length; i++) | |
2445 xs[i] /= ys[i]; | |
2446 return xs; | |
2447 } | |
2448 | |
2449 static public float[] vmul(float[] x, float[] ys){ | |
2450 final float[] xs = x.clone(); | |
2451 for(int i = 0; i < xs.length; i++) | |
2452 xs[i] *= ys[i]; | |
2453 return xs; | |
2454 } | |
2455 | |
2456 static public float[] vmuladd(float[] x, float[] ys, float[] zs){ | |
2457 final float[] xs = x.clone(); | |
2458 for(int i = 0; i < xs.length; i++) | |
2459 xs[i] = (xs[i] * ys[i]) + zs[i]; | |
2460 return xs; | |
2461 } | |
2462 | |
2463 static public float[] vmulsub(float[] x, float[] ys, float[] zs){ | |
2464 final float[] xs = x.clone(); | |
2465 for(int i = 0; i < xs.length; i++) | |
2466 xs[i] = (xs[i] * ys[i]) - zs[i]; | |
2467 return xs; | |
2468 } | |
2469 | |
2470 static public float[] vmax(float[] x, float[] ys){ | |
2471 final float[] xs = x.clone(); | |
2472 for(int i = 0; i < xs.length; i++) | |
2473 xs[i] = Math.max(xs[i], ys[i]); | |
2474 return xs; | |
2475 } | |
2476 | |
2477 static public float[] vmin(float[] x, float[] ys){ | |
2478 final float[] xs = x.clone(); | |
2479 for(int i = 0; i < xs.length; i++) | |
2480 xs[i] = Math.min(xs[i], ys[i]); | |
2481 return xs; | |
2482 } | |
2483 | |
2484 static public float[] vmap(IFn fn, float[] x) throws Exception{ | |
2485 float[] xs = x.clone(); | |
2486 for(int i = 0; i < xs.length; i++) | |
2487 xs[i] = ((Number) fn.invoke(xs[i])).floatValue(); | |
2488 return xs; | |
2489 } | |
2490 | |
2491 static public float[] vmap(IFn fn, float[] x, float[] ys) throws Exception{ | |
2492 float[] xs = x.clone(); | |
2493 for(int i = 0; i < xs.length; i++) | |
2494 xs[i] = ((Number) fn.invoke(xs[i], ys[i])).floatValue(); | |
2495 return xs; | |
2496 } | |
2497 | |
2498 } | |
2499 | |
2500 static public class D{ | |
2501 static public double add(double x, double y){ | |
2502 return x + y; | |
2503 } | |
2504 | |
2505 static public double subtract(double x, double y){ | |
2506 return x - y; | |
2507 } | |
2508 | |
2509 static public double negate(double x){ | |
2510 return -x; | |
2511 } | |
2512 | |
2513 static public double inc(double x){ | |
2514 return x + 1; | |
2515 } | |
2516 | |
2517 static public double dec(double x){ | |
2518 return x - 1; | |
2519 } | |
2520 | |
2521 static public double multiply(double x, double y){ | |
2522 return x * y; | |
2523 } | |
2524 | |
2525 static public double divide(double x, double y){ | |
2526 return x / y; | |
2527 } | |
2528 | |
2529 static public boolean equiv(double x, double y){ | |
2530 return x == y; | |
2531 } | |
2532 | |
2533 static public boolean lt(double x, double y){ | |
2534 return x < y; | |
2535 } | |
2536 | |
2537 static public boolean lte(double x, double y){ | |
2538 return x <= y; | |
2539 } | |
2540 | |
2541 static public boolean gt(double x, double y){ | |
2542 return x > y; | |
2543 } | |
2544 | |
2545 static public boolean gte(double x, double y){ | |
2546 return x >= y; | |
2547 } | |
2548 | |
2549 static public boolean pos(double x){ | |
2550 return x > 0; | |
2551 } | |
2552 | |
2553 static public boolean neg(double x){ | |
2554 return x < 0; | |
2555 } | |
2556 | |
2557 static public boolean zero(double x){ | |
2558 return x == 0; | |
2559 } | |
2560 | |
2561 static public double aget(double[] xs, int i){ | |
2562 return xs[i]; | |
2563 } | |
2564 | |
2565 static public double aset(double[] xs, int i, double v){ | |
2566 xs[i] = v; | |
2567 return v; | |
2568 } | |
2569 | |
2570 static public int alength(double[] xs){ | |
2571 return xs.length; | |
2572 } | |
2573 | |
2574 static public double[] aclone(double[] xs){ | |
2575 return xs.clone(); | |
2576 } | |
2577 | |
2578 static public double[] vec(int size, Object init){ | |
2579 double[] ret = new double[size]; | |
2580 if(init instanceof Number) | |
2581 { | |
2582 double f = ((Number) init).doubleValue(); | |
2583 for(int i = 0; i < ret.length; i++) | |
2584 ret[i] = f; | |
2585 } | |
2586 else | |
2587 { | |
2588 ISeq s = RT.seq(init); | |
2589 for(int i = 0; i < size && s != null; i++, s = s.rest()) | |
2590 ret[i] = ((Number) s.first()).doubleValue(); | |
2591 } | |
2592 return ret; | |
2593 } | |
2594 | |
2595 static public double[] vec(Object sizeOrSeq){ | |
2596 if(sizeOrSeq instanceof Number) | |
2597 return new double[((Number) sizeOrSeq).intValue()]; | |
2598 else | |
2599 { | |
2600 ISeq s = RT.seq(sizeOrSeq); | |
2601 int size = s.count(); | |
2602 double[] ret = new double[size]; | |
2603 for(int i = 0; i < size && s != null; i++, s = s.rest()) | |
2604 ret[i] = ((Number) s.first()).intValue(); | |
2605 return ret; | |
2606 } | |
2607 } | |
2608 | |
2609 static public double[] vsadd(double[] x, double y){ | |
2610 final double[] xs = x.clone(); | |
2611 for(int i = 0; i < xs.length; i++) | |
2612 xs[i] += y; | |
2613 return xs; | |
2614 } | |
2615 | |
2616 static public double[] vssub(double[] x, double y){ | |
2617 final double[] xs = x.clone(); | |
2618 for(int i = 0; i < xs.length; i++) | |
2619 xs[i] -= y; | |
2620 return xs; | |
2621 } | |
2622 | |
2623 static public double[] vsdiv(double[] x, double y){ | |
2624 final double[] xs = x.clone(); | |
2625 for(int i = 0; i < xs.length; i++) | |
2626 xs[i] /= y; | |
2627 return xs; | |
2628 } | |
2629 | |
2630 static public double[] vsmul(double[] x, double y){ | |
2631 final double[] xs = x.clone(); | |
2632 for(int i = 0; i < xs.length; i++) | |
2633 xs[i] *= y; | |
2634 return xs; | |
2635 } | |
2636 | |
2637 static public double[] svdiv(double y, double[] x){ | |
2638 final double[] xs = x.clone(); | |
2639 for(int i = 0; i < xs.length; i++) | |
2640 xs[i] = y / xs[i]; | |
2641 return xs; | |
2642 } | |
2643 | |
2644 static public double[] vsmuladd(double[] x, double y, double[] zs){ | |
2645 final double[] xs = x.clone(); | |
2646 for(int i = 0; i < xs.length; i++) | |
2647 xs[i] = xs[i] * y + zs[i]; | |
2648 return xs; | |
2649 } | |
2650 | |
2651 static public double[] vsmulsub(double[] x, double y, double[] zs){ | |
2652 final double[] xs = x.clone(); | |
2653 for(int i = 0; i < xs.length; i++) | |
2654 xs[i] = xs[i] * y - zs[i]; | |
2655 return xs; | |
2656 } | |
2657 | |
2658 static public double[] vsmulsadd(double[] x, double y, double z){ | |
2659 final double[] xs = x.clone(); | |
2660 for(int i = 0; i < xs.length; i++) | |
2661 xs[i] = xs[i] * y + z; | |
2662 return xs; | |
2663 } | |
2664 | |
2665 static public double[] vsmulssub(double[] x, double y, double z){ | |
2666 final double[] xs = x.clone(); | |
2667 for(int i = 0; i < xs.length; i++) | |
2668 xs[i] = xs[i] * y - z; | |
2669 return xs; | |
2670 } | |
2671 | |
2672 static public double[] vabs(double[] x){ | |
2673 final double[] xs = x.clone(); | |
2674 for(int i = 0; i < xs.length; i++) | |
2675 xs[i] = Math.abs(xs[i]); | |
2676 return xs; | |
2677 } | |
2678 | |
2679 static public double[] vnegabs(double[] x){ | |
2680 final double[] xs = x.clone(); | |
2681 for(int i = 0; i < xs.length; i++) | |
2682 xs[i] = -Math.abs(xs[i]); | |
2683 return xs; | |
2684 } | |
2685 | |
2686 static public double[] vneg(double[] x){ | |
2687 final double[] xs = x.clone(); | |
2688 for(int i = 0; i < xs.length; i++) | |
2689 xs[i] = -xs[i]; | |
2690 return xs; | |
2691 } | |
2692 | |
2693 static public double[] vsqr(double[] x){ | |
2694 final double[] xs = x.clone(); | |
2695 for(int i = 0; i < xs.length; i++) | |
2696 xs[i] *= xs[i]; | |
2697 return xs; | |
2698 } | |
2699 | |
2700 static public double[] vsignedsqr(double[] x){ | |
2701 final double[] xs = x.clone(); | |
2702 for(int i = 0; i < xs.length; i++) | |
2703 xs[i] *= Math.abs(xs[i]); | |
2704 return xs; | |
2705 } | |
2706 | |
2707 static public double[] vclip(double[] x, double low, double high){ | |
2708 final double[] xs = x.clone(); | |
2709 for(int i = 0; i < xs.length; i++) | |
2710 { | |
2711 if(xs[i] < low) | |
2712 xs[i] = low; | |
2713 else if(xs[i] > high) | |
2714 xs[i] = high; | |
2715 } | |
2716 return xs; | |
2717 } | |
2718 | |
2719 static public IPersistentVector vclipcounts(double[] x, double low, double high){ | |
2720 final double[] xs = x.clone(); | |
2721 int lowc = 0; | |
2722 int highc = 0; | |
2723 | |
2724 for(int i = 0; i < xs.length; i++) | |
2725 { | |
2726 if(xs[i] < low) | |
2727 { | |
2728 ++lowc; | |
2729 xs[i] = low; | |
2730 } | |
2731 else if(xs[i] > high) | |
2732 { | |
2733 ++highc; | |
2734 xs[i] = high; | |
2735 } | |
2736 } | |
2737 return RT.vector(xs, lowc, highc); | |
2738 } | |
2739 | |
2740 static public double[] vthresh(double[] x, double thresh, double otherwise){ | |
2741 final double[] xs = x.clone(); | |
2742 for(int i = 0; i < xs.length; i++) | |
2743 { | |
2744 if(xs[i] < thresh) | |
2745 xs[i] = otherwise; | |
2746 } | |
2747 return xs; | |
2748 } | |
2749 | |
2750 static public double[] vreverse(double[] x){ | |
2751 final double[] xs = x.clone(); | |
2752 for(int i = 0; i < xs.length; i++) | |
2753 xs[i] = xs[xs.length - i - 1]; | |
2754 return xs; | |
2755 } | |
2756 | |
2757 static public double[] vrunningsum(double[] x){ | |
2758 final double[] xs = x.clone(); | |
2759 for(int i = 1; i < xs.length; i++) | |
2760 xs[i] = xs[i - 1] + xs[i]; | |
2761 return xs; | |
2762 } | |
2763 | |
2764 static public double[] vsort(double[] x){ | |
2765 final double[] xs = x.clone(); | |
2766 Arrays.sort(xs); | |
2767 return xs; | |
2768 } | |
2769 | |
2770 static public double vdot(double[] xs, double[] ys){ | |
2771 double ret = 0; | |
2772 for(int i = 0; i < xs.length; i++) | |
2773 ret += xs[i] * ys[i]; | |
2774 return ret; | |
2775 } | |
2776 | |
2777 static public double vmax(double[] xs){ | |
2778 if(xs.length == 0) | |
2779 return 0; | |
2780 double ret = xs[0]; | |
2781 for(int i = 0; i < xs.length; i++) | |
2782 ret = Math.max(ret, xs[i]); | |
2783 return ret; | |
2784 } | |
2785 | |
2786 static public double vmin(double[] xs){ | |
2787 if(xs.length == 0) | |
2788 return 0; | |
2789 double ret = xs[0]; | |
2790 for(int i = 0; i < xs.length; i++) | |
2791 ret = Math.min(ret, xs[i]); | |
2792 return ret; | |
2793 } | |
2794 | |
2795 static public double vmean(double[] xs){ | |
2796 if(xs.length == 0) | |
2797 return 0; | |
2798 return vsum(xs) / xs.length; | |
2799 } | |
2800 | |
2801 static public double vrms(double[] xs){ | |
2802 if(xs.length == 0) | |
2803 return 0; | |
2804 double ret = 0; | |
2805 for(int i = 0; i < xs.length; i++) | |
2806 ret += xs[i] * xs[i]; | |
2807 return Math.sqrt(ret / xs.length); | |
2808 } | |
2809 | |
2810 static public double vsum(double[] xs){ | |
2811 double ret = 0; | |
2812 for(int i = 0; i < xs.length; i++) | |
2813 ret += xs[i]; | |
2814 return ret; | |
2815 } | |
2816 | |
2817 static public boolean vequiv(double[] xs, double[] ys){ | |
2818 return Arrays.equals(xs, ys); | |
2819 } | |
2820 | |
2821 static public double[] vadd(double[] x, double[] ys){ | |
2822 final double[] xs = x.clone(); | |
2823 for(int i = 0; i < xs.length; i++) | |
2824 xs[i] += ys[i]; | |
2825 return xs; | |
2826 } | |
2827 | |
2828 static public double[] vsub(double[] x, double[] ys){ | |
2829 final double[] xs = x.clone(); | |
2830 for(int i = 0; i < xs.length; i++) | |
2831 xs[i] -= ys[i]; | |
2832 return xs; | |
2833 } | |
2834 | |
2835 static public double[] vaddmul(double[] x, double[] ys, double[] zs){ | |
2836 final double[] xs = x.clone(); | |
2837 for(int i = 0; i < xs.length; i++) | |
2838 xs[i] = (xs[i] + ys[i]) * zs[i]; | |
2839 return xs; | |
2840 } | |
2841 | |
2842 static public double[] vsubmul(double[] x, double[] ys, double[] zs){ | |
2843 final double[] xs = x.clone(); | |
2844 for(int i = 0; i < xs.length; i++) | |
2845 xs[i] = (xs[i] - ys[i]) * zs[i]; | |
2846 return xs; | |
2847 } | |
2848 | |
2849 static public double[] vaddsmul(double[] x, double[] ys, double z){ | |
2850 final double[] xs = x.clone(); | |
2851 for(int i = 0; i < xs.length; i++) | |
2852 xs[i] = (xs[i] + ys[i]) * z; | |
2853 return xs; | |
2854 } | |
2855 | |
2856 static public double[] vsubsmul(double[] x, double[] ys, double z){ | |
2857 final double[] xs = x.clone(); | |
2858 for(int i = 0; i < xs.length; i++) | |
2859 xs[i] = (xs[i] - ys[i]) * z; | |
2860 return xs; | |
2861 } | |
2862 | |
2863 static public double[] vmulsadd(double[] x, double[] ys, double z){ | |
2864 final double[] xs = x.clone(); | |
2865 for(int i = 0; i < xs.length; i++) | |
2866 xs[i] = (xs[i] * ys[i]) + z; | |
2867 return xs; | |
2868 } | |
2869 | |
2870 static public double[] vdiv(double[] x, double[] ys){ | |
2871 final double[] xs = x.clone(); | |
2872 for(int i = 0; i < xs.length; i++) | |
2873 xs[i] /= ys[i]; | |
2874 return xs; | |
2875 } | |
2876 | |
2877 static public double[] vmul(double[] x, double[] ys){ | |
2878 final double[] xs = x.clone(); | |
2879 for(int i = 0; i < xs.length; i++) | |
2880 xs[i] *= ys[i]; | |
2881 return xs; | |
2882 } | |
2883 | |
2884 static public double[] vmuladd(double[] x, double[] ys, double[] zs){ | |
2885 final double[] xs = x.clone(); | |
2886 for(int i = 0; i < xs.length; i++) | |
2887 xs[i] = (xs[i] * ys[i]) + zs[i]; | |
2888 return xs; | |
2889 } | |
2890 | |
2891 static public double[] vmulsub(double[] x, double[] ys, double[] zs){ | |
2892 final double[] xs = x.clone(); | |
2893 for(int i = 0; i < xs.length; i++) | |
2894 xs[i] = (xs[i] * ys[i]) - zs[i]; | |
2895 return xs; | |
2896 } | |
2897 | |
2898 static public double[] vmax(double[] x, double[] ys){ | |
2899 final double[] xs = x.clone(); | |
2900 for(int i = 0; i < xs.length; i++) | |
2901 xs[i] = Math.max(xs[i], ys[i]); | |
2902 return xs; | |
2903 } | |
2904 | |
2905 static public double[] vmin(double[] x, double[] ys){ | |
2906 final double[] xs = x.clone(); | |
2907 for(int i = 0; i < xs.length; i++) | |
2908 xs[i] = Math.min(xs[i], ys[i]); | |
2909 return xs; | |
2910 } | |
2911 | |
2912 static public double[] vmap(IFn fn, double[] x) throws Exception{ | |
2913 double[] xs = x.clone(); | |
2914 for(int i = 0; i < xs.length; i++) | |
2915 xs[i] = ((Number) fn.invoke(xs[i])).doubleValue(); | |
2916 return xs; | |
2917 } | |
2918 | |
2919 static public double[] vmap(IFn fn, double[] x, double[] ys) throws Exception{ | |
2920 double[] xs = x.clone(); | |
2921 for(int i = 0; i < xs.length; i++) | |
2922 xs[i] = ((Number) fn.invoke(xs[i], ys[i])).doubleValue(); | |
2923 return xs; | |
2924 } | |
2925 } | |
2926 | |
2927 static public class I{ | |
2928 static public int add(int x, int y){ | |
2929 return x + y; | |
2930 } | |
2931 | |
2932 static public int subtract(int x, int y){ | |
2933 return x - y; | |
2934 } | |
2935 | |
2936 static public int negate(int x){ | |
2937 return -x; | |
2938 } | |
2939 | |
2940 static public int inc(int x){ | |
2941 return x + 1; | |
2942 } | |
2943 | |
2944 static public int dec(int x){ | |
2945 return x - 1; | |
2946 } | |
2947 | |
2948 static public int multiply(int x, int y){ | |
2949 return x * y; | |
2950 } | |
2951 | |
2952 static public int divide(int x, int y){ | |
2953 return x / y; | |
2954 } | |
2955 | |
2956 static public boolean equiv(int x, int y){ | |
2957 return x == y; | |
2958 } | |
2959 | |
2960 static public boolean lt(int x, int y){ | |
2961 return x < y; | |
2962 } | |
2963 | |
2964 static public boolean lte(int x, int y){ | |
2965 return x <= y; | |
2966 } | |
2967 | |
2968 static public boolean gt(int x, int y){ | |
2969 return x > y; | |
2970 } | |
2971 | |
2972 static public boolean gte(int x, int y){ | |
2973 return x >= y; | |
2974 } | |
2975 | |
2976 static public boolean pos(int x){ | |
2977 return x > 0; | |
2978 } | |
2979 | |
2980 static public boolean neg(int x){ | |
2981 return x < 0; | |
2982 } | |
2983 | |
2984 static public boolean zero(int x){ | |
2985 return x == 0; | |
2986 } | |
2987 | |
2988 static public int aget(int[] xs, int i){ | |
2989 return xs[i]; | |
2990 } | |
2991 | |
2992 static public int aset(int[] xs, int i, int v){ | |
2993 xs[i] = v; | |
2994 return v; | |
2995 } | |
2996 | |
2997 static public int alength(int[] xs){ | |
2998 return xs.length; | |
2999 } | |
3000 | |
3001 static public int[] aclone(int[] xs){ | |
3002 return xs.clone(); | |
3003 } | |
3004 | |
3005 static public int[] vec(int size, Object init){ | |
3006 int[] ret = new int[size]; | |
3007 if(init instanceof Number) | |
3008 { | |
3009 int f = ((Number) init).intValue(); | |
3010 for(int i = 0; i < ret.length; i++) | |
3011 ret[i] = f; | |
3012 } | |
3013 else | |
3014 { | |
3015 ISeq s = RT.seq(init); | |
3016 for(int i = 0; i < size && s != null; i++, s = s.rest()) | |
3017 ret[i] = ((Number) s.first()).intValue(); | |
3018 } | |
3019 return ret; | |
3020 } | |
3021 | |
3022 static public int[] vec(Object sizeOrSeq){ | |
3023 if(sizeOrSeq instanceof Number) | |
3024 return new int[((Number) sizeOrSeq).intValue()]; | |
3025 else | |
3026 { | |
3027 ISeq s = RT.seq(sizeOrSeq); | |
3028 int size = s.count(); | |
3029 int[] ret = new int[size]; | |
3030 for(int i = 0; i < size && s != null; i++, s = s.rest()) | |
3031 ret[i] = ((Number) s.first()).intValue(); | |
3032 return ret; | |
3033 } | |
3034 } | |
3035 | |
3036 static public int[] vsadd(int[] x, int y){ | |
3037 final int[] xs = x.clone(); | |
3038 for(int i = 0; i < xs.length; i++) | |
3039 xs[i] += y; | |
3040 return xs; | |
3041 } | |
3042 | |
3043 static public int[] vssub(int[] x, int y){ | |
3044 final int[] xs = x.clone(); | |
3045 for(int i = 0; i < xs.length; i++) | |
3046 xs[i] -= y; | |
3047 return xs; | |
3048 } | |
3049 | |
3050 static public int[] vsdiv(int[] x, int y){ | |
3051 final int[] xs = x.clone(); | |
3052 for(int i = 0; i < xs.length; i++) | |
3053 xs[i] /= y; | |
3054 return xs; | |
3055 } | |
3056 | |
3057 static public int[] vsmul(int[] x, int y){ | |
3058 final int[] xs = x.clone(); | |
3059 for(int i = 0; i < xs.length; i++) | |
3060 xs[i] *= y; | |
3061 return xs; | |
3062 } | |
3063 | |
3064 static public int[] svdiv(int y, int[] x){ | |
3065 final int[] xs = x.clone(); | |
3066 for(int i = 0; i < xs.length; i++) | |
3067 xs[i] = y / xs[i]; | |
3068 return xs; | |
3069 } | |
3070 | |
3071 static public int[] vsmuladd(int[] x, int y, int[] zs){ | |
3072 final int[] xs = x.clone(); | |
3073 for(int i = 0; i < xs.length; i++) | |
3074 xs[i] = xs[i] * y + zs[i]; | |
3075 return xs; | |
3076 } | |
3077 | |
3078 static public int[] vsmulsub(int[] x, int y, int[] zs){ | |
3079 final int[] xs = x.clone(); | |
3080 for(int i = 0; i < xs.length; i++) | |
3081 xs[i] = xs[i] * y - zs[i]; | |
3082 return xs; | |
3083 } | |
3084 | |
3085 static public int[] vsmulsadd(int[] x, int y, int z){ | |
3086 final int[] xs = x.clone(); | |
3087 for(int i = 0; i < xs.length; i++) | |
3088 xs[i] = xs[i] * y + z; | |
3089 return xs; | |
3090 } | |
3091 | |
3092 static public int[] vsmulssub(int[] x, int y, int z){ | |
3093 final int[] xs = x.clone(); | |
3094 for(int i = 0; i < xs.length; i++) | |
3095 xs[i] = xs[i] * y - z; | |
3096 return xs; | |
3097 } | |
3098 | |
3099 static public int[] vabs(int[] x){ | |
3100 final int[] xs = x.clone(); | |
3101 for(int i = 0; i < xs.length; i++) | |
3102 xs[i] = Math.abs(xs[i]); | |
3103 return xs; | |
3104 } | |
3105 | |
3106 static public int[] vnegabs(int[] x){ | |
3107 final int[] xs = x.clone(); | |
3108 for(int i = 0; i < xs.length; i++) | |
3109 xs[i] = -Math.abs(xs[i]); | |
3110 return xs; | |
3111 } | |
3112 | |
3113 static public int[] vneg(int[] x){ | |
3114 final int[] xs = x.clone(); | |
3115 for(int i = 0; i < xs.length; i++) | |
3116 xs[i] = -xs[i]; | |
3117 return xs; | |
3118 } | |
3119 | |
3120 static public int[] vsqr(int[] x){ | |
3121 final int[] xs = x.clone(); | |
3122 for(int i = 0; i < xs.length; i++) | |
3123 xs[i] *= xs[i]; | |
3124 return xs; | |
3125 } | |
3126 | |
3127 static public int[] vsignedsqr(int[] x){ | |
3128 final int[] xs = x.clone(); | |
3129 for(int i = 0; i < xs.length; i++) | |
3130 xs[i] *= Math.abs(xs[i]); | |
3131 return xs; | |
3132 } | |
3133 | |
3134 static public int[] vclip(int[] x, int low, int high){ | |
3135 final int[] xs = x.clone(); | |
3136 for(int i = 0; i < xs.length; i++) | |
3137 { | |
3138 if(xs[i] < low) | |
3139 xs[i] = low; | |
3140 else if(xs[i] > high) | |
3141 xs[i] = high; | |
3142 } | |
3143 return xs; | |
3144 } | |
3145 | |
3146 static public IPersistentVector vclipcounts(int[] x, int low, int high){ | |
3147 final int[] xs = x.clone(); | |
3148 int lowc = 0; | |
3149 int highc = 0; | |
3150 | |
3151 for(int i = 0; i < xs.length; i++) | |
3152 { | |
3153 if(xs[i] < low) | |
3154 { | |
3155 ++lowc; | |
3156 xs[i] = low; | |
3157 } | |
3158 else if(xs[i] > high) | |
3159 { | |
3160 ++highc; | |
3161 xs[i] = high; | |
3162 } | |
3163 } | |
3164 return RT.vector(xs, lowc, highc); | |
3165 } | |
3166 | |
3167 static public int[] vthresh(int[] x, int thresh, int otherwise){ | |
3168 final int[] xs = x.clone(); | |
3169 for(int i = 0; i < xs.length; i++) | |
3170 { | |
3171 if(xs[i] < thresh) | |
3172 xs[i] = otherwise; | |
3173 } | |
3174 return xs; | |
3175 } | |
3176 | |
3177 static public int[] vreverse(int[] x){ | |
3178 final int[] xs = x.clone(); | |
3179 for(int i = 0; i < xs.length; i++) | |
3180 xs[i] = xs[xs.length - i - 1]; | |
3181 return xs; | |
3182 } | |
3183 | |
3184 static public int[] vrunningsum(int[] x){ | |
3185 final int[] xs = x.clone(); | |
3186 for(int i = 1; i < xs.length; i++) | |
3187 xs[i] = xs[i - 1] + xs[i]; | |
3188 return xs; | |
3189 } | |
3190 | |
3191 static public int[] vsort(int[] x){ | |
3192 final int[] xs = x.clone(); | |
3193 Arrays.sort(xs); | |
3194 return xs; | |
3195 } | |
3196 | |
3197 static public int vdot(int[] xs, int[] ys){ | |
3198 int ret = 0; | |
3199 for(int i = 0; i < xs.length; i++) | |
3200 ret += xs[i] * ys[i]; | |
3201 return ret; | |
3202 } | |
3203 | |
3204 static public int vmax(int[] xs){ | |
3205 if(xs.length == 0) | |
3206 return 0; | |
3207 int ret = xs[0]; | |
3208 for(int i = 0; i < xs.length; i++) | |
3209 ret = Math.max(ret, xs[i]); | |
3210 return ret; | |
3211 } | |
3212 | |
3213 static public int vmin(int[] xs){ | |
3214 if(xs.length == 0) | |
3215 return 0; | |
3216 int ret = xs[0]; | |
3217 for(int i = 0; i < xs.length; i++) | |
3218 ret = Math.min(ret, xs[i]); | |
3219 return ret; | |
3220 } | |
3221 | |
3222 static public double vmean(int[] xs){ | |
3223 if(xs.length == 0) | |
3224 return 0; | |
3225 return vsum(xs) / (double) xs.length; | |
3226 } | |
3227 | |
3228 static public double vrms(int[] xs){ | |
3229 if(xs.length == 0) | |
3230 return 0; | |
3231 int ret = 0; | |
3232 for(int i = 0; i < xs.length; i++) | |
3233 ret += xs[i] * xs[i]; | |
3234 return Math.sqrt(ret / (double) xs.length); | |
3235 } | |
3236 | |
3237 static public int vsum(int[] xs){ | |
3238 int ret = 0; | |
3239 for(int i = 0; i < xs.length; i++) | |
3240 ret += xs[i]; | |
3241 return ret; | |
3242 } | |
3243 | |
3244 static public boolean vequiv(int[] xs, int[] ys){ | |
3245 return Arrays.equals(xs, ys); | |
3246 } | |
3247 | |
3248 static public int[] vadd(int[] x, int[] ys){ | |
3249 final int[] xs = x.clone(); | |
3250 for(int i = 0; i < xs.length; i++) | |
3251 xs[i] += ys[i]; | |
3252 return xs; | |
3253 } | |
3254 | |
3255 static public int[] vsub(int[] x, int[] ys){ | |
3256 final int[] xs = x.clone(); | |
3257 for(int i = 0; i < xs.length; i++) | |
3258 xs[i] -= ys[i]; | |
3259 return xs; | |
3260 } | |
3261 | |
3262 static public int[] vaddmul(int[] x, int[] ys, int[] zs){ | |
3263 final int[] xs = x.clone(); | |
3264 for(int i = 0; i < xs.length; i++) | |
3265 xs[i] = (xs[i] + ys[i]) * zs[i]; | |
3266 return xs; | |
3267 } | |
3268 | |
3269 static public int[] vsubmul(int[] x, int[] ys, int[] zs){ | |
3270 final int[] xs = x.clone(); | |
3271 for(int i = 0; i < xs.length; i++) | |
3272 xs[i] = (xs[i] - ys[i]) * zs[i]; | |
3273 return xs; | |
3274 } | |
3275 | |
3276 static public int[] vaddsmul(int[] x, int[] ys, int z){ | |
3277 final int[] xs = x.clone(); | |
3278 for(int i = 0; i < xs.length; i++) | |
3279 xs[i] = (xs[i] + ys[i]) * z; | |
3280 return xs; | |
3281 } | |
3282 | |
3283 static public int[] vsubsmul(int[] x, int[] ys, int z){ | |
3284 final int[] xs = x.clone(); | |
3285 for(int i = 0; i < xs.length; i++) | |
3286 xs[i] = (xs[i] - ys[i]) * z; | |
3287 return xs; | |
3288 } | |
3289 | |
3290 static public int[] vmulsadd(int[] x, int[] ys, int z){ | |
3291 final int[] xs = x.clone(); | |
3292 for(int i = 0; i < xs.length; i++) | |
3293 xs[i] = (xs[i] * ys[i]) + z; | |
3294 return xs; | |
3295 } | |
3296 | |
3297 static public int[] vdiv(int[] x, int[] ys){ | |
3298 final int[] xs = x.clone(); | |
3299 for(int i = 0; i < xs.length; i++) | |
3300 xs[i] /= ys[i]; | |
3301 return xs; | |
3302 } | |
3303 | |
3304 static public int[] vmul(int[] x, int[] ys){ | |
3305 final int[] xs = x.clone(); | |
3306 for(int i = 0; i < xs.length; i++) | |
3307 xs[i] *= ys[i]; | |
3308 return xs; | |
3309 } | |
3310 | |
3311 static public int[] vmuladd(int[] x, int[] ys, int[] zs){ | |
3312 final int[] xs = x.clone(); | |
3313 for(int i = 0; i < xs.length; i++) | |
3314 xs[i] = (xs[i] * ys[i]) + zs[i]; | |
3315 return xs; | |
3316 } | |
3317 | |
3318 static public int[] vmulsub(int[] x, int[] ys, int[] zs){ | |
3319 final int[] xs = x.clone(); | |
3320 for(int i = 0; i < xs.length; i++) | |
3321 xs[i] = (xs[i] * ys[i]) - zs[i]; | |
3322 return xs; | |
3323 } | |
3324 | |
3325 static public int[] vmax(int[] x, int[] ys){ | |
3326 final int[] xs = x.clone(); | |
3327 for(int i = 0; i < xs.length; i++) | |
3328 xs[i] = Math.max(xs[i], ys[i]); | |
3329 return xs; | |
3330 } | |
3331 | |
3332 static public int[] vmin(int[] x, int[] ys){ | |
3333 final int[] xs = x.clone(); | |
3334 for(int i = 0; i < xs.length; i++) | |
3335 xs[i] = Math.min(xs[i], ys[i]); | |
3336 return xs; | |
3337 } | |
3338 | |
3339 static public int[] vmap(IFn fn, int[] x) throws Exception{ | |
3340 int[] xs = x.clone(); | |
3341 for(int i = 0; i < xs.length; i++) | |
3342 xs[i] = ((Number) fn.invoke(xs[i])).intValue(); | |
3343 return xs; | |
3344 } | |
3345 | |
3346 static public int[] vmap(IFn fn, int[] x, int[] ys) throws Exception{ | |
3347 int[] xs = x.clone(); | |
3348 for(int i = 0; i < xs.length; i++) | |
3349 xs[i] = ((Number) fn.invoke(xs[i], ys[i])).intValue(); | |
3350 return xs; | |
3351 } | |
3352 | |
3353 } | |
3354 | |
3355 static public class L{ | |
3356 static public long add(long x, long y){ | |
3357 return x + y; | |
3358 } | |
3359 | |
3360 static public long subtract(long x, long y){ | |
3361 return x - y; | |
3362 } | |
3363 | |
3364 static public long negate(long x){ | |
3365 return -x; | |
3366 } | |
3367 | |
3368 static public long inc(long x){ | |
3369 return x + 1; | |
3370 } | |
3371 | |
3372 static public long dec(long x){ | |
3373 return x - 1; | |
3374 } | |
3375 | |
3376 static public long multiply(long x, long y){ | |
3377 return x * y; | |
3378 } | |
3379 | |
3380 static public long divide(long x, long y){ | |
3381 return x / y; | |
3382 } | |
3383 | |
3384 static public boolean equiv(long x, long y){ | |
3385 return x == y; | |
3386 } | |
3387 | |
3388 static public boolean lt(long x, long y){ | |
3389 return x < y; | |
3390 } | |
3391 | |
3392 static public boolean lte(long x, long y){ | |
3393 return x <= y; | |
3394 } | |
3395 | |
3396 static public boolean gt(long x, long y){ | |
3397 return x > y; | |
3398 } | |
3399 | |
3400 static public boolean gte(long x, long y){ | |
3401 return x >= y; | |
3402 } | |
3403 | |
3404 static public boolean pos(long x){ | |
3405 return x > 0; | |
3406 } | |
3407 | |
3408 static public boolean neg(long x){ | |
3409 return x < 0; | |
3410 } | |
3411 | |
3412 static public boolean zero(long x){ | |
3413 return x == 0; | |
3414 } | |
3415 | |
3416 static public long aget(long[] xs, int i){ | |
3417 return xs[i]; | |
3418 } | |
3419 | |
3420 static public long aset(long[] xs, int i, long v){ | |
3421 xs[i] = v; | |
3422 return v; | |
3423 } | |
3424 | |
3425 static public int alength(long[] xs){ | |
3426 return xs.length; | |
3427 } | |
3428 | |
3429 static public long[] aclone(long[] xs){ | |
3430 return xs.clone(); | |
3431 } | |
3432 | |
3433 static public long[] vec(int size, Object init){ | |
3434 long[] ret = new long[size]; | |
3435 if(init instanceof Number) | |
3436 { | |
3437 long f = ((Number) init).longValue(); | |
3438 for(int i = 0; i < ret.length; i++) | |
3439 ret[i] = f; | |
3440 } | |
3441 else | |
3442 { | |
3443 ISeq s = RT.seq(init); | |
3444 for(int i = 0; i < size && s != null; i++, s = s.rest()) | |
3445 ret[i] = ((Number) s.first()).longValue(); | |
3446 } | |
3447 return ret; | |
3448 } | |
3449 | |
3450 static public long[] vec(Object sizeOrSeq){ | |
3451 if(sizeOrSeq instanceof Number) | |
3452 return new long[((Number) sizeOrSeq).intValue()]; | |
3453 else | |
3454 { | |
3455 ISeq s = RT.seq(sizeOrSeq); | |
3456 int size = s.count(); | |
3457 long[] ret = new long[size]; | |
3458 for(int i = 0; i < size && s != null; i++, s = s.rest()) | |
3459 ret[i] = ((Number) s.first()).intValue(); | |
3460 return ret; | |
3461 } | |
3462 } | |
3463 | |
3464 | |
3465 static public long[] vsadd(long[] x, long y){ | |
3466 final long[] xs = x.clone(); | |
3467 for(int i = 0; i < xs.length; i++) | |
3468 xs[i] += y; | |
3469 return xs; | |
3470 } | |
3471 | |
3472 static public long[] vssub(long[] x, long y){ | |
3473 final long[] xs = x.clone(); | |
3474 for(int i = 0; i < xs.length; i++) | |
3475 xs[i] -= y; | |
3476 return xs; | |
3477 } | |
3478 | |
3479 static public long[] vsdiv(long[] x, long y){ | |
3480 final long[] xs = x.clone(); | |
3481 for(int i = 0; i < xs.length; i++) | |
3482 xs[i] /= y; | |
3483 return xs; | |
3484 } | |
3485 | |
3486 static public long[] vsmul(long[] x, long y){ | |
3487 final long[] xs = x.clone(); | |
3488 for(int i = 0; i < xs.length; i++) | |
3489 xs[i] *= y; | |
3490 return xs; | |
3491 } | |
3492 | |
3493 static public long[] svdiv(long y, long[] x){ | |
3494 final long[] xs = x.clone(); | |
3495 for(int i = 0; i < xs.length; i++) | |
3496 xs[i] = y / xs[i]; | |
3497 return xs; | |
3498 } | |
3499 | |
3500 static public long[] vsmuladd(long[] x, long y, long[] zs){ | |
3501 final long[] xs = x.clone(); | |
3502 for(int i = 0; i < xs.length; i++) | |
3503 xs[i] = xs[i] * y + zs[i]; | |
3504 return xs; | |
3505 } | |
3506 | |
3507 static public long[] vsmulsub(long[] x, long y, long[] zs){ | |
3508 final long[] xs = x.clone(); | |
3509 for(int i = 0; i < xs.length; i++) | |
3510 xs[i] = xs[i] * y - zs[i]; | |
3511 return xs; | |
3512 } | |
3513 | |
3514 static public long[] vsmulsadd(long[] x, long y, long z){ | |
3515 final long[] xs = x.clone(); | |
3516 for(int i = 0; i < xs.length; i++) | |
3517 xs[i] = xs[i] * y + z; | |
3518 return xs; | |
3519 } | |
3520 | |
3521 static public long[] vsmulssub(long[] x, long y, long z){ | |
3522 final long[] xs = x.clone(); | |
3523 for(int i = 0; i < xs.length; i++) | |
3524 xs[i] = xs[i] * y - z; | |
3525 return xs; | |
3526 } | |
3527 | |
3528 static public long[] vabs(long[] x){ | |
3529 final long[] xs = x.clone(); | |
3530 for(int i = 0; i < xs.length; i++) | |
3531 xs[i] = Math.abs(xs[i]); | |
3532 return xs; | |
3533 } | |
3534 | |
3535 static public long[] vnegabs(long[] x){ | |
3536 final long[] xs = x.clone(); | |
3537 for(int i = 0; i < xs.length; i++) | |
3538 xs[i] = -Math.abs(xs[i]); | |
3539 return xs; | |
3540 } | |
3541 | |
3542 static public long[] vneg(long[] x){ | |
3543 final long[] xs = x.clone(); | |
3544 for(int i = 0; i < xs.length; i++) | |
3545 xs[i] = -xs[i]; | |
3546 return xs; | |
3547 } | |
3548 | |
3549 static public long[] vsqr(long[] x){ | |
3550 final long[] xs = x.clone(); | |
3551 for(int i = 0; i < xs.length; i++) | |
3552 xs[i] *= xs[i]; | |
3553 return xs; | |
3554 } | |
3555 | |
3556 static public long[] vsignedsqr(long[] x){ | |
3557 final long[] xs = x.clone(); | |
3558 for(int i = 0; i < xs.length; i++) | |
3559 xs[i] *= Math.abs(xs[i]); | |
3560 return xs; | |
3561 } | |
3562 | |
3563 static public long[] vclip(long[] x, long low, long high){ | |
3564 final long[] xs = x.clone(); | |
3565 for(int i = 0; i < xs.length; i++) | |
3566 { | |
3567 if(xs[i] < low) | |
3568 xs[i] = low; | |
3569 else if(xs[i] > high) | |
3570 xs[i] = high; | |
3571 } | |
3572 return xs; | |
3573 } | |
3574 | |
3575 static public IPersistentVector vclipcounts(long[] x, long low, long high){ | |
3576 final long[] xs = x.clone(); | |
3577 int lowc = 0; | |
3578 int highc = 0; | |
3579 | |
3580 for(int i = 0; i < xs.length; i++) | |
3581 { | |
3582 if(xs[i] < low) | |
3583 { | |
3584 ++lowc; | |
3585 xs[i] = low; | |
3586 } | |
3587 else if(xs[i] > high) | |
3588 { | |
3589 ++highc; | |
3590 xs[i] = high; | |
3591 } | |
3592 } | |
3593 return RT.vector(xs, lowc, highc); | |
3594 } | |
3595 | |
3596 static public long[] vthresh(long[] x, long thresh, long otherwise){ | |
3597 final long[] xs = x.clone(); | |
3598 for(int i = 0; i < xs.length; i++) | |
3599 { | |
3600 if(xs[i] < thresh) | |
3601 xs[i] = otherwise; | |
3602 } | |
3603 return xs; | |
3604 } | |
3605 | |
3606 static public long[] vreverse(long[] x){ | |
3607 final long[] xs = x.clone(); | |
3608 for(int i = 0; i < xs.length; i++) | |
3609 xs[i] = xs[xs.length - i - 1]; | |
3610 return xs; | |
3611 } | |
3612 | |
3613 static public long[] vrunningsum(long[] x){ | |
3614 final long[] xs = x.clone(); | |
3615 for(int i = 1; i < xs.length; i++) | |
3616 xs[i] = xs[i - 1] + xs[i]; | |
3617 return xs; | |
3618 } | |
3619 | |
3620 static public long[] vsort(long[] x){ | |
3621 final long[] xs = x.clone(); | |
3622 Arrays.sort(xs); | |
3623 return xs; | |
3624 } | |
3625 | |
3626 static public long vdot(long[] xs, long[] ys){ | |
3627 long ret = 0; | |
3628 for(int i = 0; i < xs.length; i++) | |
3629 ret += xs[i] * ys[i]; | |
3630 return ret; | |
3631 } | |
3632 | |
3633 static public long vmax(long[] xs){ | |
3634 if(xs.length == 0) | |
3635 return 0; | |
3636 long ret = xs[0]; | |
3637 for(int i = 0; i < xs.length; i++) | |
3638 ret = Math.max(ret, xs[i]); | |
3639 return ret; | |
3640 } | |
3641 | |
3642 static public long vmin(long[] xs){ | |
3643 if(xs.length == 0) | |
3644 return 0; | |
3645 long ret = xs[0]; | |
3646 for(int i = 0; i < xs.length; i++) | |
3647 ret = Math.min(ret, xs[i]); | |
3648 return ret; | |
3649 } | |
3650 | |
3651 static public double vmean(long[] xs){ | |
3652 if(xs.length == 0) | |
3653 return 0; | |
3654 return vsum(xs) / (double) xs.length; | |
3655 } | |
3656 | |
3657 static public double vrms(long[] xs){ | |
3658 if(xs.length == 0) | |
3659 return 0; | |
3660 long ret = 0; | |
3661 for(int i = 0; i < xs.length; i++) | |
3662 ret += xs[i] * xs[i]; | |
3663 return Math.sqrt(ret / (double) xs.length); | |
3664 } | |
3665 | |
3666 static public long vsum(long[] xs){ | |
3667 long ret = 0; | |
3668 for(int i = 0; i < xs.length; i++) | |
3669 ret += xs[i]; | |
3670 return ret; | |
3671 } | |
3672 | |
3673 static public boolean vequiv(long[] xs, long[] ys){ | |
3674 return Arrays.equals(xs, ys); | |
3675 } | |
3676 | |
3677 static public long[] vadd(long[] x, long[] ys){ | |
3678 final long[] xs = x.clone(); | |
3679 for(int i = 0; i < xs.length; i++) | |
3680 xs[i] += ys[i]; | |
3681 return xs; | |
3682 } | |
3683 | |
3684 static public long[] vsub(long[] x, long[] ys){ | |
3685 final long[] xs = x.clone(); | |
3686 for(int i = 0; i < xs.length; i++) | |
3687 xs[i] -= ys[i]; | |
3688 return xs; | |
3689 } | |
3690 | |
3691 static public long[] vaddmul(long[] x, long[] ys, long[] zs){ | |
3692 final long[] xs = x.clone(); | |
3693 for(int i = 0; i < xs.length; i++) | |
3694 xs[i] = (xs[i] + ys[i]) * zs[i]; | |
3695 return xs; | |
3696 } | |
3697 | |
3698 static public long[] vsubmul(long[] x, long[] ys, long[] zs){ | |
3699 final long[] xs = x.clone(); | |
3700 for(int i = 0; i < xs.length; i++) | |
3701 xs[i] = (xs[i] - ys[i]) * zs[i]; | |
3702 return xs; | |
3703 } | |
3704 | |
3705 static public long[] vaddsmul(long[] x, long[] ys, long z){ | |
3706 final long[] xs = x.clone(); | |
3707 for(int i = 0; i < xs.length; i++) | |
3708 xs[i] = (xs[i] + ys[i]) * z; | |
3709 return xs; | |
3710 } | |
3711 | |
3712 static public long[] vsubsmul(long[] x, long[] ys, long z){ | |
3713 final long[] xs = x.clone(); | |
3714 for(int i = 0; i < xs.length; i++) | |
3715 xs[i] = (xs[i] - ys[i]) * z; | |
3716 return xs; | |
3717 } | |
3718 | |
3719 static public long[] vmulsadd(long[] x, long[] ys, long z){ | |
3720 final long[] xs = x.clone(); | |
3721 for(int i = 0; i < xs.length; i++) | |
3722 xs[i] = (xs[i] * ys[i]) + z; | |
3723 return xs; | |
3724 } | |
3725 | |
3726 static public long[] vdiv(long[] x, long[] ys){ | |
3727 final long[] xs = x.clone(); | |
3728 for(int i = 0; i < xs.length; i++) | |
3729 xs[i] /= ys[i]; | |
3730 return xs; | |
3731 } | |
3732 | |
3733 static public long[] vmul(long[] x, long[] ys){ | |
3734 final long[] xs = x.clone(); | |
3735 for(int i = 0; i < xs.length; i++) | |
3736 xs[i] *= ys[i]; | |
3737 return xs; | |
3738 } | |
3739 | |
3740 static public long[] vmuladd(long[] x, long[] ys, long[] zs){ | |
3741 final long[] xs = x.clone(); | |
3742 for(int i = 0; i < xs.length; i++) | |
3743 xs[i] = (xs[i] * ys[i]) + zs[i]; | |
3744 return xs; | |
3745 } | |
3746 | |
3747 static public long[] vmulsub(long[] x, long[] ys, long[] zs){ | |
3748 final long[] xs = x.clone(); | |
3749 for(int i = 0; i < xs.length; i++) | |
3750 xs[i] = (xs[i] * ys[i]) - zs[i]; | |
3751 return xs; | |
3752 } | |
3753 | |
3754 static public long[] vmax(long[] x, long[] ys){ | |
3755 final long[] xs = x.clone(); | |
3756 for(int i = 0; i < xs.length; i++) | |
3757 xs[i] = Math.max(xs[i], ys[i]); | |
3758 return xs; | |
3759 } | |
3760 | |
3761 static public long[] vmin(long[] x, long[] ys){ | |
3762 final long[] xs = x.clone(); | |
3763 for(int i = 0; i < xs.length; i++) | |
3764 xs[i] = Math.min(xs[i], ys[i]); | |
3765 return xs; | |
3766 } | |
3767 | |
3768 static public long[] vmap(IFn fn, long[] x) throws Exception{ | |
3769 long[] xs = x.clone(); | |
3770 for(int i = 0; i < xs.length; i++) | |
3771 xs[i] = ((Number) fn.invoke(xs[i])).longValue(); | |
3772 return xs; | |
3773 } | |
3774 | |
3775 static public long[] vmap(IFn fn, long[] x, long[] ys) throws Exception{ | |
3776 long[] xs = x.clone(); | |
3777 for(int i = 0; i < xs.length; i++) | |
3778 xs[i] = ((Number) fn.invoke(xs[i], ys[i])).longValue(); | |
3779 return xs; | |
3780 } | |
3781 | |
3782 } | |
3783 */ | |
3784 | |
3785 | |
3786 //overload resolution | |
3787 | |
3788 static public Number add(int x, Object y){ | |
3789 return add((Object)x,y); | |
3790 } | |
3791 | |
3792 static public Number add(Object x, int y){ | |
3793 return add(x,(Object)y); | |
3794 } | |
3795 | |
3796 static public Number and(int x, Object y){ | |
3797 return and((Object)x,y); | |
3798 } | |
3799 | |
3800 static public Number and(Object x, int y){ | |
3801 return and(x,(Object)y); | |
3802 } | |
3803 | |
3804 static public Number or(int x, Object y){ | |
3805 return or((Object)x,y); | |
3806 } | |
3807 | |
3808 static public Number or(Object x, int y){ | |
3809 return or(x,(Object)y); | |
3810 } | |
3811 | |
3812 static public Number xor(int x, Object y){ | |
3813 return xor((Object)x,y); | |
3814 } | |
3815 | |
3816 static public Number xor(Object x, int y){ | |
3817 return xor(x,(Object)y); | |
3818 } | |
3819 | |
3820 static public Number add(float x, Object y){ | |
3821 return add((Object)x,y); | |
3822 } | |
3823 | |
3824 static public Number add(Object x, float y){ | |
3825 return add(x,(Object)y); | |
3826 } | |
3827 | |
3828 static public Number add(long x, Object y){ | |
3829 return add((Object)x,y); | |
3830 } | |
3831 | |
3832 static public Number add(Object x, long y){ | |
3833 return add(x,(Object)y); | |
3834 } | |
3835 | |
3836 static public Number add(double x, Object y){ | |
3837 return add((Object)x,y); | |
3838 } | |
3839 | |
3840 static public Number add(Object x, double y){ | |
3841 return add(x,(Object)y); | |
3842 } | |
3843 | |
3844 static public Number minus(int x, Object y){ | |
3845 return minus((Object)x,y); | |
3846 } | |
3847 | |
3848 static public Number minus(Object x, int y){ | |
3849 return minus(x,(Object)y); | |
3850 } | |
3851 | |
3852 static public Number minus(float x, Object y){ | |
3853 return minus((Object)x,y); | |
3854 } | |
3855 | |
3856 static public Number minus(Object x, float y){ | |
3857 return minus(x,(Object)y); | |
3858 } | |
3859 | |
3860 static public Number minus(long x, Object y){ | |
3861 return minus((Object)x,y); | |
3862 } | |
3863 | |
3864 static public Number minus(Object x, long y){ | |
3865 return minus(x,(Object)y); | |
3866 } | |
3867 | |
3868 static public Number minus(double x, Object y){ | |
3869 return minus((Object)x,y); | |
3870 } | |
3871 | |
3872 static public Number minus(Object x, double y){ | |
3873 return minus(x,(Object)y); | |
3874 } | |
3875 | |
3876 static public Number multiply(int x, Object y){ | |
3877 return multiply((Object)x,y); | |
3878 } | |
3879 | |
3880 static public Number multiply(Object x, int y){ | |
3881 return multiply(x,(Object)y); | |
3882 } | |
3883 | |
3884 static public Number multiply(float x, Object y){ | |
3885 return multiply((Object)x,y); | |
3886 } | |
3887 | |
3888 static public Number multiply(Object x, float y){ | |
3889 return multiply(x,(Object)y); | |
3890 } | |
3891 | |
3892 static public Number multiply(long x, Object y){ | |
3893 return multiply((Object)x,y); | |
3894 } | |
3895 | |
3896 static public Number multiply(Object x, long y){ | |
3897 return multiply(x,(Object)y); | |
3898 } | |
3899 | |
3900 static public Number multiply(double x, Object y){ | |
3901 return multiply((Object)x,y); | |
3902 } | |
3903 | |
3904 static public Number multiply(Object x, double y){ | |
3905 return multiply(x,(Object)y); | |
3906 } | |
3907 | |
3908 static public Number divide(int x, Object y){ | |
3909 return divide((Object)x,y); | |
3910 } | |
3911 | |
3912 static public Number divide(Object x, int y){ | |
3913 return divide(x,(Object)y); | |
3914 } | |
3915 | |
3916 static public Number divide(float x, Object y){ | |
3917 return divide((Object)x,y); | |
3918 } | |
3919 | |
3920 static public Number divide(Object x, float y){ | |
3921 return divide(x,(Object)y); | |
3922 } | |
3923 | |
3924 static public Number divide(long x, Object y){ | |
3925 return divide((Object)x,y); | |
3926 } | |
3927 | |
3928 static public Number divide(Object x, long y){ | |
3929 return divide(x,(Object)y); | |
3930 } | |
3931 | |
3932 static public Number divide(double x, Object y){ | |
3933 return divide((Object)x,y); | |
3934 } | |
3935 | |
3936 static public Number divide(Object x, double y){ | |
3937 return divide(x,(Object)y); | |
3938 } | |
3939 | |
3940 static public boolean lt(int x, Object y){ | |
3941 return lt((Object)x,y); | |
3942 } | |
3943 | |
3944 static public boolean lt(Object x, int y){ | |
3945 return lt(x,(Object)y); | |
3946 } | |
3947 | |
3948 static public boolean lt(float x, Object y){ | |
3949 return lt((Object)x,y); | |
3950 } | |
3951 | |
3952 static public boolean lt(Object x, float y){ | |
3953 return lt(x,(Object)y); | |
3954 } | |
3955 | |
3956 static public boolean lt(long x, Object y){ | |
3957 return lt((Object)x,y); | |
3958 } | |
3959 | |
3960 static public boolean lt(Object x, long y){ | |
3961 return lt(x,(Object)y); | |
3962 } | |
3963 | |
3964 static public boolean lt(double x, Object y){ | |
3965 return lt((Object)x,y); | |
3966 } | |
3967 | |
3968 static public boolean lt(Object x, double y){ | |
3969 return lt(x,(Object)y); | |
3970 } | |
3971 | |
3972 static public boolean lte(int x, Object y){ | |
3973 return lte((Object)x,y); | |
3974 } | |
3975 | |
3976 static public boolean lte(Object x, int y){ | |
3977 return lte(x,(Object)y); | |
3978 } | |
3979 | |
3980 static public boolean lte(float x, Object y){ | |
3981 return lte((Object)x,y); | |
3982 } | |
3983 | |
3984 static public boolean lte(Object x, float y){ | |
3985 return lte(x,(Object)y); | |
3986 } | |
3987 | |
3988 static public boolean lte(long x, Object y){ | |
3989 return lte((Object)x,y); | |
3990 } | |
3991 | |
3992 static public boolean lte(Object x, long y){ | |
3993 return lte(x,(Object)y); | |
3994 } | |
3995 | |
3996 static public boolean lte(double x, Object y){ | |
3997 return lte((Object)x,y); | |
3998 } | |
3999 | |
4000 static public boolean lte(Object x, double y){ | |
4001 return lte(x,(Object)y); | |
4002 } | |
4003 | |
4004 static public boolean gt(int x, Object y){ | |
4005 return gt((Object)x,y); | |
4006 } | |
4007 | |
4008 static public boolean gt(Object x, int y){ | |
4009 return gt(x,(Object)y); | |
4010 } | |
4011 | |
4012 static public boolean gt(float x, Object y){ | |
4013 return gt((Object)x,y); | |
4014 } | |
4015 | |
4016 static public boolean gt(Object x, float y){ | |
4017 return gt(x,(Object)y); | |
4018 } | |
4019 | |
4020 static public boolean gt(long x, Object y){ | |
4021 return gt((Object)x,y); | |
4022 } | |
4023 | |
4024 static public boolean gt(Object x, long y){ | |
4025 return gt(x,(Object)y); | |
4026 } | |
4027 | |
4028 static public boolean gt(double x, Object y){ | |
4029 return gt((Object)x,y); | |
4030 } | |
4031 | |
4032 static public boolean gt(Object x, double y){ | |
4033 return gt(x,(Object)y); | |
4034 } | |
4035 | |
4036 static public boolean gte(int x, Object y){ | |
4037 return gte((Object)x,y); | |
4038 } | |
4039 | |
4040 static public boolean gte(Object x, int y){ | |
4041 return gte(x,(Object)y); | |
4042 } | |
4043 | |
4044 static public boolean gte(float x, Object y){ | |
4045 return gte((Object)x,y); | |
4046 } | |
4047 | |
4048 static public boolean gte(Object x, float y){ | |
4049 return gte(x,(Object)y); | |
4050 } | |
4051 | |
4052 static public boolean gte(long x, Object y){ | |
4053 return gte((Object)x,y); | |
4054 } | |
4055 | |
4056 static public boolean gte(Object x, long y){ | |
4057 return gte(x,(Object)y); | |
4058 } | |
4059 | |
4060 static public boolean gte(double x, Object y){ | |
4061 return gte((Object)x,y); | |
4062 } | |
4063 | |
4064 static public boolean gte(Object x, double y){ | |
4065 return gte(x,(Object)y); | |
4066 } | |
4067 | |
4068 | |
4069 static public boolean equiv(int x, Object y){ | |
4070 return equiv((Object)x,y); | |
4071 } | |
4072 | |
4073 static public boolean equiv(Object x, int y){ | |
4074 return equiv(x,(Object)y); | |
4075 } | |
4076 | |
4077 static public boolean equiv(float x, Object y){ | |
4078 return equiv((Object)x,y); | |
4079 } | |
4080 | |
4081 static public boolean equiv(Object x, float y){ | |
4082 return equiv(x,(Object)y); | |
4083 } | |
4084 | |
4085 static public boolean equiv(long x, Object y){ | |
4086 return equiv((Object)x,y); | |
4087 } | |
4088 | |
4089 static public boolean equiv(Object x, long y){ | |
4090 return equiv(x,(Object)y); | |
4091 } | |
4092 | |
4093 static public boolean equiv(double x, Object y){ | |
4094 return equiv((Object)x,y); | |
4095 } | |
4096 | |
4097 static public boolean equiv(Object x, double y){ | |
4098 return equiv(x,(Object)y); | |
4099 } | |
4100 | |
4101 | |
4102 static public float add(int x, float y){ | |
4103 return add((float)x,y); | |
4104 } | |
4105 | |
4106 static public float add(float x, int y){ | |
4107 return add(x,(float)y); | |
4108 } | |
4109 | |
4110 static public double add(int x, double y){ | |
4111 return add((double)x,y); | |
4112 } | |
4113 | |
4114 static public double add(double x, int y){ | |
4115 return add(x,(double)y); | |
4116 } | |
4117 | |
4118 static public long add(int x, long y){ | |
4119 return add((long)x,y); | |
4120 } | |
4121 | |
4122 static public long add(long x, int y){ | |
4123 return add(x,(long)y); | |
4124 } | |
4125 | |
4126 static public float add(long x, float y){ | |
4127 return add((float)x,y); | |
4128 } | |
4129 | |
4130 static public float add(float x, long y){ | |
4131 return add(x,(float)y); | |
4132 } | |
4133 | |
4134 static public double add(long x, double y){ | |
4135 return add((double)x,y); | |
4136 } | |
4137 | |
4138 static public double add(double x, long y){ | |
4139 return add(x,(double)y); | |
4140 } | |
4141 | |
4142 static public double add(float x, double y){ | |
4143 return add((double)x,y); | |
4144 } | |
4145 | |
4146 static public double add(double x, float y){ | |
4147 return add(x,(double)y); | |
4148 } | |
4149 | |
4150 static public float minus(int x, float y){ | |
4151 return minus((float)x,y); | |
4152 } | |
4153 | |
4154 static public float minus(float x, int y){ | |
4155 return minus(x,(float)y); | |
4156 } | |
4157 | |
4158 static public double minus(int x, double y){ | |
4159 return minus((double)x,y); | |
4160 } | |
4161 | |
4162 static public double minus(double x, int y){ | |
4163 return minus(x,(double)y); | |
4164 } | |
4165 | |
4166 static public long minus(int x, long y){ | |
4167 return minus((long)x,y); | |
4168 } | |
4169 | |
4170 static public long minus(long x, int y){ | |
4171 return minus(x,(long)y); | |
4172 } | |
4173 | |
4174 static public float minus(long x, float y){ | |
4175 return minus((float)x,y); | |
4176 } | |
4177 | |
4178 static public float minus(float x, long y){ | |
4179 return minus(x,(float)y); | |
4180 } | |
4181 | |
4182 static public double minus(long x, double y){ | |
4183 return minus((double)x,y); | |
4184 } | |
4185 | |
4186 static public double minus(double x, long y){ | |
4187 return minus(x,(double)y); | |
4188 } | |
4189 | |
4190 static public double minus(float x, double y){ | |
4191 return minus((double)x,y); | |
4192 } | |
4193 | |
4194 static public double minus(double x, float y){ | |
4195 return minus(x,(double)y); | |
4196 } | |
4197 | |
4198 static public float multiply(int x, float y){ | |
4199 return multiply((float)x,y); | |
4200 } | |
4201 | |
4202 static public float multiply(float x, int y){ | |
4203 return multiply(x,(float)y); | |
4204 } | |
4205 | |
4206 static public double multiply(int x, double y){ | |
4207 return multiply((double)x,y); | |
4208 } | |
4209 | |
4210 static public double multiply(double x, int y){ | |
4211 return multiply(x,(double)y); | |
4212 } | |
4213 | |
4214 static public long multiply(int x, long y){ | |
4215 return multiply((long)x,y); | |
4216 } | |
4217 | |
4218 static public long multiply(long x, int y){ | |
4219 return multiply(x,(long)y); | |
4220 } | |
4221 | |
4222 static public float multiply(long x, float y){ | |
4223 return multiply((float)x,y); | |
4224 } | |
4225 | |
4226 static public float multiply(float x, long y){ | |
4227 return multiply(x,(float)y); | |
4228 } | |
4229 | |
4230 static public double multiply(long x, double y){ | |
4231 return multiply((double)x,y); | |
4232 } | |
4233 | |
4234 static public double multiply(double x, long y){ | |
4235 return multiply(x,(double)y); | |
4236 } | |
4237 | |
4238 static public double multiply(float x, double y){ | |
4239 return multiply((double)x,y); | |
4240 } | |
4241 | |
4242 static public double multiply(double x, float y){ | |
4243 return multiply(x,(double)y); | |
4244 } | |
4245 | |
4246 static public float divide(int x, float y){ | |
4247 return divide((float)x,y); | |
4248 } | |
4249 | |
4250 static public float divide(float x, int y){ | |
4251 return divide(x,(float)y); | |
4252 } | |
4253 | |
4254 static public double divide(int x, double y){ | |
4255 return divide((double)x,y); | |
4256 } | |
4257 | |
4258 static public double divide(double x, int y){ | |
4259 return divide(x,(double)y); | |
4260 } | |
4261 | |
4262 static public float divide(long x, float y){ | |
4263 return divide((float)x,y); | |
4264 } | |
4265 | |
4266 static public float divide(float x, long y){ | |
4267 return divide(x,(float)y); | |
4268 } | |
4269 | |
4270 static public double divide(long x, double y){ | |
4271 return divide((double)x,y); | |
4272 } | |
4273 | |
4274 static public double divide(double x, long y){ | |
4275 return divide(x,(double)y); | |
4276 } | |
4277 | |
4278 static public double divide(float x, double y){ | |
4279 return divide((double)x,y); | |
4280 } | |
4281 | |
4282 static public double divide(double x, float y){ | |
4283 return divide(x,(double)y); | |
4284 } | |
4285 | |
4286 static public boolean lt(int x, float y){ | |
4287 return lt((float)x,y); | |
4288 } | |
4289 | |
4290 static public boolean lt(float x, int y){ | |
4291 return lt(x,(float)y); | |
4292 } | |
4293 | |
4294 static public boolean lt(int x, double y){ | |
4295 return lt((double)x,y); | |
4296 } | |
4297 | |
4298 static public boolean lt(double x, int y){ | |
4299 return lt(x,(double)y); | |
4300 } | |
4301 | |
4302 static public boolean lt(int x, long y){ | |
4303 return lt((long)x,y); | |
4304 } | |
4305 | |
4306 static public boolean lt(long x, int y){ | |
4307 return lt(x,(long)y); | |
4308 } | |
4309 | |
4310 static public boolean lt(long x, float y){ | |
4311 return lt((float)x,y); | |
4312 } | |
4313 | |
4314 static public boolean lt(float x, long y){ | |
4315 return lt(x,(float)y); | |
4316 } | |
4317 | |
4318 static public boolean lt(long x, double y){ | |
4319 return lt((double)x,y); | |
4320 } | |
4321 | |
4322 static public boolean lt(double x, long y){ | |
4323 return lt(x,(double)y); | |
4324 } | |
4325 | |
4326 static public boolean lt(float x, double y){ | |
4327 return lt((double)x,y); | |
4328 } | |
4329 | |
4330 static public boolean lt(double x, float y){ | |
4331 return lt(x,(double)y); | |
4332 } | |
4333 | |
4334 | |
4335 static public boolean lte(int x, float y){ | |
4336 return lte((float)x,y); | |
4337 } | |
4338 | |
4339 static public boolean lte(float x, int y){ | |
4340 return lte(x,(float)y); | |
4341 } | |
4342 | |
4343 static public boolean lte(int x, double y){ | |
4344 return lte((double)x,y); | |
4345 } | |
4346 | |
4347 static public boolean lte(double x, int y){ | |
4348 return lte(x,(double)y); | |
4349 } | |
4350 | |
4351 static public boolean lte(int x, long y){ | |
4352 return lte((long)x,y); | |
4353 } | |
4354 | |
4355 static public boolean lte(long x, int y){ | |
4356 return lte(x,(long)y); | |
4357 } | |
4358 | |
4359 static public boolean lte(long x, float y){ | |
4360 return lte((float)x,y); | |
4361 } | |
4362 | |
4363 static public boolean lte(float x, long y){ | |
4364 return lte(x,(float)y); | |
4365 } | |
4366 | |
4367 static public boolean lte(long x, double y){ | |
4368 return lte((double)x,y); | |
4369 } | |
4370 | |
4371 static public boolean lte(double x, long y){ | |
4372 return lte(x,(double)y); | |
4373 } | |
4374 | |
4375 static public boolean lte(float x, double y){ | |
4376 return lte((double)x,y); | |
4377 } | |
4378 | |
4379 static public boolean lte(double x, float y){ | |
4380 return lte(x,(double)y); | |
4381 } | |
4382 | |
4383 static public boolean gt(int x, float y){ | |
4384 return gt((float)x,y); | |
4385 } | |
4386 | |
4387 static public boolean gt(float x, int y){ | |
4388 return gt(x,(float)y); | |
4389 } | |
4390 | |
4391 static public boolean gt(int x, double y){ | |
4392 return gt((double)x,y); | |
4393 } | |
4394 | |
4395 static public boolean gt(double x, int y){ | |
4396 return gt(x,(double)y); | |
4397 } | |
4398 | |
4399 static public boolean gt(int x, long y){ | |
4400 return gt((long)x,y); | |
4401 } | |
4402 | |
4403 static public boolean gt(long x, int y){ | |
4404 return gt(x,(long)y); | |
4405 } | |
4406 | |
4407 static public boolean gt(long x, float y){ | |
4408 return gt((float)x,y); | |
4409 } | |
4410 | |
4411 static public boolean gt(float x, long y){ | |
4412 return gt(x,(float)y); | |
4413 } | |
4414 | |
4415 static public boolean gt(long x, double y){ | |
4416 return gt((double)x,y); | |
4417 } | |
4418 | |
4419 static public boolean gt(double x, long y){ | |
4420 return gt(x,(double)y); | |
4421 } | |
4422 | |
4423 static public boolean gt(float x, double y){ | |
4424 return gt((double)x,y); | |
4425 } | |
4426 | |
4427 static public boolean gt(double x, float y){ | |
4428 return gt(x,(double)y); | |
4429 } | |
4430 | |
4431 static public boolean gte(int x, float y){ | |
4432 return gte((float)x,y); | |
4433 } | |
4434 | |
4435 static public boolean gte(float x, int y){ | |
4436 return gte(x,(float)y); | |
4437 } | |
4438 | |
4439 static public boolean gte(int x, double y){ | |
4440 return gte((double)x,y); | |
4441 } | |
4442 | |
4443 static public boolean gte(double x, int y){ | |
4444 return gte(x,(double)y); | |
4445 } | |
4446 | |
4447 static public boolean gte(int x, long y){ | |
4448 return gte((long)x,y); | |
4449 } | |
4450 | |
4451 static public boolean gte(long x, int y){ | |
4452 return gte(x,(long)y); | |
4453 } | |
4454 | |
4455 static public boolean gte(long x, float y){ | |
4456 return gte((float)x,y); | |
4457 } | |
4458 | |
4459 static public boolean gte(float x, long y){ | |
4460 return gte(x,(float)y); | |
4461 } | |
4462 | |
4463 static public boolean gte(long x, double y){ | |
4464 return gte((double)x,y); | |
4465 } | |
4466 | |
4467 static public boolean gte(double x, long y){ | |
4468 return gte(x,(double)y); | |
4469 } | |
4470 | |
4471 static public boolean gte(float x, double y){ | |
4472 return gte((double)x,y); | |
4473 } | |
4474 | |
4475 static public boolean gte(double x, float y){ | |
4476 return gte(x,(double)y); | |
4477 } | |
4478 | |
4479 static public boolean equiv(int x, float y){ | |
4480 return equiv((float)x,y); | |
4481 } | |
4482 | |
4483 static public boolean equiv(float x, int y){ | |
4484 return equiv(x,(float)y); | |
4485 } | |
4486 | |
4487 static public boolean equiv(int x, double y){ | |
4488 return equiv((double)x,y); | |
4489 } | |
4490 | |
4491 static public boolean equiv(double x, int y){ | |
4492 return equiv(x,(double)y); | |
4493 } | |
4494 | |
4495 static public boolean equiv(int x, long y){ | |
4496 return equiv((long)x,y); | |
4497 } | |
4498 | |
4499 static public boolean equiv(long x, int y){ | |
4500 return equiv(x,(long)y); | |
4501 } | |
4502 | |
4503 static public boolean equiv(long x, float y){ | |
4504 return equiv((float)x,y); | |
4505 } | |
4506 | |
4507 static public boolean equiv(float x, long y){ | |
4508 return equiv(x,(float)y); | |
4509 } | |
4510 | |
4511 static public boolean equiv(long x, double y){ | |
4512 return equiv((double)x,y); | |
4513 } | |
4514 | |
4515 static public boolean equiv(double x, long y){ | |
4516 return equiv(x,(double)y); | |
4517 } | |
4518 | |
4519 static public boolean equiv(float x, double y){ | |
4520 return equiv((double)x,y); | |
4521 } | |
4522 | |
4523 static public boolean equiv(double x, float y){ | |
4524 return equiv(x,(double)y); | |
4525 } | |
4526 | |
4527 } |