Merge pull request #3475 from mapycz/logarithm

Add support for natural logarithm in expressions (via @talaj)
This commit is contained in:
Artem Pavlenko 2016-08-01 15:07:01 +02:00 committed by GitHub
commit 68db7ee224
3 changed files with 15 additions and 0 deletions

View file

@ -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())
;

View file

@ -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
{

View file

@ -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)