Re: ubyte + ubyte = int

2022-10-26 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 27 October 2022 at 01:57:15 UTC, Salih Dincer wrote: You should help the compiler with return type: I love D, enjoys it when I code...:) I played a little on the code, and the following is possible and beautiful: ```d // If you type auto instead of ubyte as return type, the re

Re: ubyte + ubyte = int

2022-10-26 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 26 October 2022 at 21:10:54 UTC, 0xEAB wrote: I know this is advanced stuff, but the compiler *could* even prove that the calculation(s) won’t go beyond `ubyte.max`. ```d //... => char? return (decimal - ubyte(10) + ubyte('A')); return '\xFF'; } ``` You should help t

Re: Importing modules under DUB on Windows

2022-10-26 Thread Hipreme via Digitalmars-d-learn
On Wednesday, 26 October 2022 at 22:51:53 UTC, DLearner wrote: On Wednesday, 26 October 2022 at 18:53:58 UTC, Hipreme wrote: On Wednesday, 26 October 2022 at 18:37:00 UTC, DLearner wrote: On Wednesday, 26 October 2022 at 16:58:08 UTC, H. S. Teoh wrote: On Wed, Oct 26, 2022 at 04:20:01PM +,

Re: Importing modules under DUB on Windows

2022-10-26 Thread DLearner via Digitalmars-d-learn
On Wednesday, 26 October 2022 at 18:53:58 UTC, Hipreme wrote: On Wednesday, 26 October 2022 at 18:37:00 UTC, DLearner wrote: On Wednesday, 26 October 2022 at 16:58:08 UTC, H. S. Teoh wrote: On Wed, Oct 26, 2022 at 04:20:01PM +, DLearner via Digitalmars-d-learn wrote: [...] Maybe try inst

Re: ubyte + ubyte = int

2022-10-26 Thread Ali Çehreli via Digitalmars-d-learn
On 10/26/22 14:19, Ali Çehreli wrote: >https://dlang.org/spec/type.html#integer-promotions Reading "Value Range Propagation" further down that link, I learned that e.g. masking 'decimal' with 0xf makes the code compile: return ((decimal & 0xf) + ubyte('0')); return ((deci

Re: ubyte + ubyte = int

2022-10-26 Thread Ali Çehreli via Digitalmars-d-learn
On 10/26/22 14:10, 0xEAB wrote: > I guess, this fancy behavior is inherited from C. Yes. It is called integer promotions: https://dlang.org/spec/type.html#integer-promotions (The next section is related as well.) > I know this is advanced stuff, but the compiler *could* even prove that > th

ubyte + ubyte = int

2022-10-26 Thread 0xEAB via Digitalmars-d-learn
```d @safe: void main() { import std.stdio : writeln; writeln(ubyte(4).toHexDigit); } ubyte toHexDigit(ubyte decimal) pure nothrow @nogc { if (decimal < 10) return (decimal + ubyte('0')); if (decimal < 16) return (decimal - ubyte(10) + ubyte('A')); return '\

Re: library to solve the system of linear equations

2022-10-26 Thread Yura via Digitalmars-d-learn
The workaround is to compile without --release mode, but using the "O3" ldc flag instead does the job - the binary is fast, yet the try - catch block executes properly. On Wednesday, 26 October 2022 at 20:13:37 UTC, Yura wrote: OK, got the problem solved by adding the following lines in my dub

Re: library to solve the system of linear equations

2022-10-26 Thread Yura via Digitalmars-d-learn
OK, got the problem solved by adding the following lines in my dub.sdl file: lflags "-lopenblas" "-lgfortran" dflags "--static" However, one problem still remains. Apparently, when compiled with dub --release mode I got segfault in my try - catch block. Any solution to this? On Wednesday,

Re: Importing modules under DUB on Windows

2022-10-26 Thread Hipreme via Digitalmars-d-learn
On Wednesday, 26 October 2022 at 18:37:00 UTC, DLearner wrote: On Wednesday, 26 October 2022 at 16:58:08 UTC, H. S. Teoh wrote: On Wed, Oct 26, 2022 at 04:20:01PM +, DLearner via Digitalmars-d-learn wrote: Hi Never used DUB before. Wanted to use a function stored in a module outside the ma

Re: Importing modules under DUB on Windows

2022-10-26 Thread DLearner via Digitalmars-d-learn
On Wednesday, 26 October 2022 at 16:58:08 UTC, H. S. Teoh wrote: On Wed, Oct 26, 2022 at 04:20:01PM +, DLearner via Digitalmars-d-learn wrote: Hi Never used DUB before. Wanted to use a function stored in a module outside the main source. Main source has `import ;` Put a line into the JS

Re: Importing modules under DUB on Windows

2022-10-26 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Oct 26, 2022 at 04:20:01PM +, DLearner via Digitalmars-d-learn wrote: > Hi > > Never used DUB before. > Wanted to use a function stored in a module outside the main source. > > Main source has `import ;` > > Put a line into the JSON: `"importPaths": "C:\\Users\\..."` pointing > to t

Re: Hipreme's #2 Tip of the day - Reducing .di files dependency

2022-10-26 Thread Hipreme via Digitalmars-d-learn
On Tuesday, 25 October 2022 at 12:29:50 UTC, Andrey Zherikov wrote: On Sunday, 23 October 2022 at 20:12:46 UTC, Hipreme wrote: This will greatly reduce the number of import and dependencies you need if you ever need to distribute a library. Could you elaborate more on the benefit? Does it redu

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-26 Thread Kagamin via Digitalmars-d-learn
Looks like explicitly initialized variable in this case allocates array literal. Uninitialized variable is initialized with init pattern. This may be correct as uninitialized variable isn't guaranteed to hold a value most useful for you, it's only guaranteed to hold a defined value.

Re: library to solve the system of linear equations

2022-10-26 Thread Yura via Digitalmars-d-learn
I am now trying to compile the code statically using the dub manager via the following command line: dub build --force --build=release --compiler=path_to_ldc2/ldc2 and having these lines in my dub.sdl file: dependency "mir" version="~>3.2.3" dependency "lubeck" version="~>1.5.1" dflags "-stati

Re: Is "auto t=T();" not the same as "T t;"?

2022-10-26 Thread Andrey Zherikov via Digitalmars-d-learn
On Wednesday, 26 October 2022 at 04:40:17 UTC, Salih Dincer wrote: On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov wrote: Does the second piece of code shows a bug or my expectation is not correct (and why if so)? As a result, if this is a bug, Andrey has the right to report it.