Merge pull request #3475 from mapycz/logarithm
Add support for natural logarithm in expressions (via @talaj)
This commit is contained in:
commit
68db7ee224
3 changed files with 15 additions and 0 deletions
|
@ -102,6 +102,7 @@ unary_function_types::unary_function_types()
|
|||
("tan", tan_impl())
|
||||
("atan", atan_impl())
|
||||
("exp", exp_impl())
|
||||
("log", log_impl())
|
||||
("abs", abs_impl())
|
||||
("length",length_impl())
|
||||
;
|
||||
|
|
|
@ -50,6 +50,17 @@ struct exp_impl
|
|||
|
||||
};
|
||||
|
||||
// log
|
||||
struct log_impl
|
||||
{
|
||||
//using type = T;
|
||||
value_type operator() (value_type const& val) const
|
||||
{
|
||||
return std::log(val.to_double());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// sin
|
||||
struct sin_impl
|
||||
{
|
||||
|
|
|
@ -108,6 +108,9 @@ TEST_CASE("expressions")
|
|||
TRY_CHECK(eval(" rad_to_deg * atan(1.0) ").to_double() == approx(45.0));
|
||||
// exp
|
||||
TRY_CHECK(eval(" exp(0.0) ") == 1.0);
|
||||
// log
|
||||
TRY_CHECK(eval(" log(1.0) ") == 0.0);
|
||||
TRY_CHECK(eval(" log(exp(1.0)) ") == 1.0);
|
||||
// abs
|
||||
TRY_CHECK(eval(" abs(cos(-pi)) ") == 1.0);
|
||||
// length (string)
|
||||
|
|
Loading…
Reference in a new issue