Bug 6715 – Using a custom pow function for ^^

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-09-22T11:46:57Z
Last change time
2024-12-13T17:56:29Z
Assigned to
No Owner
Creator
siegelords_abode
Moved to GitHub: dmd#17531 →

Comments

Comment #0 by siegelords_abode — 2011-09-22T11:46:57Z
I want to use a custom pow function (e.g. the one from the C standard library, or from Tango) instead of the one in std.math, but a^^b is rewritten into std.math.pow(a, b) which makes this difficult to accomplish. I can work around it by using a static method like so: struct std { struct math { static auto pow(real a, real b); } } But I'd rather not have to do that (it breaks std imports, for example). Can we have ^^ rewritten into a simple pow?
Comment #1 by siegelords_abode — 2012-04-04T16:01:30Z
An even better idea occurred to me today, now that UFCS has been introduced. Instead of my original proposal, why not do this: a^^b turns into a.pow(b) Due to the way properties are looked up this is safer than the original proposal (bad things won't happen if you have variables named 'pow' for example).
Comment #2 by bearophile_hugs — 2012-04-04T16:17:36Z
(In reply to comment #0) > Can we have ^^ rewritten into a simple pow? Note: I think that currently a^^b is optimized in some special cases by the compiler (like b = 2). A simple function call causes a loss of those handy optimizations.
Comment #3 by siegelords_abode — 2012-12-29T08:08:04Z
(In reply to comment #2) > (In reply to comment #0) > > > Can we have ^^ rewritten into a simple pow? > > Note: I think that currently a^^b is optimized in some special cases by the > compiler (like b = 2). A simple function call causes a loss of those handy > optimizations. I never asked for those optimizations to be disabled. I am solely talking about the cases when ^^ is rewritten as a function.
Comment #4 by ibuclaw — 2017-12-12T22:51:04Z
The function rewrite should really be targeting `core.math` instead of `std.math`. Or, granted that this is an operation with a special syntax, the initial template could be part of object.d, which then forwards to the correct function as appropriate.
Comment #5 by robert.schadek — 2024-12-13T17:56:29Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17531 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB