Thread overview
[Issue 3240] New: std.numeric.findRoot only works with real
Aug 10, 2009
Don
Aug 11, 2009
Don
August 10, 2009
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: -------
August 10, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3240





--- Comment #1 from Lars T. Kyllingstad <bugzilla@kyllingen.net>  2009-08-10 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: -------
August 10, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3240


Don <clugdbug@yahoo.com.au> changed:

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




--- Comment #2 from Don <clugdbug@yahoo.com.au>  2009-08-10 04:40:17 PDT ---
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: -------
August 10, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3240





--- Comment #3 from Lars T. Kyllingstad <bugzilla@kyllingen.net>  2009-08-10 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: -------
August 10, 2009
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: -------
August 10, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3240





--- Comment #4 from Andrei Alexandrescu <andrei@metalanguage.com>  2009-08-10 07:14:55 PDT ---
(In reply to comment #3)
> 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: -------
August 11, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3240


Don <clugdbug@yahoo.com.au> changed:

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




--- Comment #5 from Don <clugdbug@yahoo.com.au>  2009-08-11 00:22:18 PDT ---
Fixed in SVN commit 1246.

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