Code speed

Ary Borenszweig ary at esperanto.org.ar
Thu Apr 15 09:33:46 PDT 2010


Don wrote:
> Lars T. Kyllingstad wrote:
>> Don wrote:
>>> bearophile wrote:
>>>> So far I've just given a light reading of the code. Notes:
>>>
>>>> - pow(x, 2) and sqrt(y) can be written as x ^^ 2 and y ^^ 0.5 (but 
>>>> you have to import std.math anyway, because of a bug).
>>>
>>> That's not a bug. It's intentional. x ^^ y will probably always 
>>> require import std.math, if y is a floating point number.
>>
>> Really?  Why is that?  I find that kind of disappointing, I always 
>> believed it to be a temporary solution.
>>
>> I think the inconsistency with the other operators will make this a 
>> major WTF for people new to the language.  Why should a^^b require an 
>> explicit import while a*b doesn't?
> 
> Because pow() for floating point, when implemented properly, is a HUGE 
> function, that ends up dragging almost all of std.math into the 
> executable. And I think it's deceptive to do that silently.
> To make it completely built-in, basically all of std.math would need to 
> be moved into druntime. Feel free to try to change my mind, of course.

Is there a better way to do pow() for floating point numbers without 
importing std.math?

I see this:

1. You want to do x ^^ fp.
2. The compiler complains saying "if you want to do that, import 
std.math. I'm telling you this just to let you know you'll be importing 
the whole module".

Alternative 1 for user:
User says "Ok, I import std.math"

Alternative 2 for user:
User says "No way I'm importing std.math just to make a pow. But... I 
still *need* to make that pow... what is your advice, mr. compiler?"


More information about the Digitalmars-d-learn mailing list