Re: Arbitrary precision decimal numbers

2022-08-10 Thread Tejas via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 14:11:04 UTC, Ruby The Roobster wrote: On Saturday, 6 August 2022 at 13:20:19 UTC, Sergey wrote: On Thursday, 4 August 2022 at 13:01:30 UTC, Ruby The Roobster wrote: Is there any implementation in phobos of something similar to BigInt but for non-integers as well

Re: Cast converts AA to rvalue?

2022-08-10 Thread ag0aep6g via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 17:14:08 UTC, Johan wrote: ``` void f() { aa[1] = 1; // error } shared static this() { f(); } ``` I had considered it, but discarded it... `f` is also a template in our code. Your remark made me check again, and the call chain is short, perhaps I'll conv

Re: My programs issues

2022-08-10 Thread pascal111 via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 14:45:05 UTC, Andrey Zherikov wrote: On Wednesday, 10 August 2022 at 14:08:59 UTC, pascal111 wrote: This version has modern features, it's 1) functional 2) goto-less. There is nothing modern ;-D Take a look in this linear programming and you will know what's

Re: Cast converts AA to rvalue?

2022-08-10 Thread Johan via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 09:52:10 UTC, ag0aep6g wrote: On 10.08.22 10:20, Johan wrote: ``` shared immutable int[int] aa; void main () {     // (cast()aa)[1] = 1; // works without immutable     (*cast(int[int]*)(&aa))[1] = 1; } ``` We have shared static constructors for that: shared s

Re: Array Wierdness

2022-08-10 Thread Ruby The Roobster via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 15:50:45 UTC, Steven Schveighoffer wrote: On 8/10/22 11:26 AM, Ruby The Roobster wrote: [SNIP] A related bug: https://issues.dlang.org/show_bug.cgi?id=23140 -Steve Funnily enough, I came across this when trying to fix that same bug.

Re: Array Wierdness

2022-08-10 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/10/22 11:26 AM, Ruby The Roobster wrote: On Wednesday, 10 August 2022 at 15:19:41 UTC, Ruby The Roobster wrote: Take the following code: ```d void main() {     shared class C { bool opEquals(const(shared(C)) rhs) const shared { return true;}}     const(C) c = new C();     const(C)[] a =

Re: Array Wierdness

2022-08-10 Thread Ruby The Roobster via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 15:19:41 UTC, Ruby The Roobster wrote: Take the following code: ```d void main() { shared class C { bool opEquals(const(shared(C)) rhs) const shared { return true;}} const(C) c = new C(); const(C)[] a = [c]; const(C)[] b = [c]; assert(a[0] =

Array Wierdness

2022-08-10 Thread Ruby The Roobster via Digitalmars-d-learn
Take the following code: ```d void main() { shared class C { bool opEquals(const(shared(C)) rhs) const shared { return true;}} const(C) c = new C(); const(C)[] a = [c]; const(C)[] b = [c]; assert(a[0] == b[0]); } ``` This code (supposedly) checks whether ```a``` and ```b``

Re: My programs issues

2022-08-10 Thread Andrey Zherikov via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 14:08:59 UTC, pascal111 wrote: This version has modern features, it's 1) functional 2) goto-less. There is nothing modern ;-D

Re: Arbitrary precision decimal numbers

2022-08-10 Thread Ruby The Roobster via Digitalmars-d-learn
On Saturday, 6 August 2022 at 13:20:19 UTC, Sergey wrote: On Thursday, 4 August 2022 at 13:01:30 UTC, Ruby The Roobster wrote: Is there any implementation in phobos of something similar to BigInt but for non-integers as well? If there isn't is there a dub package that does this, and if so, whi

Re: My programs issues

2022-08-10 Thread pascal111 via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 14:03:53 UTC, Andrey Zherikov wrote: On Wednesday, 10 August 2022 at 13:34:53 UTC, pascal111 wrote: So, the program will be like this: Is this clearer? ```d import std.stdio; import std.algorithm; import std.range; double getNumber() { double x; writ

Re: My programs issues

2022-08-10 Thread Andrey Zherikov via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 13:34:53 UTC, pascal111 wrote: So, the program will be like this: Is this clearer? ```d import std.stdio; import std.algorithm; import std.range; double getNumber() { double x; write("Enter a number: "); readf(" %s\n", &x); writeln; retur

Re: My programs issues

2022-08-10 Thread pascal111 via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 13:22:03 UTC, rikki cattermole wrote: On 11/08/2022 12:36 AM, pascal111 wrote: 2) I used "goto", I heard from someone before that using "goto" isn't good programming feature. This is mostly a historical debate at this point. Back 40 years ago, goto wasn't typi

Re: My programs issues

2022-08-10 Thread pascal111 via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 13:13:20 UTC, Adam D Ruppe wrote: On Wednesday, 10 August 2022 at 12:36:42 UTC, pascal111 wrote: 1) I used "exit()" from "core.stdc.stdlib;" module, but someone can say this isn't the D way to exit the program. It is better to simply return a value from main ins

Re: My programs issues

2022-08-10 Thread rikki cattermole via Digitalmars-d-learn
On 11/08/2022 12:36 AM, pascal111 wrote: 2) I used "goto", I heard from someone before that using "goto" isn't good programming feature. This is mostly a historical debate at this point. Back 40 years ago, goto wasn't typically limited within a procedure and doesn't have any checks in place

Re: My programs issues

2022-08-10 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 12:36:42 UTC, pascal111 wrote: 1) I used "exit()" from "core.stdc.stdlib;" module, but someone can say this isn't the D way to exit the program. It is better to simply return a value from main instead. 2) I used "goto", I heard from someone before that using "go

My programs issues

2022-08-10 Thread pascal111 via Digitalmars-d-learn
In next program 1) I used "exit()" from "core.stdc.stdlib;" module, but someone can say this isn't the D way to exit the program. 2) I used "goto", I heard from someone before that using "goto" isn't good programming feature. '''D module proj07; import std.stdio; import std.algorithm; impo

Re: Cast converts AA to rvalue?

2022-08-10 Thread ag0aep6g via Digitalmars-d-learn
On 10.08.22 10:20, Johan wrote: ``` shared immutable int[int] aa; void main () {     // (cast()aa)[1] = 1; // works without immutable     (*cast(int[int]*)(&aa))[1] = 1; } ``` We have shared static constructors for that: shared static this() { aa[1] = 1; /* no cast needed */ }

Re: Fix template parameter

2022-08-10 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 06:15:39 UTC, Dom Disc wrote: Ok, then I consider this is a bug in Phobos that should be corrected. All instances of ```D foo(T : fixedType)(T x) { } ``` should be replaced by ```D foo(fixedType x) { } ``` Perhaps, but not necessarily. The body of foo could d

Re: Cast converts AA to rvalue?

2022-08-10 Thread Johan via Digitalmars-d-learn
On Wednesday, 10 August 2022 at 00:28:53 UTC, Steven Schveighoffer wrote: On 8/9/22 7:02 PM, Johan wrote: Testcase: ``` shared int[int] aa; void main () {     cast()aa[1] = 1; } ``` If you use `cast()(aa[1]) = 1`, it has a range error even on older versions. That it ever worked is puzzling.