www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3240] New: std.numeric.findRoot only works with real

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3240

           Summary: std.numeric.findRoot only works with real
           Product: D
           Version: 2.031
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bugzilla kyllingen.net


Trying to use std.numeric.findRoot with other types than real gives template
instantiation errors originating from lines 599 and 560 in numeric.d (DMD
2.031, SVN rev. 1200):

  599   if (a==0) c = ieeeMean(copysign(0.0L, b), b);
  560   else if (b==0) c = ieeeMean(copysign(0.0L, a), a);

If a and b are double, I get the following errors:

/usr/local/include/d/phobos2/std/numeric.d(599): Error: template
std.math.ieeeMean(T) does not match any function template declaration
/usr/local/include/d/phobos2/std/numeric.d(599): Error: template
std.math.ieeeMean(T) cannot deduce template function from argument types
!()(real,double)
/usr/local/include/d/phobos2/std/numeric.d(600): Error: template
std.math.ieeeMean(T) does not match any function template declaration
/usr/local/include/d/phobos2/std/numeric.d(600): Error: template
std.math.ieeeMean(T) cannot deduce template function from argument types
!()(real,double)


This is because IFTI doesn't work with implicit conversions (bug 1641 and
probably others), and std.math.copysign() always returns a real.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 10 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3240






03:29:47 PDT ---
Um.. like the actual pasted error messages say, the line numbers should be 599
and 600, not 500 and 560. Sorry, don't know how that happened.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 10 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3240


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au





Good catch. That's caused by a change to the signature of ieeeMean(). Trivially
fixable by inserting casts, though arguably copySign should become a templated
function.

BTW I wrote this code for Tango, it will eventually have a signature change to
match the new Phobos style. It predates ranges, for example, even though it's a
perfect example of a floating-point range-based algorithm. Thus, it's not as
generic as it could be.

Don.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 10 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3240






04:50:09 PDT ---
There's an even simpler fix -- i.e. less typing. :)

Since both a, b and c are of type T, this also works:

  599   if (a==0) c = ieeeMean!T(copysign(0.0L, b), b);
  600   else if (b==0) c = ieeeMean!T(copysign(0.0L, a), a);

I've added this fix to my local Phobos. I just tried this for fun, and expected
to get an error from trying to implicitly cast real to double. But for some
reason it worked.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 10 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3240


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei metalanguage.com
         AssignedTo|nobody puremagic.com        |andrei metalanguage.com




-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 10 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3240






07:14:55 PDT ---

 There's an even simpler fix -- i.e. less typing. :)
 
 Since both a, b and c are of type T, this also works:
 
   599   if (a==0) c = ieeeMean!T(copysign(0.0L, b), b);
   600   else if (b==0) c = ieeeMean!T(copysign(0.0L, a), a);
 
 I've added this fix to my local Phobos. I just tried this for fun, and expected
 to get an error from trying to implicitly cast real to double. But for some
 reason it worked.
Don, sorry, I took this over before seeing you are considering working on it. You may want to take ownership. Thanks! -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 10 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3240


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED





Fixed in SVN commit 1246.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 11 2009