Don wrote:
Ary Borenszweig wrote:
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?"

That's a good point, it should be possible to use a static import as well. I do think it's pretty odd to be doing floating point without importing std.math, though. I mean, abs() is absolutely fundamental.

But if you do a static import the whole module gets linked in, right?

My point is, if you are going to pow, you will need std.math, so it'll always be a burden to import it by hand when using it. ^^

Reply via email to