www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Clarification on testsuite 'runnable/testmath.d'

reply Daniel Green <venix1 gmail.com> writes:
I've been working on fixing GDC/MinGW's runtime support.  I ran across 
the following and was hoping to get a clarification on what DMD does 
differently than GDC.

void testexp()
{
     printf("exp(3.0) = %Lg, %Lg\n", exp(3.0), E * E * E);
     assert(equals(exp(3.0), E * E * E, 16));
}

Of interest is exp(3.0).  GDC matches exp(3.0) to double exp(double). 
This causes problems with printf due to %Lg wanting a real but only 
receiving a double.

Looking at the D specification for overloading functions.
     1. no match
     2. match with implicit conversions
     3. match with conversion to const
     4. exact match


The specification doesn't indicate what levels are better.  I would 
guess 4 is the best since an exact match should take precedence.
However, that results in GDC matching exp(3.0) to double exp(double).

How does DMD match exp(3.0)?

Could it possibly be a typo?  For 32-bit this test passes because the 
printf doesn't segfault, it's only  noticeable with 64-bit since it 
segfaults.
Jan 13 2012
next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 1/13/2012 10:51 PM, Daniel Green wrote:
 Could it possibly be a typo? For 32-bit this test passes because the printf
 doesn't segfault, it's only noticeable with 64-bit since it segfaults.

3.0 should match double, when there is both double and real.
Jan 14 2012
next sibling parent reply Daniel Green <venix1 gmail.com> writes:
On 1/14/2012 3:29 AM, Walter Bright wrote:
 On 1/13/2012 10:51 PM, Daniel Green wrote:
 Could it possibly be a typo? For 32-bit this test passes because the
 printf
 doesn't segfault, it's only noticeable with 64-bit since it segfaults.

3.0 should match double, when there is both double and real.

On 1/14/2012 3:29 AM, Walter Bright wrote:
 On 1/13/2012 10:51 PM, Daniel Green wrote:
 Could it possibly be a typo? For 32-bit this test passes because the
 printf
 doesn't segfault, it's only noticeable with 64-bit since it segfaults.

3.0 should match double, when there is both double and real.

When I run the following through DMD r is type real. For GDC r is type double. The matched function would be double exp(double x) safe pure nothrow { return exp(cast(real)x); }. Is it expected that DMD promotes a double to real? // GDC: r is type double // DMD: r is type real import std.stdio; import std.math; void main() { auto r = exp(3.0); writefln("%s", typeof(r).stringof); }
Jan 14 2012
parent Daniel Green <venix1 gmail.com> writes:
On 1/14/2012 10:34 AM, Iain Buclaw wrote:
 Strange, I get 'double' for both DMD and GDC... is this maybe a Windows thing?

Just ran it with linux and got 'double' as well. So it appears to be a Windows thing.
Jan 14 2012
prev sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
On 14 January 2012 15:20, Daniel Green <venix1 gmail.com> wrote:
 On 1/14/2012 3:29 AM, Walter Bright wrote:
 On 1/13/2012 10:51 PM, Daniel Green wrote:
 Could it possibly be a typo? For 32-bit this test passes because the
 printf
 doesn't segfault, it's only noticeable with 64-bit since it segfaults.

3.0 should match double, when there is both double and real.

On 1/14/2012 3:29 AM, Walter Bright wrote:
 On 1/13/2012 10:51 PM, Daniel Green wrote:
 Could it possibly be a typo? For 32-bit this test passes because the
 printf
 doesn't segfault, it's only noticeable with 64-bit since it segfaults.

3.0 should match double, when there is both double and real.

When I run the following through DMD r is type real. =A0For GDC r is type double. The matched function would be =A0 double exp(double x) safe pure nothrow =A0{ return exp(cast(real)x);=

 Is it expected that DMD promotes a double to real?


 // GDC: r is type double
 // DMD: r is type real
 import std.stdio;
 import std.math;

 void main()
 {
 =A0 =A0auto r =3D exp(3.0);
 =A0 =A0writefln("%s", typeof(r).stringof);
 }

Strange, I get 'double' for both DMD and GDC... is this maybe a Windows thi= ng? --=20 Iain Buclaw *(p < e ? p++ : p) =3D (c & 0x0f) + '0';
Jan 14 2012
prev sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--f46d0418264216e06304b679480e
Content-Type: text/plain; charset=ISO-8859-1

I think the only difference may be that gdc possibly folds the call to
exp().

Check the difference between what code gdc generates compared to how gcc
processed it:  -fdump-tree-original  -fdump-tree-optimized

----
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';

On 14 Jan 2012 06:56, "Daniel Green" <venix1 gmail.com> wrote:
 I've been working on fixing GDC/MinGW's runtime support.  I ran across

differently than GDC.
 void testexp()
 {
    printf("exp(3.0) = %Lg, %Lg\n", exp(3.0), E * E * E);
    assert(equals(exp(3.0), E * E * E, 16));
 }

 Of interest is exp(3.0).  GDC matches exp(3.0) to double exp(double).

receiving a double.
 Looking at the D specification for overloading functions.
    1. no match
    2. match with implicit conversions
    3. match with conversion to const
    4. exact match


 The specification doesn't indicate what levels are better.  I would guess

 However, that results in GDC matching exp(3.0) to double exp(double).

 How does DMD match exp(3.0)?

 Could it possibly be a typo?  For 32-bit this test passes because the

segfaults. --f46d0418264216e06304b679480e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <p>I think the only difference may be that gdc possibly folds the call to e= xp().</p> <p>Check the difference between what code gdc generates compared to how gcc= processed it:=A0 -fdump-tree-original=A0 -fdump-tree-optimized</p> <p>----<br> Iain Buclaw</p> <p>*(p &lt; e ? p++ : p) =3D (c &amp; 0x0f) + &#39;0&#39;;</p> <p>On 14 Jan 2012 06:56, &quot;Daniel Green&quot; &lt;<a href=3D"mailto:ven= ix1 gmail.com">venix1 gmail.com</a>&gt; wrote:<br> &gt;<br> &gt; I&#39;ve been working on fixing GDC/MinGW&#39;s runtime support. =A0I = ran across the following and was hoping to get a clarification on what DMD = does differently than GDC.<br> &gt;<br> &gt; void testexp()<br> &gt; {<br> &gt; =A0 =A0printf(&quot;exp(3.0) =3D %Lg, %Lg\n&quot;, exp(3.0), E * E * E= );<br> &gt; =A0 =A0assert(equals(exp(3.0), E * E * E, 16));<br> &gt; }<br> &gt;<br> &gt; Of interest is exp(3.0). =A0GDC matches exp(3.0) to double exp(double)= . This causes problems with printf due to %Lg wanting a real but only recei= ving a double.<br> &gt;<br> &gt; Looking at the D specification for overloading functions.<br> &gt; =A0 =A01. no match<br> &gt; =A0 =A02. match with implicit conversions<br> &gt; =A0 =A03. match with conversion to const<br> &gt; =A0 =A04. exact match<br> &gt;<br> &gt;<br> &gt; The specification doesn&#39;t indicate what levels are better. =A0I wo= uld guess 4 is the best since an exact match should take precedence.<br> &gt; However, that results in GDC matching exp(3.0) to double exp(double).<= br> &gt;<br> &gt; How does DMD match exp(3.0)?<br> &gt;<br> &gt; Could it possibly be a typo? =A0For 32-bit this test passes because th= e printf doesn&#39;t segfault, it&#39;s only =A0noticeable with 64-bit sinc= e it segfaults.<br> </p> --f46d0418264216e06304b679480e--
Jan 14 2012