[英]C++ math expression from math formula
First, the log
function already computes the logarithm to the base e
.首先,
log
函数已经计算了以e
为底的对数。 You don't need to perform any change-of-base.您不需要执行任何基数更改。
Second, split your expression into parts to make it easier to write, and to understand:其次,将您的表达式分成几部分,以便于编写和理解:
const double F = getpixel(j, k);
const double numerator = log(1.0 + a * F);
const double denominator = log(2.0);
const double result = numerator / denominator;
You could choose to split it more (eg store the a*F
, and 1 + a*F
separately too).您可以选择更多地拆分它(例如,也将
a*F
和1 + a*F
分开存储)。
Once you've got that, if you really want it in a single line, it's easy enough to combine (but there's no need; the compiler will typically merge constant expressions together for you):一旦你得到了它,如果你真的想要在一行中,它很容易组合(但没有必要;编译器通常会为你将常量表达式合并在一起):
const double result = log(1.0 + a * getpixel(j, k) / log(2.0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.