Re: Divisibility of a java.math.BigInteger object



On 9 Jul 2008 14:15:50 GMT, ram@xxxxxxxxxxxxxxxxxx (Stefan Ram) wrote:

Calculating the remainder of a java.math.BigInteger object
seems to be slow. For a number > 100, it would be sufficient
and possibly faster to just extract the two least significant
digits and compare them with »00«. But I can not directly
access the internal representation of a java.math.BigInteger
object. Does anyone see a possibility to accelerate such a
divisibility test for a java.math.BigInteger object using the
same tricks one uses when testing this by mental arithmetic?
How fast is BigInteger.mod() compared with BigInteger.remainder()?
What about BigInteger.divideAndRemainder()?

To access the internal representation of a BigInteger use
BigInteger.toByteArray() or for the least significant bits use
BigInteger.longValue() and similar. Use toString() for the
represenataion in decimal digits, though I suspect that will be too
slow for your purposes.

rossum

.



Relevant Pages

  • Re: Two results of set geometry
    ... digits of pi and a subsequent 5 cannot be distinguished from pi as ... cannot compare it to pi because pi then does not and cannot exist. ... given enough time and stability of the representation and having ... Everything that exists, exists in physics, is limited by physics ...
    (sci.math)
  • Re: Reading specific memory address into variable
    ... I need to compare two numeric variables to ... If you could get to the mantissa and exponent of the number you're ... except it will be in binary significant digits (which can be ... converted to decimal significant digits by division by log10. ...
    (comp.lang.cpp)
  • Re: Relative Cardinality
    ... > 90 additional digits are required to reach position 10^100. ... The number of digits needed to compare two magnitudes depends only on ... No one knows how much can be stored in the whole universe since no one ...
    (sci.math)
  • Re: Internal representation of a TimeStamp
    ... Scaliger numbers (or "Julian Days") are the number of days since Jan. 1, ... I've been told that a timestamp-declared field, although 26 digits ... has a different internal representation that makes it a lot ... timestamps audit fields, and I'm quite sure he'll be worried about the ...
    (comp.sys.ibm.as400.misc)
  • Re: does a program work in all cases?
    ... necessarily true on all platforms. ... any internal representation the compiler desires. ... standard promises is that it will *compare* equal to 0. ...
    (comp.lang.c)