digitalmars.D.learn - bigint
- Ellery Newcomer (11/11) Nov 26 2010 why does the following code fail?
- bearophile (8/9) Nov 27 2010 Reduced case for bugzilla:
- bearophile (1/2) Nov 27 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5281
- Matthias Walter (12/16) Nov 28 2010 I investigated into the bug and the reason is the signature of opEquals,
why does the following code fail? import std.bigint; void main(){ BigInt b1 = 1; BigInt b2 = 3; BigInt e1 = 1; BigInt e2 = 3; BigInt[] b = [b1,b2]; BigInt[] e = [e1,e2]; assert(b == e); }
Nov 26 2010
Ellery Newcomer:why does the following code fail?Reduced case for bugzilla: import std.bigint; void main() { assert([BigInt(1)] == [BigInt(1)]); } Bye, bearophile
Nov 27 2010
Reduced case for bugzilla:http://d.puremagic.com/issues/show_bug.cgi?id=5281
Nov 27 2010
On 11/27/2010 02:05 PM, bearophile wrote:I investigated into the bug and the reason is the signature of opEquals, which currently is bool opEquals(Tdummy=void)(ref const BigInt y) const bool opEquals(T: int)(T y) const The only working sigature for array-of-structs-comparison to work is bool opEquals(ref const BigInt y) const But this removes the ability to compare against ints. (btw, it should probably be long in the 2nd signature?!) array-comparison should definitely take templated opEquals functions into account, or is there something mentioned in the spec? MatthiasReduced case for bugzilla:http://d.puremagic.com/issues/show_bug.cgi?id=5281
Nov 28 2010
Matthias Walter Wrote:bool opEquals(Tdummy=void)(ref const BigInt y) const bool opEquals(T: int)(T y) const The only working sigature for array-of-structs-comparison to work is bool opEquals(ref const BigInt y) const But this removes the ability to compare against ints.Why are they templated to begin with? Just for the heck of it? bool opEquals(ref const BigInt y) const bool opEquals(long y) const
Nov 28 2010
Kagamin wrote:Matthias Walter Wrote:No, because then it fails for ulong. It's those bloody C implicit conversions.bool opEquals(Tdummy=void)(ref const BigInt y) const bool opEquals(T: int)(T y) const The only working sigature for array-of-structs-comparison to work is bool opEquals(ref const BigInt y) const But this removes the ability to compare against ints.Why are they templated to begin with? Just for the heck of it? bool opEquals(ref const BigInt y) const bool opEquals(long y) const
Nov 28 2010
Don Wrote:hmm... works for me: --- struct A { bool opEquals(ref const A y) const { return false; } bool opEquals(long y) const { return true; } } int main() { A a; ulong b=42; assert(a==b); return 0; } ---Why are they templated to begin with? Just for the heck of it? bool opEquals(ref const BigInt y) const bool opEquals(long y) constNo, because then it fails for ulong. It's those bloody C implicit conversions.
Nov 29 2010
Kagamin wrote:Don Wrote:Yes, but the code is incorrect if b is larger than long.max. The problem is that values in the range long.max+1..ulong.max get turned into values in the range -1 .. -long.max-1 How can you distinguish them?hmm... works for me: --- struct A { bool opEquals(ref const A y) const { return false; } bool opEquals(long y) const { return true; } } int main() { A a; ulong b=42; assert(a==b); return 0; } ---Why are they templated to begin with? Just for the heck of it? bool opEquals(ref const BigInt y) const bool opEquals(long y) constNo, because then it fails for ulong. It's those bloody C implicit conversions.
Nov 29 2010