rpn/src/rpn-logs.h

95 lines
2.1 KiB
C
Raw Normal View History

#define _USE_MATH_DEFINES
//
void rpn_e(void)
{
2015-05-19 17:51:03 +02:00
putf(M_E);
}
void rpn_log()
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = log10(((number*)_stack->get_obj(0))->_value);
}
void rpn_alog()
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = pow(((number*)_stack->get_obj(0))->_value, 10);
}
void rpn_ln()
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = log(((number*)_stack->get_obj(0))->_value);
}
void rpn_exp()
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = exp(((number*)_stack->get_obj(0))->_value);
}
void rpn_sinh()
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = sinh(((number*)_stack->get_obj(0))->_value);
}
void rpn_asinh()
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
2015-05-19 17:51:03 +02:00
floating_t value = ((number*)_stack->get_obj(0))->_value;
if(value>0)
value = log(value + sqrt(value * value + 1));
else
value = -log(-value + sqrt(value * value + 1));
2015-05-19 17:51:03 +02:00
((number*)_stack->get_obj(0))->_value = value;
}
void rpn_cosh()
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = cosh(((number*)_stack->get_obj(0))->_value);
}
void rpn_acosh()
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
2015-05-19 17:51:03 +02:00
floating_t value = ((number*)_stack->get_obj(0))->_value;
if(value>0)
value = log(value + sqrt(value * value - 1));
else
value = -log(-value + sqrt(value * value - 1));
2015-05-19 17:51:03 +02:00
((number*)_stack->get_obj(0))->_value = value;
}
void rpn_tanh()
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
((number*)_stack->get_obj(0))->_value = tanh(((number*)_stack->get_obj(0))->_value);
}
void rpn_atanh()
{
2015-05-19 17:51:03 +02:00
MIN_ARGUMENTS(1);
ARG_MUST_BE_OF_TYPE(0, cmd_number);
2015-05-19 17:51:03 +02:00
floating_t value = ((number*)_stack->get_obj(0))->_value;
value = (log(1 + value) - log(1 - value)) / 2;
((number*)_stack->get_obj(0))->_value = value;
}