[phobos] Bug 4455: Taking sqrt of an integer

Lars Tandle Kyllingstad lars at kyllingen.net
Fri Jul 16 01:38:53 PDT 2010


On Fri, 2010-07-16 at 07:32 +0200, Don Clugston wrote:
> On 16 July 2010 04:16, David Simcha <dsimcha at gmail.com> wrote:
> > On 7/15/2010 9:22 PM, Don Clugston wrote:
> >>
> >> On 16 July 2010 01:04, David Simcha<dsimcha at gmail.com>  wrote:
> >>
> >>>
> >>> So is everyone on board for this?  If not, please say something.
> >>>  Otherwise
> >>> I'll make the changes.
> >>>
> >>
> >> It won't work. sqrt is a compiler intrinsic, and can't be changed to a
> >> template without modifying the compiler.
> >
> > (Smacks hand against forehead.)  I realized that right after I sent that
> > message.  I guess the options are, then:
> >
> > 1.  Modify the compiler.  I guess the easiest way would be to rename the
> > sqrt() intrinsic to sqrtImpl() and have a function called sqrt() in std.math
> > that forwards to sqrtImpl().
> 
> I think __sqrt() would be a better name. I'd recommend renaming sin()
> and cos() at the same time, since the intrinsics are hopelessly
> inaccurate for large arguments.
> 
> >
> > 2.  Live with it for now.  It's an extremely annoying bug in that math-heavy
> > code runs into it constantly, but it's an easy bug to work around.
> >
> > 3.  Get rid of sqrt(float).  Walter, or whoever put it there in the first
> > place:  Why is it there?  Do we really need it?
> 
> It makes no difference to the generated x87 code. It does affect type
> inference, but it's not adding much value.
> 
> >
> > 4.  Make explicit overloads for every single numeric type.  This is ugly but
> > do-able and would definitely be a 100% solution.
> 
> Note that the same issue applies to all std.math functions, although
> sqrt() might be the only one that is truly annoying.


The math functions are all evaluated at maximum precision anyway, aren't
they?  Wouldn't it then make sense to remove all overloads except the
ones that take real arguments?  That would have the added benefit of
making said fact (provided it is a fact) very explicit.

-Lars



More information about the phobos mailing list