add support for natural logarithm function in expressions
This commit is contained in:
parent
9a0d7b0d68
commit
c1ab5c8e6c
3 changed files with 15 additions and 0 deletions
|
@ -102,6 +102,7 @@ unary_function_types::unary_function_types()
|
||||||
("tan", tan_impl())
|
("tan", tan_impl())
|
||||||
("atan", atan_impl())
|
("atan", atan_impl())
|
||||||
("exp", exp_impl())
|
("exp", exp_impl())
|
||||||
|
("log", log_impl())
|
||||||
("abs", abs_impl())
|
("abs", abs_impl())
|
||||||
("length",length_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
|
// sin
|
||||||
struct sin_impl
|
struct sin_impl
|
||||||
{
|
{
|
||||||
|
|
|
@ -108,6 +108,9 @@ TEST_CASE("expressions")
|
||||||
TRY_CHECK(eval(" rad_to_deg * atan(1.0) ").to_double() == approx(45.0));
|
TRY_CHECK(eval(" rad_to_deg * atan(1.0) ").to_double() == approx(45.0));
|
||||||
// exp
|
// exp
|
||||||
TRY_CHECK(eval(" exp(0.0) ") == 1.0);
|
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
|
// abs
|
||||||
TRY_CHECK(eval(" abs(cos(-pi)) ") == 1.0);
|
TRY_CHECK(eval(" abs(cos(-pi)) ") == 1.0);
|
||||||
// length (string)
|
// length (string)
|
||||||
|
|
Loading…
Reference in a new issue