[Issue 7013] Mutable interface for BigInts

2022-12-17 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=7013

Iain Buclaw  changed:

   What|Removed |Added

   Priority|P2  |P4

--


[Issue 7013] Mutable interface for BigInts

2013-07-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=7013



--- Comment #5 from bearophile_h...@eml.cc 2013-07-09 10:24:39 PDT ---
(In reply to comment #4)
> You're right, I looked at the code for BigInt, every time you do +=, it
> allocates a new underlying buffer. That's pretty inefficient if you're using
> these operations in an inner loop.

On the other hand I think a mutable integer is not what most people expect, and
it can cause some undesired side effects (and bugs).

That's why I suggested to introduce a specific syntax that allows you to manage
bigints as mutable buffers where max performance is needed, and keep their
behavour clean on default. Generally I think it's better to perform tricky
optimizations only on explicit request.

Some possible alternative syntaxes:

x.mutable += y;
x.mulAcc(y);
x.mutate!"+"(y);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 7013] Mutable interface for BigInts

2013-07-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=7013



--- Comment #3 from bearophile_h...@eml.cc 2013-07-09 09:58:59 PDT ---
(In reply to comment #2)

> When you perform x+=y; the data inside x probably doesn't change.

I meant the original x.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 7013] Mutable interface for BigInts

2013-07-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=7013



--- Comment #4 from hst...@quickfur.ath.cx 2013-07-09 10:07:34 PDT ---
You're right, I looked at the code for BigInt, every time you do +=, it
allocates a new underlying buffer. That's pretty inefficient if you're using
these operations in an inner loop.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 7013] Mutable interface for BigInts

2013-07-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=7013



--- Comment #2 from bearophile_h...@eml.cc 2013-07-09 09:57:35 PDT ---
(In reply to comment #1)
> In latest git HEAD, the following works:
> 
> import std.bigint;
> void main() {
> BigInt x = 123;
> BigInt y = 321;
> x += y;
> assert(x == 444);
> }
> 
> Not sure what's happening under the hood, though. Is it making internal
> allocations?

That code works, but it's not about what this enhancement request is about.
When you perform x+=y; the data inside x probably doesn't change.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 7013] Mutable interface for BigInts

2013-07-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=7013


hst...@quickfur.ath.cx changed:

   What|Removed |Added

 CC||hst...@quickfur.ath.cx


--- Comment #1 from hst...@quickfur.ath.cx 2013-07-09 08:59:04 PDT ---
In latest git HEAD, the following works:

import std.bigint;
void main() {
BigInt x = 123;
BigInt y = 321;
x += y;
assert(x == 444);
}

Not sure what's happening under the hood, though. Is it making internal
allocations?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---