www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Does std.bigint compile under D2.40?

reply Paul D. Anderson <paul.d.removethis.anderson comcast.andthis.net> writes:
I'm close to wrapping up a decimal (bigfloat) module for D (coming soon to
dsource!) and, as you might imagine, it uses std.bigint heavily. 

I upgraded my compiler from D2.30 to D2.40 and got error messages regarding
conflicts between struct constructors and struct initializers. I cleaned up my
code, but when I tried to compile again it complained about struct initializers
in std.bigint.

I'm away from my home computer, so I can't give specifics on the error(s), but
I know bigint is overdue for a rework, and that it has been missing from the
phobos documentation for a long time. My question is whether anyone else is
using std.bigint and has experienced this problem.

For what it's worth, there are several features that I wish were present in
std.bigint, mostly dealing with decimal representation:

1. Return the number of decimal digits are in a given bigint.
2. Return the first or last decimal digits in a bigint.
3. Some sort of decimal shift; divide/multiply by a given power or ten.

For the time being I've implemented these in my Decimal class, but are they of
wider use to anyone else? (Note: I'm sure there are more efficient ways to
implement these functions, and including them in std.bigint may allow these
efficiency gaings.)
Feb 16 2010
next sibling parent reply Don <nospam nospam.com> writes:
Paul D. Anderson wrote:
 I'm close to wrapping up a decimal (bigfloat) module for D (coming soon to
dsource!) and, as you might imagine, it uses std.bigint heavily. 
Cool!
 I upgraded my compiler from D2.30 to D2.40 and got error messages regarding
conflicts between struct constructors and struct initializers. I cleaned up my
code, but when I tried to compile again it complained about struct initializers
in std.bigint.
 
 I'm away from my home computer, so I can't give specifics on the error(s), but
I know bigint is overdue for a rework, and that it has been missing from the
phobos documentation for a long time. My question is whether anyone else is
using std.bigint and has experienced this problem.
I'm planning on replacing std.bigint with an upgraded version of tango.math.bigint. Haven't got around to it yet (distracted by fixing compiler bugs <g>, and anyway the new operator overloading syntax will appear in the next release). You should probably take a look at Tango bigint to get an idea of how it differs from the current std.bigint. Eg, it supports efficient powers.
 For what it's worth, there are several features that I wish were present in
std.bigint, mostly dealing with decimal representation:
 
 1. Return the number of decimal digits are in a given bigint.
 2. Return the first or last decimal digits in a bigint.
 3. Some sort of decimal shift; divide/multiply by a given power or ten.
Feb 16 2010
parent reply Paul D. Anderson <paul.d.removethis.anderson comcast.andthis.net> writes:
Don Wrote:

<snip> and anyway the new operator overloading syntax will 
appear in the next release). </snip>

Can you point me to info on what the new syntax will look like?

Thanks,

Paul
Feb 26 2010
parent reply Don <nospam nospam.com> writes:
Paul D. Anderson wrote:
 Don Wrote:
 
 <snip> and anyway the new operator overloading syntax will 
 appear in the next release). </snip>
 
 Can you point me to info on what the new syntax will look like?
 
 Thanks,
 
 Paul
http://www.dsource.org/projects/phobos/browser/trunk/docsrc/operatoroverloading.dd
Feb 26 2010
next sibling parent Paul D. Anderson <paul.d.removethis.anderson comcast.andthis.net> writes:
Gracias.

Don Wrote:

 Paul D. Anderson wrote:
 Don Wrote:
 
 <snip> and anyway the new operator overloading syntax will 
 appear in the next release). </snip>
 
 Can you point me to info on what the new syntax will look like?
 
 Thanks,
 
 Paul
http://www.dsource.org/projects/phobos/browser/trunk/docsrc/operatoroverloading.dd
Feb 26 2010
prev sibling next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Don:
 http://www.dsource.org/projects/phobos/browser/trunk/docsrc/operatoroverloading.dd
It says: 223 logical negation operator. More obscurely absent is a unary operator 224 to convert to a bool result. ... 234 if (e) => if (e.opCast!(bool)) 235 if (!e) => if (!e.opCast!(bool)) ... 238 $(P etc., whenever a bool result is expected. This only happens, however, for 239 instances of structs. Class references are converted to bool by checking to 240 see if the class reference is null or not. I have asked for this several times, but I didn't know that was accepted :-) So if you change a class into a struct or the opposite, you have to be careful of changing all such points where the boolean value is asked for. What does it happen if this semantics is extended to class instances too? I guess this is an unthinkable change. Bye, bearophile
Feb 26 2010
prev sibling parent reply Paul D. Anderson <paul.d.removethis.anderson comcast.andthis.net> writes:
Don Wrote:

 Paul D. Anderson wrote:
 Don Wrote:
 
 <snip> and anyway the new operator overloading syntax will 
 appear in the next release). </snip>
 
 Can you point me to info on what the new syntax will look like?
 
 Thanks,
 
 Paul
http://www.dsource.org/projects/phobos/browser/trunk/docsrc/operatoroverloading.dd
This was also helpful to me, when I finally found it: http://www.prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP7
Feb 26 2010
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Paul D. Anderson:
 This was also helpful to me, when I finally found it:
http://www.prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP7
That page contains this point:

non-linear operations (*, /, etc), and memory allocation. Expression
optimisation is unimportant, except for efficient handling of temporaries.<
It misses an important use case of bigints: safe integer values that most times are about as small as normal ints/longs, but can become two or more times longer in uncommon situations, for example an unusually large input. This use case asks bigints to be very fast when they can fit in just 30-64 bits (so such number can be put inside the struct that represents the bigint, fully on the stack). In this case expression optimization becomes a little more important. (Python2.x uses such numbers, it shows you can write a large number of programs using just them, if they have that stack optimization for small values). Bye, bearophile
Feb 26 2010
prev sibling parent Don <nospam nospam.com> writes:
Paul D. Anderson wrote:
 Don Wrote:
 
 Paul D. Anderson wrote:
 Don Wrote:

 <snip> and anyway the new operator overloading syntax will 
 appear in the next release). </snip>

 Can you point me to info on what the new syntax will look like?

 Thanks,

 Paul
http://www.dsource.org/projects/phobos/browser/trunk/docsrc/operatoroverloading.dd
This was also helpful to me, when I finally found it: http://www.prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP7
Yes, but it was not accepted.
Feb 26 2010
prev sibling parent Jay Norwood <jayn io.com> writes:
I like this guy's C++ template arbitrary precision code.

http://www.hvks.com/Numerical/arbitrary_precision.html
Feb 24 2010