complex arithmetic in D: multiple questions
J-S Caux
js at gmail.com
Fri Mar 9 14:41:47 UTC 2018
On Friday, 9 March 2018 at 13:56:33 UTC, Nicholas Wilson wrote:
>> - I would expect the D `Complex!double` case to work faster
>> than the `real` one. Why is it the other way around? [I can
>> accept (and use) D with Complex!real running 1/3 the speed of
>> C++ (but with increased accuracy), but I'd also love to be
>> able to run D with `Complex!double` at C++ speeds, since the
>> tradeoff might be worth it for some calculations]
>
> because the double version is doing the exact same work as the
> real
> except that it is also converting between real and double for
> atan2 (from arg).
> https://github.com/dlang/phobos/blob/master/std/math.d#L1352
>
> I'm really not sure why phobos does that, it should't.
Is this a case for a bug report? Seems pretty bizarre to do that,
like an oversight/neglect.
>> - what is the best way to correct the unfortunate (to be
>> polite) omission of many standard mathematical functions from
>> std.complex? [if I may be frank, this is a real pain for us
>> scientists] There exists
>> https://gist.github.com/Biotronic/17af645c2c9b7913de1f04980cd22b37 but can this be integrated (after improvements) in the language, or should I (re)build my own?
>
> It will be much faster to build your own that just forward to
> the C functions (or LLVM intrinsics) see
> https://github.com/libmir/mir-algorithm/blob/master/source/mir/math/common.d#L126 for a starting point (we'd greatly appreciate pull requests for anything missing).
> Even if the decision to make std.math behave at the appropriate
> precision is accepted, it will still take an entire release
> cycle (unless you use dmd master), and I'm not so sure it will.
>
OK thanks. I looked at libmir, and saw many good things there. I
was wondering: is it still actively developed/maintained? How
will it fit with the "core" D in the future? [I don't want to
build dependencies to libraries which aren't there to stay in the
long run, I want code which can survive for decades]. It would
seem to me that some of the things included in there should be
part of D core/std anyway.
Going further, I'm really wondering what the plan is as far as
Complex is concerned. Right now it just feels neglected
(half-done/aborted transition from creal etc to Complex, lots of
missing basic functions etc), and is one major blocking point as
far as adoption (among scientists) is concerned. Julia is really
taking off with many of my colleagues, mostly because due respect
was given to maths. I'd certainly choose Julia if it wasn't for
the fact that I can't get my exploratory/testing codes to run
faster than about 1/10th of my C++ stuff. It seems D could have
such an appeal in the realm of science, but these little things
are really blocking adoption (including for myself).
>> [related questions:
>
> Did you press send too soon?
No, the related questions were linked in my previous post (just
copied & pasted it further above, but didn't delete these last
couple of words properly).
Thanks a lot Nicholas!
More information about the Digitalmars-d-learn
mailing list