[Issue 11188] std.math.abs fails for shared, const or immutable BigInt types

2013-10-10 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=11188



--- Comment #2 from Joseph Rushton Wakeling  
2013-10-10 11:23:53 PDT ---
(In reply to comment #1)
> Does std.math.abs even work for anything other than built-in types currently? 
> I
> know it should, but I'm skeptical if it does.

It works for regular BigInt, it's just when you qualify that with shared, const
or immutable that it fails.

> In any case, it should take inout arguments since it doesn't (and shouldn't)
> modify them. So this (in theory) should work:
> 
> inout(Num) abs(Num)(inout(Num) x) if ( ... ) {
> return (x >= 0) ? x : -x;
> }

I'll give that a go and if it works, send a patch to Phobos.  Thanks for the
thought.  Incidentally, shouldn't "in" be sufficient there for the input?

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


[Issue 11188] std.math.abs fails for shared, const or immutable BigInt types

2013-10-10 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=11188


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

   What|Removed |Added

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


--- Comment #1 from hst...@quickfur.ath.cx 2013-10-10 11:20:06 PDT ---
Does std.math.abs even work for anything other than built-in types currently? I
know it should, but I'm skeptical if it does.

In any case, it should take inout arguments since it doesn't (and shouldn't)
modify them. So this (in theory) should work:

inout(Num) abs(Num)(inout(Num) x) if ( ... ) {
return (x >= 0) ? x : -x;
}

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


[Issue 11188] std.math.abs fails for shared, const or immutable BigInt types

2013-10-10 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=11188



--- Comment #3 from hst...@quickfur.ath.cx 2013-10-10 11:36:03 PDT ---
(In reply to comment #2)
> I'll give that a go and if it works, send a patch to Phobos.  Thanks for the
> thought.  Incidentally, shouldn't "in" be sufficient there for the input?

In this case, you need inout, because you want to propagate the incoming
qualifiers to the output: if x>=0, then you're returning x again, so the return
type needs to carry whatever qualifiers x had on entering the function.
Everything implicitly converts to const, of course, but it would suck if you
returned const and the caller passed in unqual, and now after calling abs he
can't modify the BigInt anymore!

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


[Issue 11188] std.math.abs fails for shared, const or immutable BigInt types

2013-10-10 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=11188



--- Comment #4 from Joseph Rushton Wakeling  
2013-10-10 11:47:51 PDT ---
Tweaking std.math.abs to accept an inout input results in the following error
when I added a regular BigInt to the unittests:

assert(abs(BigInt(-234567)) == 234567);

---
std/math.d(311): Error: function std.bigint.BigInt.opCmp (ref const(BigInt) y)
const is not callable using argument types (int) inout
std/math.d(311): Error: mutable method std.bigint.BigInt.opUnary!"-".opUnary is
not callable using a inout object
std/math.d(341): Error: template instance std.math.abs!(BigInt) error
instantiating
---

So I'd guess in turn std.bigint.BigInt.opCmp (and other BigInt methods) ought
to require (or at least have available) inout input.

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


[Issue 11188] std.math.abs fails for shared, const or immutable BigInt types

2013-10-10 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=11188



--- Comment #5 from Joseph Rushton Wakeling  
2013-10-10 17:33:40 PDT ---
(In reply to comment #3)
> In this case, you need inout, because you want to propagate the incoming
> qualifiers to the output: if x>=0, then you're returning x again, so the 
> return
> type needs to carry whatever qualifiers x had on entering the function.
> Everything implicitly converts to const, of course, but it would suck if you
> returned const and the caller passed in unqual, and now after calling abs he
> can't modify the BigInt anymore!

I wasn't talking about returning const, but about the _input_ to the function.

I'm not actually certain you do always want to propagate the qualifiers to the
output -- I may want to be able to do:

immutable BigInt x = -345678;
BigInt xAbs = abs(x);

... or is inout sensitive to things like this?  In any case, bear in mind that
abs doesn't always guaranteed to return the same type -- if you give it (say) a
cfloat or an ifloat, it'll return a real.

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


[Issue 11188] std.math.abs fails for shared, const or immutable BigInt types

2013-11-01 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=11188


Simen Kjaeraas  changed:

   What|Removed |Added

   Keywords||pull
 CC||simen.kja...@gmail.com


--- Comment #6 from Simen Kjaeraas  2013-11-01 18:35:01 
PDT ---
https://github.com/D-Programming-Language/phobos/pull/1679

This pull solves some of the problems in this issue. Shared is more
complicated, so will have to wait.

It may be that the problems of shared are better fixed elsewhere - pure
functions on a type that's implicitly castable to immutable seem like they
should be callable with shared parameters, but I might be wrong.

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


[Issue 11188] std.math.abs fails for shared, const or immutable BigInt types

2013-11-02 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=11188



--- Comment #7 from Joseph Rushton Wakeling  
2013-11-02 04:55:32 PDT ---
(In reply to comment #6)
> This pull solves some of the problems in this issue. Shared is more
> complicated, so will have to wait.

Thanks very much Simen -- there are some aspects of your fix that I would not
have thought of myself, but now that I've seen them, they are obvious things to
watch out for, so I really appreciate not only the solution but also the
insight gained thereby :-)

I agree that shared is a bigger issue than just BigInt and any fix for it needs
to wait for shared itself to be properly sorted out.  See also:
https://github.com/D-Programming-Language/phobos/pull/1616#issuecomment-25865836

... for earlier discussion.

I'll give your code a test and see how it plays with std.rational, which was
the original project from which awareness of this issue arose.

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


[Issue 11188] std.math.abs fails for shared, const or immutable BigInt types

2013-11-03 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=11188



--- Comment #8 from Simen Kjaeraas  2013-11-03 13:25:17 
PST ---
Adding this overload to std.math is a workaround for the problems with shared:

Num abs(Num)(shared Num x) @safe pure nothrow 
if (is(typeof(abs(Num.init))) && is(typeof({Num n = x;})))
{
Num tmp = x;
return abs(tmp);
}


However, given that shared is currently rather ill-specified, and possibly will
change dramatically relatively soon (let's hope so), and that this is a
workaround for a single function only, I feel it's better to leave the
workaround out for the time being, and wait for a real solution.

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


[Issue 11188] std.math.abs fails for shared, const or immutable BigInt types

2013-11-18 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=11188


bearophile_h...@eml.cc changed:

   What|Removed |Added

 CC||bearophile_h...@eml.cc


--- Comment #9 from bearophile_h...@eml.cc 2013-11-18 02:49:23 PST ---
Seems fixed or partially fixed:
https://github.com/D-Programming-Language/phobos/compare/cc52695e4a15...9a93d82e9924

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