Re: So why double to float conversion is implicit ?

2017-10-28 Thread aberba via Digitalmars-d
On Sunday, 22 October 2017 at 14:59:41 UTC, Andrei Alexandrescu wrote: On 10/22/17 9:41 AM, User wrote: Is there a list of such quirks or gotchas in dlang? The ones I know of are 1. Implicit conversion from double to float 2. Integer division results in integer result truncation the

Re: So why double to float conversion is implicit ?

2017-10-27 Thread Basile B. via Digitalmars-d
On Tuesday, 24 October 2017 at 15:29:38 UTC, Basile B. wrote: On Saturday, 21 October 2017 at 20:17:12 UTC, NX wrote: I was working on some sort of math library for use in graphical computing and I wrote something like this: const float PiOver2 = (atan(1.0) * 4) / 2; Interestingly enough, I

Re: So why double to float conversion is implicit ?

2017-10-25 Thread Fool via Digitalmars-d
On Wednesday, 25 October 2017 at 01:24:01 UTC, codephantom wrote: http://web.mit.edu/curhan/www/docs/Articles/15341_Readings/Group_Dynamics/Janis_Groupthink_from_Psych_Today.pdf Great read, thank you for sharing!

Re: So why double to float conversion is implicit ?

2017-10-25 Thread Fool via Digitalmars-d
On Tuesday, 24 October 2017 at 17:54:55 UTC, Andrei Alexandrescu wrote: For the record, I remember the points made: * When converting across integral types, any failed coercion yields a value essentially unrelated to the source. So we deemed these unacceptable. * When converting int to

Re: So why double to float conversion is implicit ?

2017-10-24 Thread codephantom via Digitalmars-d
On Wednesday, 25 October 2017 at 01:06:40 UTC, codephantom wrote: Consensus within groups is kind of important actually...it encourages harmony and coherence..with which.. there is no group. if only we could edit our post to correct it...when's that going to happen btw. ;-) of course I

Re: So why double to float conversion is implicit ?

2017-10-24 Thread codephantom via Digitalmars-d
On Tuesday, 24 October 2017 at 16:28:03 UTC, Fool wrote: @all: It is sad to see how parts of the community are losing their distance to the project and even put a gloss on completely absurd design decisions. Consensus within groups is kind of important actually...it encourages harmony and

Re: So why double to float conversion is implicit ?

2017-10-24 Thread Andrei Alexandrescu via Digitalmars-d
On 10/24/2017 12:28 PM, Fool wrote: On Tuesday, 24 October 2017 at 14:28:20 UTC, Basile B. wrote:     float f0 = cos(2 * PI /  1.123548789545545646452154L);     float f1 = cos(cast(float)(2 * PI / 1.123548789545545646452154L)); [...] but paradoxically the first is more accurate. There is no

Re: So why double to float conversion is implicit ?

2017-10-24 Thread Fool via Digitalmars-d
On Tuesday, 24 October 2017 at 14:28:20 UTC, Basile B. wrote: float f0 = cos(2 * PI / 1.123548789545545646452154L); float f1 = cos(cast(float)(2 * PI / 1.123548789545545646452154L)); [...] but paradoxically the first is more accurate. There is no paradox. That's comparing apples

Re: So why double to float conversion is implicit ?

2017-10-24 Thread Basile B. via Digitalmars-d
On Saturday, 21 October 2017 at 20:17:12 UTC, NX wrote: I was working on some sort of math library for use in graphical computing and I wrote something like this: const float PiOver2 = (atan(1.0) * 4) / 2; Interestingly enough, I realized that atan() returns double (in this case) but wait,

Re: So why double to float conversion is implicit ?

2017-10-24 Thread Basile B. via Digitalmars-d
On Tuesday, 24 October 2017 at 01:22:57 UTC, codephantom wrote: On Monday, 23 October 2017 at 21:51:24 UTC, Basile B. wrote: --- /** * Wraps a floating point type that doesn't follow D permissive float conversion * rules. * * In D, as in C++, implicit conversion from $(D double) to $(D

Re: So why double to float conversion is implicit ?

2017-10-23 Thread codephantom via Digitalmars-d
On Monday, 23 October 2017 at 21:51:24 UTC, Basile B. wrote: --- /** * Wraps a floating point type that doesn't follow D permissive float conversion * rules. * * In D, as in C++, implicit conversion from $(D double) to $(D float) is allowed, * leading to a possible precision loss. This

Re: So why double to float conversion is implicit ?

2017-10-23 Thread Basile B. via Digitalmars-d
On Saturday, 21 October 2017 at 20:17:12 UTC, NX wrote: I was working on some sort of math library for use in graphical computing and I wrote something like this: const float PiOver2 = (atan(1.0) * 4) / 2; Interestingly enough, I realized that atan() returns double (in this case) but wait,

Re: So why double to float conversion is implicit ?

2017-10-23 Thread Atila Neves via Digitalmars-d
On Saturday, 21 October 2017 at 20:17:12 UTC, NX wrote: I was working on some sort of math library for use in graphical computing and I wrote something like this: const float PiOver2 = (atan(1.0) * 4) / 2; Interestingly enough, I realized that atan() returns double (in this case) but wait,

Re: So why double to float conversion is implicit ?

2017-10-23 Thread codephantom via Digitalmars-d
On Saturday, 21 October 2017 at 20:17:12 UTC, NX wrote: I think this is a serious topic and needs clarification. Just out of interest, as opposed to wanting to debate the merits... I did a little investigation of how various languages deal with floating point precision (by default) for

Re: So why double to float conversion is implicit ?

2017-10-22 Thread Jerry via Digitalmars-d
On Sunday, 22 October 2017 at 10:57:24 UTC, NX wrote: On Sunday, 22 October 2017 at 02:25:44 UTC, codephantom wrote: On Saturday, 21 October 2017 at 20:17:12 UTC, NX wrote: Interestingly enough, I realized that atan() returns double (in this case) but wait, it's assigned to a float variable!

Re: So why double to float conversion is implicit ?

2017-10-22 Thread codephantom via Digitalmars-d
On Sunday, 22 October 2017 at 10:57:24 UTC, NX wrote: I just think spec should be reviewed at this point. Well, as Andrei famously once said, don't argue with the language, just build stuff. So in that spirit, lets not argue with the language specification, but find a solution that meets

Re: So why double to float conversion is implicit ?

2017-10-22 Thread Andrei Alexandrescu via Digitalmars-d
On 10/22/17 9:41 AM, User wrote: Is there a list of such quirks or gotchas in dlang? The ones I know of are 1. Implicit conversion from double to float 2. Integer division results in integer result truncation the fractional part. These are not gotchas, as TDPL explains. One unpleasant

Re: So why double to float conversion is implicit ?

2017-10-22 Thread jmh530 via Digitalmars-d
On Sunday, 22 October 2017 at 13:41:23 UTC, User wrote: Is there a list of such quirks or gotchas in dlang? The ones I know of are 1. Implicit conversion from double to float 2. Integer division results in integer result truncation the fractional part. 3. ?? #2 is common for statically

Re: So why double to float conversion is implicit ?

2017-10-22 Thread User via Digitalmars-d
Is there a list of such quirks or gotchas in dlang? The ones I know of are 1. Implicit conversion from double to float 2. Integer division results in integer result truncation the fractional part. 3. ??

Re: So why double to float conversion is implicit ?

2017-10-22 Thread Basile B. via Digitalmars-d
On Sunday, 22 October 2017 at 12:17:49 UTC, Basile B. wrote: On Sunday, 22 October 2017 at 10:57:24 UTC, NX wrote: [...] Fortunately D provides enough to simplify self-discipline: --- import std.traits; struct FP(T) if (isFloatingPoint!T) { T _value; alias _value this; void

Re: So why double to float conversion is implicit ?

2017-10-22 Thread Basile B. via Digitalmars-d
On Sunday, 22 October 2017 at 10:57:24 UTC, NX wrote: On Sunday, 22 October 2017 at 02:25:44 UTC, codephantom wrote: On Saturday, 21 October 2017 at 20:17:12 UTC, NX wrote: Interestingly enough, I realized that atan() returns double (in this case) but wait, it's assigned to a float variable!

Re: So why double to float conversion is implicit ?

2017-10-22 Thread Ola Fosheim Grøstad via Digitalmars-d
On Sunday, 22 October 2017 at 10:57:24 UTC, NX wrote: D is not C/C++ either. I fail to see how does it help to be C++ compliant. It's absolutely trivial to tell the compiler that conversion is on purpose by explicitly casting and it immensely helps to reduce bugs (since we are humans after

Re: So why double to float conversion is implicit ?

2017-10-22 Thread NX via Digitalmars-d
On Sunday, 22 October 2017 at 02:25:44 UTC, codephantom wrote: On Saturday, 21 October 2017 at 20:17:12 UTC, NX wrote: Interestingly enough, I realized that atan() returns double (in this case) but wait, it's assigned to a float variable! Compiler didn't even emit warnings, let alone errors.

Re: So why double to float conversion is implicit ?

2017-10-21 Thread codephantom via Digitalmars-d
On Saturday, 21 October 2017 at 20:17:12 UTC, NX wrote: Interestingly enough, I realized that atan() returns double (in this case) but wait, it's assigned to a float variable! Compiler didn't even emit warnings, let alone errors. There a few lessons here. (1) D is not Java ;-) (2) Know

Re: So why double to float conversion is implicit ?

2017-10-21 Thread user1234 via Digitalmars-d
On Saturday, 21 October 2017 at 20:17:12 UTC, NX wrote: I was working on some sort of math library for use in graphical computing and I wrote something like this: const float PiOver2 = (atan(1.0) * 4) / 2; Interestingly enough, I realized that atan() returns double (in this case) but wait,

So why double to float conversion is implicit ?

2017-10-21 Thread NX via Digitalmars-d
I was working on some sort of math library for use in graphical computing and I wrote something like this: const float PiOver2 = (atan(1.0) * 4) / 2; Interestingly enough, I realized that atan() returns double (in this case) but wait, it's assigned to a float variable! Compiler didn't even