Re: Printing floating point numbers

2019-10-24 Thread berni44 via Digitalmars-d-learn
On Thursday, 24 October 2019 at 20:48:02 UTC, Yui Hosaka wrote: Do you have any idea for this issue? I added a bug report: https://issues.dlang.org/show_bug.cgi?id=20320 Internally the conversation from the binary representation of the value to the printed one is done by a call to a C funct

Can not understand this code.

2019-10-24 Thread lili via Digitalmars-d-learn
Hi: What is the alias Min = xxx mean? why need defined a alias Min in Min template? ``` template Min(alias pred, Args...) if (Args.length > 0 && __traits(isTemplate, pred)) { static if (Args.length == 1) { alias Min = Alias!(Args[0]); } else static if (isLess!(pred, Args[

Re: About the in expression, Why can't use with array.

2019-10-24 Thread Ali Çehreli via Digitalmars-d-learn
On 10/24/2019 05:58 AM, lili wrote: > Hi: > In Dlang where is strange design. The in expression can only use to > associative array, why array can not use in expression. In addition to the big O surprise, there is another important issue that may be seen as either for or against supporting t

Re: About the in expression, Why can't use with array.

2019-10-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, October 24, 2019 8:40:59 PM MDT lili via Digitalmars-d-learn wrote: > On Thursday, 24 October 2019 at 22:40:31 UTC, Jonathan M Davis > > wrote: > > On Thursday, October 24, 2019 7:04:56 AM MDT Paul Backus via > > > > Digitalmars-d- learn wrote: > >> On Thursday, 24 October 2019 at 12:

Re: About the in expression, Why can't use with array.

2019-10-24 Thread lili via Digitalmars-d-learn
On Thursday, 24 October 2019 at 22:40:31 UTC, Jonathan M Davis wrote: On Thursday, October 24, 2019 7:04:56 AM MDT Paul Backus via Digitalmars-d- learn wrote: On Thursday, 24 October 2019 at 12:58:11 UTC, lili wrote: > Hi: >In Dlang where is strange design. The in expression can > only > >

Re: About the in expression, Why can't use with array.

2019-10-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, October 24, 2019 7:04:56 AM MDT Paul Backus via Digitalmars-d- learn wrote: > On Thursday, 24 October 2019 at 12:58:11 UTC, lili wrote: > > Hi: > >In Dlang where is strange design. The in expression can only > > > > use to associative array, why array can not use in expression. > >

Re: Eliding of slice range checking

2019-10-24 Thread Per Nordlöw via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 14:52:42 UTC, kinke wrote: godbolt.org supports D as well and is way more powerful than run.dlang.io, besides offering way more LDC versions to choose from. It can also be used to remove the 'cluttering': https://d.godbolt.org/z/ejEmrK Very useful. Especially

Re: Eliding of slice range checking

2019-10-24 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 24 October 2019 at 18:37:05 UTC, welkam wrote: I remember in some video Chandler Carruth said that value range propagation across function boundary was implemented in llvm but later removed because it produced no performance improvement for C and C++ code. I wonder how it fare when

Re: Printing floating point numbers

2019-10-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 24 October 2019 at 20:48:02 UTC, Yui Hosaka wrote: Do you have any idea for this issue? my suspicion would be that .016 is actually represented as .015 and the .2 round ignores all those 9's...

Printing floating point numbers

2019-10-24 Thread Yui Hosaka via Digitalmars-d-learn
The following code prints weird results on my machine. import std.stdio; void main() { real a = 0.16; real b = 0.016; writefln("%.1f", a); writefln("%.2f", b); } Output: --- 0.2 0.01 I am using dmd on Windows. It doesn't happen when compiling with -m32. $ dmd DMD32

Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-24 Thread Ali Çehreli via Digitalmars-d-learn
On 10/24/2019 10:57 AM, Robert M. Münch wrote: > Unfortunately, member function template instances are never virtual > functions, so you can't override them." > > Is there a reason why these type of functions are not virtual or can't > be made virtual? One practical reason is, the number of thei

Re: Eliding of slice range checking

2019-10-24 Thread welkam via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 11:20:59 UTC, Per Nordlöw wrote: Does DMD/LDC avoid range-checking in slice-expressions such as the one in my array-overload of `startsWith` defined as bool startsWith(T)(scope const(T)[] haystack, scope const(T)[] needle) { if (haystack.l

Re: Remove unwanted ' \r ' from an Array ... by reading a *.txt file.

2019-10-24 Thread welkam via Digitalmars-d-learn
On Thursday, 24 October 2019 at 16:49:09 UTC, Mil58 wrote: On Thursday, 24 October 2019 at 16:21:47 UTC, welkam wrote: On Thursday, 24 October 2019 at 15:27:05 UTC, Mil58 wrote: [...] void main() { File("data.txt", "r+") .byLineCopy() .array() .each!writeln; } byL

Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-24 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-10-23 17:22:38 +, Ali ‡ehreli said: On 10/23/2019 02:43 AM, Robert M. Münch wrote: >> Unfortunately, member function template instances are never virtual >> functions, so you can't override them. > > What I don't understand is: > > 1. The RX lib has a member function template

Re: Good way let low-skill people edit CSV files with predefined row names?

2019-10-24 Thread jmh530 via Digitalmars-d-learn
On Thursday, 24 October 2019 at 17:41:21 UTC, Dukc wrote: This was wrong: Atila's Excel-d enables writing plugin functions, but not reading the spreadsheets. There are other DUB utilities for that, though. I quess I will give my employer two options: Either the price variables are in an on

Re: Good way let low-skill people edit CSV files with predefined row names?

2019-10-24 Thread Dukc via Digitalmars-d-learn
On Thursday, 24 October 2019 at 16:50:17 UTC, Dukc wrote: Hmm, I need to check whether I can do that on LibreOffice Calc. Unfortunately, no. If there's a way to do that, it's not obvious. I should be able to make an easy-to-use excel-to-csv translator using Atilas Excel utilites without too

Re: Remove unwanted ' \r ' from an Array ... by reading a *.txt file.

2019-10-24 Thread Ali Çehreli via Digitalmars-d-learn
On 10/24/2019 10:21 AM, Ali Çehreli wrote:   auto lines = File(fileName, "r").byLineCopy(No.keepTerminator, '\r');   auto result = lines.joiner("-").text; I would normally do the following auto lines = File(fileName, "r").byLineCopy(No.keepTerminator, '\r'); auto result = format!"%-(%s-%

Re: [DTrace probe] is there a [portable] way to add section to elf executable?

2019-10-24 Thread welkam via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 15:24:13 UTC, drug wrote: I'd like to add (and modify) section to ELF executable to implement DTrace probes. DTrace does it in probe assembly: ``` __asm__ __volatile__ ( "990: nop .pushsection .note.stapsdt,\"?\",\"note\" .balign 4

Re: Remove unwanted ' \r ' from an Array ... by reading a *.txt file.

2019-10-24 Thread Ali Çehreli via Digitalmars-d-learn
On 10/24/2019 09:49 AM, Mil58 wrote: On Thursday, 24 October 2019 at 16:21:47 UTC, welkam wrote: On Thursday, 24 October 2019 at 15:27:05 UTC, Mil58 wrote: [...] void main() {     File("data.txt", "r+")     .byLineCopy()     .array()     .each!writeln; } byLineCopy removes the ne

Re: dub build doesn't work

2019-10-24 Thread welkam via Digitalmars-d-learn
On Thursday, 24 October 2019 at 01:17:24 UTC, OiseuKodeur wrote: BTW if you prefer using optlink and the digitalmars C runtime, you can instruct dub to do so with: --arch=x86 how can i add --arch=x86 flag to the dub.json so it do it automatically ? "dflags": [ "--arch=x86" ] Th

Re: Converting a ulong to a byte array and constructing a ulong from it

2019-10-24 Thread welkam via Digitalmars-d-learn
On Thursday, 24 October 2019 at 14:08:36 UTC, 9898287 wrote: Does this contain any undefined behavior? It is in C as far as I knew. immutable int number = 1; auto bad_idea = (cast(ubyte*) &number)[0 .. number.sizeof]; bad_idea[0] = 2; writeln(number); //1 writeln(*(cast(int*)bad_idea.ptr)); //2

Re: Good way let low-skill people edit CSV files with predefined row names?

2019-10-24 Thread Dukc via Digitalmars-d-learn
On Thursday, 24 October 2019 at 16:20:50 UTC, jmh530 wrote: If they are only opening it in Excel, then you can lock cells. You should be able to do that with VBA. At least I know it works with xlsx files. Not sure on csv now that I think on it. Hmm, I need to check whether I can do that on L

Re: Remove unwanted ' \r ' from an Array ... by reading a *.txt file.

2019-10-24 Thread Mil58 via Digitalmars-d-learn
On Thursday, 24 October 2019 at 16:21:47 UTC, welkam wrote: On Thursday, 24 October 2019 at 15:27:05 UTC, Mil58 wrote: [...] void main() { File("data.txt", "r+") .byLineCopy() .array() .each!writeln; } byLineCopy removes the new lines. If in the future you would n

Re: Good way let low-skill people edit CSV files with predefined row names?

2019-10-24 Thread jmh530 via Digitalmars-d-learn
On Thursday, 24 October 2019 at 16:20:20 UTC, jmh530 wrote: On Thursday, 24 October 2019 at 16:03:26 UTC, Dukc wrote: [snip] If they are only opening it in Excel, then you can lock cells. You should be able to do that with VBA. At least I know it works with xlsx files. Not sure on csv now

Re: Good way let low-skill people edit CSV files with predefined row names?

2019-10-24 Thread jmh530 via Digitalmars-d-learn
On Thursday, 24 October 2019 at 16:03:26 UTC, Dukc wrote: [snip] If they are only opening it in Excel, then you can lock cells. You should be able to do that with VBA.

Re: Remove unwanted ' \r ' from an Array ... by reading a *.txt file.

2019-10-24 Thread welkam via Digitalmars-d-learn
On Thursday, 24 October 2019 at 15:27:05 UTC, Mil58 wrote: Hi all It's me again ;-) (because you're very strong in Dlang, here...) In want a result as i write in a comment, with remove unwanted '\r' >> import std.stdio; import std.file; import std.conv; import std.process : executeShell; /* C

Good way let low-skill people edit CSV files with predefined row names?

2019-10-24 Thread Dukc via Digitalmars-d-learn
We're planning to have our product preview program to calculate and suggest a price for the product displayed. There are a lot of variables to take into account, so it's essential the users can edit the price variables themselves. The problem is that many of them are not the best computer user

Re: Good way let low-skill people edit CSV files with predefined row names?

2019-10-24 Thread Dukc via Digitalmars-d-learn
On Thursday, 24 October 2019 at 16:03:26 UTC, Dukc wrote: Even if it isn't CSV, it is going to be easier for me to write a translator than a GUI editor. Assuming the file format is simple, of course

Remove unwanted ' \r ' from an Array ... by reading a *.txt file.

2019-10-24 Thread Mil58 via Digitalmars-d-learn
Hi all It's me again ;-) (because you're very strong in Dlang, here...) In want a result as i write in a comment, with remove unwanted '\r' >> import std.stdio; import std.file; import std.conv; import std.process : executeShell; /* Content of 'values.txt' >> abcd 1234 03b52h */ void

Re: Converting a ulong to a byte array and constructing a ulong from it

2019-10-24 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 24 October 2019 at 14:08:36 UTC, 9898287 wrote: On Thursday, 24 October 2019 at 13:50:54 UTC, Paul Backus wrote: Use a cast: ulong m = *cast(ulong*) bytes.ptr; Does this contain any undefined behavior? It is in C as far as I knew. The equivalent code in C would use a char*

Re: Converting a ulong to a byte array and constructing a ulong from it

2019-10-24 Thread Daniel Kozak via Digitalmars-d-learn
On Thu, Oct 24, 2019 at 3:35 PM 9898287 via Digitalmars-d-learn wrote: > > What's the function for converting a ulong to a native-endian > byte array? > For example, > > auto bytes = 0x1234567890123456u64.to_ne_bytes(); > // should yield > // [0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56] in big

Re: Converting a ulong to a byte array and constructing a ulong from it

2019-10-24 Thread Radu via Digitalmars-d-learn
On Thursday, 24 October 2019 at 13:33:30 UTC, 9898287 wrote: What's the function for converting a ulong to a native-endian byte array? For example, auto bytes = 0x1234567890123456u64.to_ne_bytes(); // should yield // [0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56] in big-endian and // [0x56,

Re: Converting a ulong to a byte array and constructing a ulong from it

2019-10-24 Thread 9898287 via Digitalmars-d-learn
On Thursday, 24 October 2019 at 13:50:54 UTC, Paul Backus wrote: On Thursday, 24 October 2019 at 13:33:30 UTC, 9898287 wrote: What's the function for converting a ulong to a native-endian byte array? For example, auto bytes = 0x1234567890123456u64.to_ne_bytes(); // should yield // [0x12, 0x34,

Re: Converting a ulong to a byte array and constructing a ulong from it

2019-10-24 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 24 October 2019 at 13:33:30 UTC, 9898287 wrote: What's the function for converting a ulong to a native-endian byte array? For example, auto bytes = 0x1234567890123456u64.to_ne_bytes(); // should yield // [0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56] in big-endian and // [0x56,

Converting a ulong to a byte array and constructing a ulong from it

2019-10-24 Thread 9898287 via Digitalmars-d-learn
What's the function for converting a ulong to a native-endian byte array? For example, auto bytes = 0x1234567890123456u64.to_ne_bytes(); // should yield // [0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56] in big-endian and // [0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12] in little-endian sy

Re: About the in expression, Why can't use with array.

2019-10-24 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 24 October 2019 at 12:58:11 UTC, lili wrote: Hi: In Dlang where is strange design. The in expression can only use to associative array, why array can not use in expression. Checking for the presence of an item in an array requires a linear search. You can do it with std.algori

About the in expression, Why can't use with array.

2019-10-24 Thread lili via Digitalmars-d-learn
Hi: In Dlang where is strange design. The in expression can only use to associative array, why array can not use in expression.

Re: Differences between two dates (in days...)

2019-10-24 Thread Mil58 via Digitalmars-d-learn
On Thursday, 24 October 2019 at 12:01:21 UTC, Adam D. Ruppe wrote: On Thursday, 24 October 2019 at 11:50:04 UTC, Mil58 wrote: [...] Try this: Duration diff = cast(DateTime) auj - deb; writeln("Diff : ", diff.total!"days"); [...] Awsome ! Thank you for your quick reply... Both lines work pe

Re: Differences between two dates (in days...)

2019-10-24 Thread Daniel Kozak via Digitalmars-d-learn
On Thu, Oct 24, 2019 at 1:55 PM Mil58 via Digitalmars-d-learn wrote: > > Hi All... > I am desperate for the answer to the following problem: > to obtain the difference between the date of today and an older > date (results in days...) > > See my script below, where I would like to do: > "date of t

Re: Differences between two dates (in days...)

2019-10-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 24 October 2019 at 11:50:04 UTC, Mil58 wrote: See my script below, where I would like to do: "date of today" (var: auj) - "an older date" (var: deb) = xx days Try this: Duration diff = cast(DateTime) auj - deb; writeln("Diff : ", diff.total!"days"); So basically, just subtract

Differences between two dates (in days...)

2019-10-24 Thread Mil58 via Digitalmars-d-learn
Hi All... I am desperate for the answer to the following problem: to obtain the difference between the date of today and an older date (results in days...) See my script below, where I would like to do: "date of today" (var: auj) - "an older date" (var: deb) = xx days import std.stdio; import

Re: How to use classes from another d files

2019-10-24 Thread Vinod K Chandran via Digitalmars-d-learn
On Thursday, 24 October 2019 at 10:19:23 UTC, Vinod K Chandran wrote: On Tuesday, 22 October 2019 at 18:34:52 UTC, Daniel Kozak wrote: On Tue, Oct 22, 2019 at 8:30 PM Vinod K Chandran via Digitalmars-d-learn wrote: On Tuesday, 22 October 2019 at 17:38:58 UTC, Adam D. Ruppe wrote: > [...] T

Re: How to use classes from another d files

2019-10-24 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 22 October 2019 at 18:34:52 UTC, Daniel Kozak wrote: On Tue, Oct 22, 2019 at 8:30 PM Vinod K Chandran via Digitalmars-d-learn wrote: On Tuesday, 22 October 2019 at 17:38:58 UTC, Adam D. Ruppe wrote: > On Tuesday, 22 October 2019 at 17:34:51 UTC, Vinod K > Chandran wrote: >> [...

Re: How to use classes from another d files

2019-10-24 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 22 October 2019 at 18:31:17 UTC, Adam D. Ruppe wrote: On Tuesday, 22 October 2019 at 18:21:36 UTC, Vinod K Chandran wrote: But what if there is too many include files ? The dmd -i thing will do that for you dmd -i main.d and it will automatically find the others, assuming they ar

Re: How to use classes from another d files

2019-10-24 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 22 October 2019 at 18:33:32 UTC, Ali Çehreli wrote: On 10/22/2019 11:25 AM, Vinod K Chandran wrote: > On Tuesday, 22 October 2019 at 17:38:58 UTC, Adam D. Ruppe wrote: >> [...] Chandran wrote: >>> [...] playing >> [...] command line? That: The -i switch is the answer to your question