std.math log and family

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Oct 31 01:08:23 UTC 2018


On Wed, Oct 31, 2018 at 12:48:03AM +0000, Joe via Digitalmars-d-learn wrote:
[...]
> I'd like to know if the lack of double/float versions of 'log',
> 'log10', etc. are intentional, i.e., there's some rationale behind it,
> or an oversight.

It's an oversight.  Thanks for bringing it to our attention.

Well, actually there's a historical reason behind it, but that's no
excuse.  Please file a bug against Phobos here:

	http://issues.dlang.org/


> I'd also like to know the proper/best way to deal with the error,
> considering the real code embeds the 'Funcptr's in an array of
> structs.  Is it better to write a function 'mylog' that internally
> casts the argument and the return value, or is there some safe way to
> cast away the 'log' function at the point of initializing the array?

I don't think it's safe to cast the function pointer, because of
mismatching types. You might get undefined behaviour at runtime. Define
your own wrapper instead, as you said, that just forwards the
implementation to std.math.log. You don't need to cast the argument
because it implicitly promotes to real anyway:

	float mylog(float arg) { return std.math.log(arg); }
	auto funcptr = &mylog;


> Also, is it preferable to post the first question
> (intentional/oversight) in the Phobos forum? And what is the preferred
> way of reporting the LDC problem, via GitHub?

If you're unsure, just ask on the forum. :)

In this case, this is a bug in Phobos itself, so an issue should be
filed at: http://issues.dlang.org/

(While discussion on the forum may be helpful, always remember to file
an issue, because forum discussions may get forgotten after some time,
whereas issues in the bug tracker will eventually get looked at. Don't
be shy to clamor on the forum about bugs that nobody has responded to in
a long time, though.  Sometimes things get overlooked and we just need
a reminder.)


T

-- 
Long, long ago, the ancient Chinese invented a device that lets them see through walls. It was called the "window".


More information about the Digitalmars-d-learn mailing list