-
-
Notifications
You must be signed in to change notification settings - Fork 651
[big feature] Implement core.math.pow() for ^^ operator #14297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Thanks for your pull request, @ibuclaw! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#14297" |
50efc14
to
eb78d88
Compare
immutable t2 = t1 + r; | ||
immutable lo1 = k * ln2lo + logctail; | ||
immutable lo2 = t1 - t2 + r; | ||
// Evaluation is optimized assuming superscalar pipelined execution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiple issue? All processors are pipelined in some way and basically anything is superscalar now.
over what test program/benchmark + compiler settings etc. |
// x = the value to evaluate | ||
// A = array of coefficients | ||
pragma(inline, true) | ||
static real poly_inline(alias A)(real x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these functions could probably be put inside a template somewhere else so there's no risk of having a bunch of them in the binary N times over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm just making it work first, then making it pretty later. :-)
Yet to decide on whether to (A) make them private, or shunt them off to core.internal.math
, and (B) keep them as inline templates or (possibly inline) plain functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: all these _inline
functions do not handle non-finite (and in some cases subnormal) input values because those are assumed to be taken care of by the "special cases" handling of outer pow()
function.
Adds two new functions for the power operator: typeof(X * Y) pow(X, Y) if (IntOrFloat!X && Int!Y); typeof(X * Y) pow(X, Y) if (IntOrFloat!X && Float!Y);
Adds two new functions for the power operator:
Lowers
x ^^ y
operator tocore.math.pow(x, y)
.Self assessment score:
2/10 readability
0/10 maintainability
10/10 speed (so long as you're using 64-bit doubles)
42/10 compiler+druntime changed together in one PR.
Implementation
The integral power function is pretty much taken from the std.math template. Where it differs is rather than having two separate templates for
pow(int, int)
andpow(float, int)
, these have been merged into onepow(int_or_float, int)
function.The floating point power function similarly merges the
pow(int, float)
andpow(float, float)
templates into onepow(int_or_float, float)
function. It is otherwise a complete reworking, as the std.math implementation fails to deliver on two fronts:real
precision only.sign * exp2(y * log2(x))
or (sign * exp2(fyl2x(x, y))
), which is not accurate in practice.The new implementation is split up into two (or three) different algorithms:
Unittesting
The unittests in std.math are OK, though have an affinity towards real precision testing. Most can be hoisted into core.math and tweaked to validate all types, i.e:
foreach (T; AliasSeq!(float, double, real))
.Note: some tests in std.math are just plain wrong, thankfully they only concern the special case handling, i.e
pow(1, nan) == 1
(std.math asserts the result is nan).Benchmarking
Naive test only confirms what we already know about x87 speeds (note, std.math.pow only computes at real precision)
Tested on: