01: /* BigIntegers.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Fri Sep 19 13:06:48 2003, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2003 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.math;
20:
21: import java.math.BigInteger;
22: import org.zkoss.lang.Objects;
23:
24: /**
25: * BigInteger utilities.
26: *
27: * @author tomyeh
28: */
29: public class BigIntegers {
30: /** Represents 0 in big integer.
31: */
32: public static final BigInteger ZERO = BigInteger.ZERO;
33:
34: /** Converts an integer to a big integer.
35: */
36: public static final BigInteger toBigInteger(int v) {
37: return v == 0 ? ZERO : new BigInteger(Objects.toByteArray(v));
38: }
39:
40: /** Converts a long to a big integer.
41: */
42: public static final BigInteger toBigInteger(long v) {
43: return v == 0 ? ZERO : new BigInteger(Objects.toByteArray(v));
44: }
45:
46: /** Converts a short to a big integer.
47: */
48: public static final BigInteger toBigInteger(short v) {
49: return v == 0 ? ZERO : new BigInteger(Objects.toByteArray(v));
50: }
51:
52: /** Converts a byte to a big integer.
53: */
54: public static final BigInteger toBigInteger(byte v) {
55: return v == 0 ? ZERO : new BigInteger(Objects.toByteArray(v));
56: }
57:
58: /** Converts an integer to a big integer.
59: */
60: public static final BigInteger toBigInteger(Integer v) {
61: return toBigInteger(v.intValue());
62: }
63:
64: /** Converts a long to a big integer.
65: */
66: public static final BigInteger toBigInteger(Long v) {
67: return toBigInteger(v.longValue());
68: }
69:
70: /** Converts a short to a big integer.
71: */
72: public static final BigInteger toBigInteger(Short v) {
73: return toBigInteger(v.shortValue());
74: }
75:
76: /** Converts a byte to a big integer.
77: */
78: public static final BigInteger toBigInteger(Byte v) {
79: return toBigInteger(v.byteValue());
80: }
81: }
|