一个C++可以指定基础的日志的实现?

发布于 2024-12-19 01:46:29 字数 344 浏览 4 评论 0原文

我最近一直在玩一些数学,我想知道是否有人编写/见过可以为其指定基数(根..?)的日志的 C++ 实现?如:

数学函数定义 http://i1091.photobucket.com/albums/ i383/dannydeth1/forumla.png

显然我更喜欢将基数作为参数: double d =日志(b,x);

感谢您的宝贵时间,非常感谢您的回答。 :}

编辑:另外,我认为它会使用泰勒级数?

I've been playing around with some math recently and I would like to know if anyone has written/seen a C++ implementation of log that one can specify the base (root..?) for? As in:

Mathematical function definition http://i1091.photobucket.com/albums/i383/dannydeth1/forumla.png

Obviously I would prefer giving the base as an argument: double d = log(b,x);

Thank you for your time and any answers are much appreciated. :}

EDIT: Also, I take it would use Taylor Series?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空名 2024-12-26 01:46:29

log_b_(x) = log(x) / log(b)。只需这样做:

double log(double base, double x)
{
    return std::log(x) / std::log(base);
}

log_b_(x) = log(x) / log(b). Just do this:

double log(double base, double x)
{
    return std::log(x) / std::log(base);
}
电影里的梦 2024-12-26 01:46:29

自己实现起来很简单:

double
logb( double n, double b )
{
    return log(n) / log(b);
}

它通常有用吗?或者几乎所有用途都包含在 loglog10log2 中?

It's straightforward to implement yourself:

double
logb( double n, double b )
{
    return log(n) / log(b);
}

Is it generally useful? Or are practically all of the uses subsumed by log, log10 and log2?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文