On Thursday, 28 October 2021 at 21:23:15 UTC, kyle wrote:
```
void main()
{
import std.math : abs, sgn;
alias n_type = short; //or int, long, byte, whatever
assert(n_type.min == abs(n_type.min));
assert(sgn(abs(n_type.min)) == -1);
}
```
I stumbled into this fun today. I
On Friday, 29 October 2021 at 08:05:35 UTC, Dom DiSc wrote:
On Thursday, 28 October 2021 at 21:26:04 UTC, kyle wrote:
Okay I checked the phobos docs and it does say "Limitations
Does not work correctly for signed intergal types and value
Num.min." Should have looked there first, I know. Still
On Sat, Oct 30, 2021 at 07:56:35PM -0700, Ali Çehreli via Digitalmars-d-learn
wrote:
> On 10/30/21 3:47 PM, Elronnd wrote:
>
> > If the GC were moving, it would also have to move the pointers you
> > took to AA elements.
>
> I doubt D's GC can ever change pointer values because the values may
>
On Sunday, 31 October 2021 at 10:12:49 UTC, Siarhei Siamashka
wrote:
On Sunday, 31 October 2021 at 05:04:33 UTC, Dom DiSc wrote:
On Friday, 29 October 2021 at 14:20:09 UTC, Ali Çehreli wrote:
[...]
This should be no surprise. You need to know what the
resulting type of int + uint should be.
```d
auto foo(int value, auto s = Section(2, 60)) {
int max; /* ^--- ?
...*/
return Section (0, max)
}
```
Is possible something like above pointed. OK, I know it isn't
because I tried! Well, wouldn't it be nice if it did?
Why shouldn't the inference be
On Sunday, 31 October 2021 at 05:04:33 UTC, Dom DiSc wrote:
On Friday, 29 October 2021 at 14:20:09 UTC, Ali Çehreli wrote:
Unsigned!T abs(T)(const(T) x) if(isIntegral!T)
{
static if(isSigned!T) if(x < 0) return cast(Unsigned!T)-x;
return x;
}
void main() {
int a = -5;
int b = -4;
On 10/31/21 9:49 AM, H. S. Teoh wrote:
> The current spec explicitly states that masking pointers this way is UB.
Ok. :) What about unions?
union U {
ulong u;
void* p;
}
Can the GC deal with that?
Or other smart ways where I store the pointer in two parts as
page+offset? (Perhaps that's
Hi! I'm C learner and found the high similarity between C and D,
and was converting C code into D but couldn't get the equivalent
of this C statement "srand(time(NULL));".
On 10/30/21 10:04 PM, Dom DiSc wrote:
> On Friday, 29 October 2021 at 14:20:09 UTC, Ali Çehreli wrote:
>> Unsigned!T abs(T)(const(T) x) if(isIntegral!T)
>> {
>>static if(isSigned!T) if(x < 0) return cast(Unsigned!T)-x;
>>return x;
>> }
>>
>> void main() {
>> int a = -5;
>> int b = -4;
On Sunday, 31 October 2021 at 05:04:33 UTC, Dom DiSc wrote:
This should be no surprise. You need to know what the resulting
type of int + uint should be. And it is .. uint! which is
one of the stupit integer-promotion rules inherited from C.
In C++ it is undefined behaviour to take the
On Sunday, 31 October 2021 at 10:32:50 UTC, Imperatorn wrote:
What I would like is for it to mirror math.
Use bigints.
On Sunday, 31 October 2021 at 17:02:00 UTC, Ali Çehreli wrote:
On 10/31/21 9:54 AM, pascal111 wrote:
Hi! I'm C learner and found the high similarity between C and
D, and was converting C code into D
Welcome! :) In case it makes to your use cases, check out
-betterC as well:
On Sunday, 31 October 2021 at 18:51:09 UTC, user1234 wrote:
To me it is the right answer. Maybe that OP wanted the
TemplateType parameter to be implicitly added (and that's why
Ali interpreted the question as a language proposal)?
Ah, I see. Interesting proposal.
On 10/31/21 9:54 AM, pascal111 wrote:
Hi! I'm C learner and found the high similarity between C and D, and was
converting C code into D
Welcome! :) In case it makes to your use cases, check out -betterC as well:
https://dlang.org/spec/betterc.html
> but couldn't get the equivalent of this
On Sun, Oct 31, 2021 at 09:54:23AM -0700, Ali Çehreli via Digitalmars-d-learn
wrote:
> On 10/31/21 9:49 AM, H. S. Teoh wrote:
>
> > The current spec explicitly states that masking pointers this way is UB.
>
> Ok. :) What about unions?
>
> union U {
> ulong u;
> void* p;
> }
>
> Can the GC
On 10/31/21 7:07 AM, Salih Dincer wrote:
> ```d
> auto foo(int value, auto s = Section(2, 60)) {
> int max; /* ^--- ?
> ...*/
> return Section (0, max)
> }
> ```
> Is possible something like above pointed. OK, I know it isn't because I
> tried! Well, wouldn't
On Sunday, 31 October 2021 at 17:35:35 UTC, Ali Çehreli wrote:
On 10/31/21 7:07 AM, Salih Dincer wrote:
> ```d
> auto foo(int value, auto s = Section(2, 60)) {
> int max; /* ^--- ?
> ...*/
> return Section (0, max)
> }
> ```
> Is possible something like above
On 10/31/21 9:54 AM, Ali Çehreli wrote:
Or other smart ways where I store the pointer in two parts as
page+offset?
Ok, that was silly. There would be no reference to the GC memory if I
chopped off a pointer. :/
Ali
On Sunday, 31 October 2021 at 16:54:35 UTC, pascal111 wrote:
Hi! I'm C learner and found the high similarity between C and
D, and was converting C code into D but couldn't get the
equivalent of this C statement "srand(time(NULL));".
Since D gives you access to the C standard library, you can
On Sunday, 31 October 2021 at 17:51:45 UTC, data pulverizer wrote:
On Sunday, 31 October 2021 at 17:35:35 UTC, Ali Çehreli wrote:
On 10/31/21 7:07 AM, Salih Dincer wrote:
> [...]
because I
> [...]
Makes sense because e.g. the following works:
struct S {
auto i = 42;
}
I bet the problem
On Sunday, 31 October 2021 at 17:35:35 UTC, Ali Çehreli wrote:
On 10/31/21 7:07 AM, Salih Dincer wrote:
> ```d
> auto foo(int value, auto s = Section(2, 60)) {
> int max; /* ^--- ?
> ...*/
> return Section (0, max)
> }
> ```
> Is possible something like above
21 matches
Mail list logo