View mode: basic / threaded / horizontal-split · Log in · Help
February 16, 2010
Does std.bigint compile under D2.40?
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.)
February 16, 2010
Re: Does std.bigint compile under D2.40?
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.
February 25, 2010
Re: Does std.bigint compile under D2.40?
I like this guy's C++ template arbitrary precision code.

http://www.hvks.com/Numerical/arbitrary_precision.html
February 26, 2010
New operator overloading syntax. Was: Does std.bigint compile under D2.40?
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
February 26, 2010
Re: New operator overloading syntax. Was: Does std.bigint compile under D2.40?
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
February 26, 2010
Re: New operator overloading syntax. Was: Does std.bigint compile
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
February 26, 2010
Re: New operator overloading syntax. Was: Does std.bigint compile
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
February 26, 2010
Re: New operator overloading syntax. Was: Does std.bigint compile
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
February 26, 2010
Re: New operator overloading syntax. Was: Does std.bigint compile
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:

>Use case # 2: BigInt?, BigFloat?, etc: Time is dominated by two things: 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
February 27, 2010
Re: New operator overloading syntax. Was: Does std.bigint compile
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.
Top | Discussion index | About this forum | D home