Re: Question about: ("1.1").to!int;

2020-10-24 Thread Jack via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote: Hi, import std.stdio, std.conv; void main(string[ ] args) { auto a = (1).to!int; // this works auto b = ("1").to!int; // this works auto c = (1.1).to!int; // this works and c = 1 auto d = ("1.1").to!int; //

Re: Question about: ("1.1").to!int;

2020-10-24 Thread Виталий Фадеев via Digitalmars-d-learn
On Saturday, 24 October 2020 at 14:10:02 UTC, matheus wrote: On Saturday, 24 October 2020 at 04:04:18 UTC, Виталий Фадеев wrote: On Friday, 23 October 2020 at 16:59:06 UTC, matheus wrote: On Friday, 23 October 2020 at 13:57:41 UTC, Joseph Rushton Wakeling wrote: On Wednesday, 21 October 2020

Re: Question about: ("1.1").to!int;

2020-10-24 Thread matheus via Digitalmars-d-learn
On Saturday, 24 October 2020 at 04:04:18 UTC, Виталий Фадеев wrote: On Friday, 23 October 2020 at 16:59:06 UTC, matheus wrote: On Friday, 23 October 2020 at 13:57:41 UTC, Joseph Rushton Wakeling wrote: On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote: Well since the caller is

Re: Question about: ("1.1").to!int;

2020-10-23 Thread Виталий Фадеев via Digitalmars-d-learn
On Friday, 23 October 2020 at 16:59:06 UTC, matheus wrote: On Friday, 23 October 2020 at 13:57:41 UTC, Joseph Rushton Wakeling wrote: On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote: Well since the caller is handling a string, shouldn't the caller verify the content before any

Re: Question about: ("1.1").to!int;

2020-10-23 Thread Виталий Фадеев via Digitalmars-d-learn
On Friday, 23 October 2020 at 16:59:06 UTC, matheus wrote: On Friday, 23 October 2020 at 13:57:41 UTC, Joseph Rushton Wakeling wrote: On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote: Since (1.1).to!int = 1, shouldn't the string value ("1.1").to!int at least try to convert to

Re: Question about: ("1.1").to!int;

2020-10-23 Thread matheus via Digitalmars-d-learn
On Friday, 23 October 2020 at 13:57:41 UTC, Joseph Rushton Wakeling wrote: On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote: Since (1.1).to!int = 1, shouldn't the string value ("1.1").to!int at least try to convert to float/double and then to int? The thing is, that's a great way

Re: Question about: ("1.1").to!int;

2020-10-23 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On Friday, 23 October 2020 at 14:16:50 UTC, user1234 wrote: The third case is just like `cast(int) 1.1` it's not _at programmer request_ from my point of view If the programmer explicitly writes a `to!int` or the `cast(int)`, then it's pretty clearly at their request. And it's unambiguous

Re: Question about: ("1.1").to!int;

2020-10-23 Thread bachmeier via Digitalmars-d-learn
On Friday, 23 October 2020 at 13:57:41 UTC, Joseph Rushton Wakeling wrote: In particular, if `to` just accepted any string numerical representation for conversion to int, how could the caller explicitly _exclude_ non-integer input, if that is their use-case? So it's far better to require

Re: Question about: ("1.1").to!int;

2020-10-23 Thread user1234 via Digitalmars-d-learn
On Friday, 23 October 2020 at 13:57:41 UTC, Joseph Rushton Wakeling wrote: On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote: Since (1.1).to!int = 1, shouldn't the string value ("1.1").to!int at least try to convert to float/double and then to int? The thing is, that's a great way

Re: Question about: ("1.1").to!int;

2020-10-23 Thread Joseph Rushton Wakeling via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote: Since (1.1).to!int = 1, shouldn't the string value ("1.1").to!int at least try to convert to float/double and then to int? The thing is, that's a great way for hard-to-identify bugs to creep into code. In these cases: auto

Re: Question about: ("1.1").to!int;

2020-10-23 Thread matheus via Digitalmars-d-learn
On Friday, 23 October 2020 at 08:09:13 UTC, Виталий Фадеев wrote: On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote: Hi, import std.stdio, std.conv; void main(string[ ] args) { auto a = (1).to!int; // this works auto b = ("1").to!int; // this works auto c =

Re: Question about: ("1.1").to!int;

2020-10-23 Thread Виталий Фадеев via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote: Hi, import std.stdio, std.conv; void main(string[ ] args) { auto a = (1).to!int; // this works auto b = ("1").to!int; // this works auto c = (1.1).to!int; // this works and c = 1 auto d = ("1.1").to!int; //

Re: Question about: ("1.1").to!int;

2020-10-21 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote: Since (1.1).to!int = 1, shouldn't the string value ("1.1").to!int at least try to convert to float/double and then to int? I don't think so. A silent string->double conversion isn't IMO consistent with D's design.

Question about: ("1.1").to!int;

2020-10-21 Thread matheus via Digitalmars-d-learn
Hi, import std.stdio, std.conv; void main(string[ ] args) { auto a = (1).to!int; // this works auto b = ("1").to!int; // this works auto c = (1.1).to!int; // this works and c = 1 auto d = ("1.1").to!int; // Doesn't work } The forth line gives me: