Re: Problem with object understanding and datatypes

2013-06-23 Thread Nordlöw
Is this code available in any repo/archive somewhere? /Per

Re: Problem with object understanding and datatypes

2013-05-25 Thread Namal
Thank you very much, I thought the operators are alrdy checked by if (op == + || op == - || op == /) But I did same tests for ushort uint and ulong, but for ulong it didn't compile. unittest{ alias sulong = Saturated!ulong; assert(sulong(18_446_744_073_709_551_610) + sulong(2) ==

Re: Problem with object understanding and datatypes

2013-05-25 Thread bearophile
Namal: And if so, do I always have to use a suffix when the number is bigger than uint? It looks a bit silly, I agree. Bye, bearophile

Re: Problem with object understanding and datatypes

2013-05-25 Thread Namal
On Saturday, 25 May 2013 at 10:15:42 UTC, bearophile wrote: Namal: And if so, do I always have to use a suffix when the number is bigger than uint? It looks a bit silly, I agree. Bye, bearophile Well, now I have same Error for signed long: else{ static if (op == +){

Re: Problem with object understanding and datatypes

2013-05-25 Thread Ali Çehreli
On 05/25/2013 04:34 AM, Namal wrote: assert(slong(9_223_372_036_854_775_806) + slong(-3) == slong(-9_223_372_036_854_775_808)); } The first test is ok, but second wont even compile. Even if I append a L to each number. According to the Integer Literals section here:

Re: Problem with object understanding and datatypes

2013-05-25 Thread Namal
Thanks, that helped me alot.

Re: Problem with object understanding and datatypes

2013-05-25 Thread Namal
I have one more question towards using unsigned datatype assert(sint(-2_147_483_647) - sint(3) == sint(-2_147_483_648)); assert(sint(-2_147_483_647) - sint(3) == sint(2_147_483_648)); Here I get an error for the second line, because it cannot be convertet if i use unsigned

Re: Problem with object understanding and datatypes

2013-05-25 Thread Ali Çehreli
On 05/25/2013 11:57 AM, Namal wrote: I have one more question towards using unsigned datatype assert(sint(-2_147_483_647) - sint(3) == sint(-2_147_483_648)); assert(sint(-2_147_483_647) - sint(3) == sint(2_147_483_648)); Here I get an error for the second line, because it cannot be

Problem with object understanding and datatypes

2013-05-24 Thread Namal
So the task is to write a struct object for the saturation arithmetic. I tried first to write it for the unsigned Types: struct Saturated(T) if (isIntegral!T) { static assert (isUnsigned!T || isSigned!T); @property { static Saturated min() {

Re: Problem with object understanding and datatypes

2013-05-24 Thread Ali Çehreli
On 05/24/2013 01:19 PM, Namal wrote: if(rhs.max - rhs._value _value) I had a compilation error so I had to change that line to the following: if(T.max - rhs._value _value){ assert(subyte(128) - subyte(129) == subyte(0)); } But the last test does not pass.

Re: Problem with object understanding and datatypes

2013-05-24 Thread Namal
255 - 129 is less than 128 so the result is T.max, which is 255, which is not equal to 0. I dont understand this at all 255 - 129 should be 126 in ubyte or not?

Re: Problem with object understanding and datatypes

2013-05-24 Thread Juan Manuel Cabo
On Saturday, 25 May 2013 at 01:03:53 UTC, Namal wrote: 255 - 129 is less than 128 so the result is T.max, which is 255, which is not equal to 0. I dont understand this at all 255 - 129 should be 126 in ubyte or not? I checked, and operation between two ubyte is an int. When you cast