Java Doc for LargeInteger.java in  » Science » jscience-4.3.1 » org » jscience » mathematics » number » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Science » jscience 4.3.1 » org.jscience.mathematics.number 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.jscience.mathematics.number.LargeInteger

LargeInteger
final public class LargeInteger extends Number (Code)

This class represents an immutable integer number of arbitrary size.

It has the following advantages over the java.math.BigInteger class:

  • Optimized for 64 bits architectures. But still runs significantly faster on 32 bits processors.
  • Real-time compliant for improved performance and predictability (no garbage generated when executing in javolution.context.StackContext StackContext ).
  • Improved algorithms (e.g. Concurrent Karabutsa multiplication in O(nLog3) instead of O(n2).

Note: This class uses ConcurrentContext ConcurrentContext to accelerate calculations on multi-cores systems.


author:
   Jean-Marie Dautelle
version:
   3.3, January 14, 2007
See Also:    * Wikipedia: Arbitrary-precision Arithmetic


Field Summary
final static  TextFormat<LargeInteger>DECIMAL_FORMAT
     Holds the format for large integers (decimal representation by default).
final static  LargeIntegerFIVE
     Holds five.
final static  LargeIntegerLONG_MIN_VALUE
    
final public static  LargeIntegerONE
     The large integer representing the multiplicative identity.
final public static  Configurable<Integer>PRIME_CERTAINTY
     Holds the certainty required when testing for primality (default 100, the probability for a composite to pass the primality test is less than 2-100).
final static  XMLFormat<LargeInteger>XML
     Holds the default XML representation for large integers.
final public static  LargeIntegerZERO
     The large integer representing the additive identity.


Method Summary
public  LargeIntegerabs()
     Returns the absolute value of this large integer.
public  intbitLength()
     Returns the minimal number of bits to represent this large integer in the minimal two's-complement (sign excluded).
public  intcompareTo(LargeInteger that)
     Compares two large integers numerically.
Parameters:
  that - the integer to compare with.
public  intcompareTo(long value)
     Compares this large integer to the specified long value.
Parameters:
  value - the long value to compare with.
public  LargeIntegercopy()
    
public  intdigitLength()
     Returns the minimal number of decimal digits necessary to represent this large integer (sign excluded).
public  LargeIntegerdivide(LargeInteger that)
     Returns this large integer divided by the one specified (integer division).
public  LargeIntegerdivide(int divisor)
     Returns this large integer divided by the specified int divisor.
public  doubledoubleValue()
     Returns the value of this large integer as a double.
public  booleanequals(Object that)
     Compares this large integer against the specified object.
Parameters:
  that - the object to compare with.
public  booleanequals(long value)
     Compares this large integer against the specified long value.
Parameters:
  value - long value to compare with.
public static  Appendableformat(LargeInteger li, int radix, Appendable out)
     Formats the specified large integer in the specified radix and into the specified Appendable argument.
Parameters:
  li - the large integer to format.
Parameters:
  radix - the radix.
Parameters:
  out - the Appendable to append.
public  LargeIntegergcd(LargeInteger that)
     Returns the greatest common divisor of this large integer and the one specified.
Parameters:
  that - the other number to compute the GCD with.
public  intgetLowestSetBit()
     Returns the index of the lowest-order one bit in this large integer or -1 if this.equals(ZERO).
public  LargeIntegergetRemainder()
     Returns the final undivided part after division that is less or of lower degree than the divisor.
public  inthashCode()
     Returns the hash code for this large integer number.
public  LargeIntegerinverseScaled(int precision)
     Returns a scaled approximation of 1 / this.
Parameters:
  precision - the requested precision (reciprocal error being ± 1).
public  booleanisEven()
     Indicates if this large integer is an even number.
public  booleanisLargerThan(LargeInteger that)
     Indicates if this large integer is larger than the one specified in absolute value.
Parameters:
  that - the integer to be compared with.
public  booleanisNegative()
     Indicates if this large integer is less than LargeInteger.ZERO .
public  booleanisOdd()
     Indicates if this large integer is an odd number.
public  booleanisPositive()
     Indicates if this large integer is greater than LargeInteger.ZERO ( LargeInteger.ZERO is not included).
public  booleanisPowerOfTwo()
     Indicates if this number is a power of two (equals to 2 ( LargeInteger.bitLength bitLength() - 1)).
public  booleanisProbablyPrime()
     Indicates if this large integer is probably prime.
public  booleanisZero()
     Indicates if this large integer is equal to LargeInteger.ZERO .
public  longlongValue()
     Returns the low order bits of this large integer as a long.
public  LargeIntegerminus(LargeInteger that)
     Returns the difference between this large integer and the one specified.
Parameters:
  that - the integer to be subtracted.
public  LargeIntegerminus(long value)
     Returns the difference between this large integer and the specified value
Parameters:
  value - the value to be subtracted.
public  LargeIntegermod(LargeInteger m)
     Returns this large integer modulo the specified large integer.
public  LargeIntegermodInverse(LargeInteger m)
     Returns the large integer whose value is (this-1 mod m) .
Parameters:
  m - the modulus.
public  LargeIntegermodPow(LargeInteger exp, LargeInteger m)
     Returns this large integer raised at the specified exponent modulo the specified modulus.
Parameters:
  exp - the exponent.
Parameters:
  m - the modulus.
public  LargeIntegeropposite()
     Returns the opposite of this large integer.
public static  LargeIntegerparse(CharSequence csq, int radix, Cursor cursor)
     Parses the specified character sequence from the specified position as a large integer in the specified radix.
Parameters:
  csq - the character sequence to parse.
Parameters:
  radix - the radix to be used while parsing.
Parameters:
  cursor - the current cursor position (being maintained).
public  LargeIntegerplus(long value)
     Returns the sum of this large integer with the specified long integer (convenience method)
Parameters:
  value - the long integer being added.
public  LargeIntegerplus(LargeInteger that)
     Returns the sum of this large integer with the one specified.
Parameters:
  that - the integer to be added.
public  LargeIntegerremainder(LargeInteger that)
     Returns the remainder of the division of this large integer with the one specified (convenience method equivalent to this.divide(that).getRemainder()).
Parameters:
  that - the value by which this integer is to be divided, and theremainder returned.
public  LargeIntegershiftLeft(int n)
     Returns the value of this large integer after performing a binary shift to left.
public  LargeIntegershiftRight(int n)
     Returns the value of this large integer after performing a binary shift to right with sign extension (-1 >> 1 == -1). The shift distance, n, may be negative, in which case this method performs a LargeInteger.shiftLeft(int) .
Parameters:
  n - the shift distance, in bits.
public  LargeIntegersqrt()
     Returns the integer square root of this integer.
public  LargeIntegertimes(LargeInteger that)
     Returns the product of this large integer with the one specified.
Parameters:
  that - the large integer multiplier.
public  LargeIntegertimes(long multiplier)
     Returns the product of this large integer with the specified long multiplier.
Parameters:
  multiplier - the long multiplier.
public  LargeIntegertimes10pow(int n)
     Returns the value of this large integer after multiplication by a power of ten.
public  LargeIntegertimes2pow(int n)
     Returns the value of this large integer after multiplication by a power of two.
public  inttoByteArray(byte[] bytes, int offset)
     Returns the two's-complement binary representation of this large integer.
public  TexttoText()
     Returns the text representation of this number using the current TextFormat.getInstance(Class) format .
public  TexttoText(int radix)
     Returns the text representation of this number in the specified radix.
Parameters:
  radix - the radix of the representation.
public static  LargeIntegervalueOf(long value)
     Returns the large integer of specified long value.
Parameters:
  value - the long value.
public static  LargeIntegervalueOf(byte[] bytes, int offset, int length)
     Returns the large integer of specified two's-complement binary representation.
public static  LargeIntegervalueOf(CharSequence csq)
     Returns the large integer for the specified character sequence using the current TextFormat.getInstance(Class) format .
Parameters:
  csq - the character sequence to parse.
public static  LargeIntegervalueOf(CharSequence csq, int radix)
     Returns the large integer for the specified character sequence in the specified radix.
Parameters:
  csq - the character sequence to parse.
Parameters:
  radix - the radix of the representation.
public static  LargeIntegervalueOf(java.math.BigInteger bigInteger)
     Returns the large integer corresponding to the specified java.math.BigInteger instance.
Parameters:
  bigInteger - the big integer instance.

Field Detail
DECIMAL_FORMAT
final static TextFormat<LargeInteger> DECIMAL_FORMAT(Code)
Holds the format for large integers (decimal representation by default).
See Also:   LargeInteger.parse(CharSequence,int,TextFormat.Cursor)
See Also:   LargeInteger.format(LargeInteger,int,Appendable)



FIVE
final static LargeInteger FIVE(Code)
Holds five.



LONG_MIN_VALUE
final static LargeInteger LONG_MIN_VALUE(Code)
Holds Long.MIN_VALUE



ONE
final public static LargeInteger ONE(Code)
The large integer representing the multiplicative identity.



PRIME_CERTAINTY
final public static Configurable<Integer> PRIME_CERTAINTY(Code)
Holds the certainty required when testing for primality (default 100, the probability for a composite to pass the primality test is less than 2-100).



XML
final static XMLFormat<LargeInteger> XML(Code)
Holds the default XML representation for large integers. This representation consists of a simple value attribute holding the LargeInteger.toText() textual representation.



ZERO
final public static LargeInteger ZERO(Code)
The large integer representing the additive identity.





Method Detail
abs
public LargeInteger abs()(Code)
Returns the absolute value of this large integer. |this|.



bitLength
public int bitLength()(Code)
Returns the minimal number of bits to represent this large integer in the minimal two's-complement (sign excluded). the length of this integer in bits (sign excluded).



compareTo
public int compareTo(LargeInteger that)(Code)
Compares two large integers numerically.
Parameters:
  that - the integer to compare with. -1, 0 or 1 as this integer is numerically less than, equal to,or greater than that.
throws:
  ClassCastException - that is not a large integer.



compareTo
public int compareTo(long value)(Code)
Compares this large integer to the specified long value.
Parameters:
  value - the long value to compare with. -1, 0 or 1 as this integer is numerically less than, equal to,or greater than the specified value.



copy
public LargeInteger copy()(Code)



digitLength
public int digitLength()(Code)
Returns the minimal number of decimal digits necessary to represent this large integer (sign excluded). the maximum number of digits.



divide
public LargeInteger divide(LargeInteger that)(Code)
Returns this large integer divided by the one specified (integer division). The remainder of this division is accessible using LargeInteger.getRemainder .
Parameters:
  that - the integer divisor. this / that and this % that (LargeInteger.getRemainder)
throws:
  ArithmeticException - if that.equals(ZERO)



divide
public LargeInteger divide(int divisor)(Code)
Returns this large integer divided by the specified int divisor. The remainder of this division is accessible using LargeInteger.getRemainder .
Parameters:
  divisor - the int divisor. this / divisor and this % divisor(LargeInteger.getRemainder)
throws:
  ArithmeticException - if divisor == 0



doubleValue
public double doubleValue()(Code)
Returns the value of this large integer as a double. the numeric value represented by this integer after conversionto type double.



equals
public boolean equals(Object that)(Code)
Compares this large integer against the specified object.
Parameters:
  that - the object to compare with. true if the objects are the same; falseotherwise.



equals
public boolean equals(long value)(Code)
Compares this large integer against the specified long value.
Parameters:
  value - long value to compare with. true if this large integer has the specified value;false otherwise.



format
public static Appendable format(LargeInteger li, int radix, Appendable out) throws IOException(Code)
Formats the specified large integer in the specified radix and into the specified Appendable argument.
Parameters:
  li - the large integer to format.
Parameters:
  radix - the radix.
Parameters:
  out - the Appendable to append. the specified Appendable object.
throws:
  IllegalArgumentException - if radix is not in [2 .. 36] range.
throws:
  IOException - if an I/O exception occurs.



gcd
public LargeInteger gcd(LargeInteger that)(Code)
Returns the greatest common divisor of this large integer and the one specified.
Parameters:
  that - the other number to compute the GCD with. a positive number or LargeInteger.ZERO if(this.isZero() && that.isZero()).



getLowestSetBit
public int getLowestSetBit()(Code)
Returns the index of the lowest-order one bit in this large integer or -1 if this.equals(ZERO). the index of the rightmost bit set or -1



getRemainder
public LargeInteger getRemainder()(Code)
Returns the final undivided part after division that is less or of lower degree than the divisor. This value is only set by the LargeInteger.divide operation and is not considered as part of this large integer (ignored by all methods). the remainder of the division for which this large integeris the quotient.



hashCode
public int hashCode()(Code)
Returns the hash code for this large integer number. the hash code value.



inverseScaled
public LargeInteger inverseScaled(int precision)(Code)
Returns a scaled approximation of 1 / this.
Parameters:
  precision - the requested precision (reciprocal error being ± 1). 2(precision + this.bitLength()) / this
throws:
  ArithmeticException - if this.isZero()



isEven
public boolean isEven()(Code)
Indicates if this large integer is an even number. (this & 1) == ZERO



isLargerThan
public boolean isLargerThan(LargeInteger that)(Code)
Indicates if this large integer is larger than the one specified in absolute value.
Parameters:
  that - the integer to be compared with. this.abs().compareTo(that.abs()) > 0.



isNegative
public boolean isNegative()(Code)
Indicates if this large integer is less than LargeInteger.ZERO . this < ZERO



isOdd
public boolean isOdd()(Code)
Indicates if this large integer is an odd number. (this & 1) != ZERO



isPositive
public boolean isPositive()(Code)
Indicates if this large integer is greater than LargeInteger.ZERO ( LargeInteger.ZERO is not included). this > ZERO



isPowerOfTwo
public boolean isPowerOfTwo()(Code)
Indicates if this number is a power of two (equals to 2 ( LargeInteger.bitLength bitLength() - 1)). true if this number is a power of two; false otherwise.



isProbablyPrime
public boolean isProbablyPrime()(Code)
Indicates if this large integer is probably prime. true if this large integer is probable prime;false otherwise.



isZero
public boolean isZero()(Code)
Indicates if this large integer is equal to LargeInteger.ZERO . this == ZERO



longValue
public long longValue()(Code)
Returns the low order bits of this large integer as a long.

Note: This conversion can lose information about the overall magnitude of the integer value and may return a result with the opposite sign.

the numeric value represented by this integer after conversionto type long.



minus
public LargeInteger minus(LargeInteger that)(Code)
Returns the difference between this large integer and the one specified.
Parameters:
  that - the integer to be subtracted. this - that.



minus
public LargeInteger minus(long value)(Code)
Returns the difference between this large integer and the specified value
Parameters:
  value - the value to be subtracted. this - value.



mod
public LargeInteger mod(LargeInteger m)(Code)
Returns this large integer modulo the specified large integer.

Note: The result as the same sign as the divisor unlike the Java remainder (%) operator (which as the same sign as the dividend).


Parameters:
  m - the modulus. this mod m
See Also:   LargeInteger.getRemainder()



modInverse
public LargeInteger modInverse(LargeInteger m)(Code)
Returns the large integer whose value is (this-1 mod m) .
Parameters:
  m - the modulus. this-1 mod m.
throws:
  ArithmeticException - m <= 0, or this integerhas no multiplicative inverse mod m (that is, this integeris not relatively prime to m).



modPow
public LargeInteger modPow(LargeInteger exp, LargeInteger m)(Code)
Returns this large integer raised at the specified exponent modulo the specified modulus.
Parameters:
  exp - the exponent.
Parameters:
  m - the modulus. thisexp mod m
throws:
  ArithmeticException - m <= 0
See Also:   LargeInteger.modInverse



opposite
public LargeInteger opposite()(Code)
Returns the opposite of this large integer. -this.



parse
public static LargeInteger parse(CharSequence csq, int radix, Cursor cursor)(Code)
Parses the specified character sequence from the specified position as a large integer in the specified radix.
Parameters:
  csq - the character sequence to parse.
Parameters:
  radix - the radix to be used while parsing.
Parameters:
  cursor - the current cursor position (being maintained). the corresponding large integer.
throws:
  NumberFormatException - if error when parsing.



plus
public LargeInteger plus(long value)(Code)
Returns the sum of this large integer with the specified long integer (convenience method)
Parameters:
  value - the long integer being added. this + value.



plus
public LargeInteger plus(LargeInteger that)(Code)
Returns the sum of this large integer with the one specified.
Parameters:
  that - the integer to be added. this + that.



remainder
public LargeInteger remainder(LargeInteger that)(Code)
Returns the remainder of the division of this large integer with the one specified (convenience method equivalent to this.divide(that).getRemainder()).
Parameters:
  that - the value by which this integer is to be divided, and theremainder returned. this % that
throws:
  ArithmeticException - if that.equals(ZERO)
See Also:   LargeInteger.divide(LargeInteger)



shiftLeft
public LargeInteger shiftLeft(int n)(Code)
Returns the value of this large integer after performing a binary shift to left. The shift distance, n, may be negative, in which case this method performs a right shift.
Parameters:
  n - the shift distance, in bits. this << n.
See Also:   LargeInteger.shiftRight



shiftRight
public LargeInteger shiftRight(int n)(Code)
Returns the value of this large integer after performing a binary shift to right with sign extension (-1 >> 1 == -1). The shift distance, n, may be negative, in which case this method performs a LargeInteger.shiftLeft(int) .
Parameters:
  n - the shift distance, in bits. this >> n.



sqrt
public LargeInteger sqrt()(Code)
Returns the integer square root of this integer. k such as k^2 <= this < (k + 1)^2
throws:
  ArithmeticException - if this integer is negative.



times
public LargeInteger times(LargeInteger that)(Code)
Returns the product of this large integer with the one specified.
Parameters:
  that - the large integer multiplier. this · that.



times
public LargeInteger times(long multiplier)(Code)
Returns the product of this large integer with the specified long multiplier.
Parameters:
  multiplier - the long multiplier. this · multiplier.



times10pow
public LargeInteger times10pow(int n)(Code)
Returns the value of this large integer after multiplication by a power of ten. For example:[code] LargeInteger billion = LargeInteger.ONE.times10pow(9); // 1E9 LargeInteger million = billion.times10pow(-3);[/code]
Parameters:
  n - the decimal exponent. this · 10n



times2pow
public LargeInteger times2pow(int n)(Code)
Returns the value of this large integer after multiplication by a power of two. This method is equivalent to LargeInteger.shiftLeft(int) for positive n; but is different from LargeInteger.shiftRight(int) for negative n as no sign extension is performed (-1 >>> 1 == 0).
Parameters:
  n - the power of 2 exponent. this · 2n.



toByteArray
public int toByteArray(byte[] bytes, int offset)(Code)
Returns the two's-complement binary representation of this large integer. The output array is in big-endian byte-order: the most significant byte is at the offset position.
Parameters:
  bytes - the bytes to hold the binary representation (two's-complement) of this large integer.
Parameters:
  offset - the offset at which to start writing the bytes. the number of bytes written.
throws:
  IndexOutOfBoundsException - if bytes.length < (bitLength() >> 3) + 1
See Also:   LargeInteger.valueOf(byte[],int,int)
See Also:   LargeInteger.bitLength



toText
public Text toText()(Code)
Returns the text representation of this number using the current TextFormat.getInstance(Class) format . TextFormat.getInstance(LargeInteger.class).format(this)



toText
public Text toText(int radix)(Code)
Returns the text representation of this number in the specified radix.
Parameters:
  radix - the radix of the representation. the text representation of this number in the specified radix.



valueOf
public static LargeInteger valueOf(long value)(Code)
Returns the large integer of specified long value.
Parameters:
  value - the long value. the corresponding large integer number.



valueOf
public static LargeInteger valueOf(byte[] bytes, int offset, int length)(Code)
Returns the large integer of specified two's-complement binary representation. The input array is assumed to be in big-endian byte-order: the most significant byte is at the offset position.
Parameters:
  bytes - the binary representation (two's-complement).
Parameters:
  offset - the offset at which to start reading the bytes.
Parameters:
  length - the maximum number of bytes to read. the corresponding large integer number.
throws:
  IndexOutOfBoundsException - if offset + length > bytes.length
See Also:   LargeInteger.toByteArray



valueOf
public static LargeInteger valueOf(CharSequence csq)(Code)
Returns the large integer for the specified character sequence using the current TextFormat.getInstance(Class) format .
Parameters:
  csq - the character sequence to parse. TextFormat.getInstance(LargeInteger.class).parse(csq)
throws:
  NumberFormatException - if error when parsing.



valueOf
public static LargeInteger valueOf(CharSequence csq, int radix)(Code)
Returns the large integer for the specified character sequence in the specified radix.
Parameters:
  csq - the character sequence to parse.
Parameters:
  radix - the radix of the representation. LargeInteger.parse(csq, radix, cursor)
throws:
  NumberFormatException - if error when parsing.



valueOf
public static LargeInteger valueOf(java.math.BigInteger bigInteger)(Code)
Returns the large integer corresponding to the specified java.math.BigInteger instance.
Parameters:
  bigInteger - the big integer instance. the large integer having the same value.



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.