Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #1609 (new enhancement)

Opened 15 years ago

Last modified 14 years ago

Add methods to BigInt

Reported by: keinfarbton Assigned to: Don Clugston
Priority: major Milestone: 1.0
Component: Tango Version: 0.99.8 Sean
Keywords: Cc:

Description

Add those methods that are present in java.math.BigInteger?

Change History

04/21/09 07:04:21 changed by Don Clugston

It is indeed intended that BigInt? should gain more functionality. It's very limited right now; the most obvious missing feature is formatting, which makes it rather useless at present. Please make a list of the desired methods, together with a link to the most appropriate documentation.

(Most of my time is taken up with getting the basics of D2 math working. I'll return to BigInt? when that's done).

04/22/09 13:52:01 changed by keinfarbton

From http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html

this(long);
long longValue();
int bitLength();
BigInt pow(int exponent);
bool testBit(int n);
bool setBit(int n);
bool clearBit(int n);
bool flipBit(int n);
bool testBit(int n);

06/27/09 14:30:56 changed by JarrettBillingsley

Reverse overloads of the appropriate operators (all but Add and Mul) are needed. (i.e. 6 - bigint is currently an error)

Also, would it be possible to get bitwise operators (and, or, xor) as well?

06/30/09 08:41:28 changed by Don Clugston

You're right about the reverse overloads. I don't think bitwise operators make sense on signed BigInts?. Built-in types use 2's-complement, but BigInt? doesn't. You can define the operations to pretend that it does, but is it actually a good idea? (Actually, I'm not sure that logical operators make sense even on built-in signed types!) What are the use cases?

Note that you can say: uint [] x, uint [] y; x[] = x[] y[]; so the functionality is already in the language. So the question may be, does BigUint? need to be exposed? (I hope not).

07/16/09 10:23:09 changed by Don Clugston

I've now added pow() which was by far the most difficult of the requested methods. toLong() and opCall(long) are also in place, as is uintLength and ulongLength.

Not sure about bitLength, since in theory it can exceed size_t! I guess in practice, it can't. But, since BigInt? uses copy-on-write, those bit operations would be unbelievable inefficient. They can't be done with that interface.

What do you think is the better interface: BigInt? x = BigInt?(70); BigInt? y = BigInt?.pow(x, 80);

OR

BigInt? x = BigInt?(70); BigInt? y = x; y.pow(80);

02/01/10 20:15:20 changed by Don Clugston

  • milestone changed from 0.99.9 to 1.0.