static DEC_TYPE IEEE_FUNCTION_NAME (DEC_TYPE x) { decContext context; decNumber dn_result; DEC_TYPE result; decNumber dn_x; decNumber dn_one; decNumber dn_exponent; DEC_TYPE one = DFP_CONSTANT(1.0); FUNC_CONVERT_TO_DN(&x, &dn_x); FUNC_CONVERT_TO_DN(&one, &dn_one); if (decNumberIsNaN (&dn_x)) return x+x; if (decNumberIsInfinite (&dn_x)) return decNumberIsNegative (&dn_x) ? DFP_CONSTANT(-1.0) : x; decContextDefault(&context, DEFAULT_CONTEXT); decNumberExp(&dn_exponent, &dn_x, &context); decNumberSubtract(&dn_result, &dn_exponent, &dn_one, &context); FUNC_CONVERT_FROM_DN(&dn_result, &result, &context); if (context.status & DEC_Overflow) DFP_EXCEPT (FE_OVERFLOW); return result; }
void* decSingleExp (void* _0, const void* _1, decContext* ctx) noexcept { decNumber _0num; decNumber _1num; decSingleToNumber (_1, &_1num); decNumberExp (&_0num, &_1num, ctx); return decSingleFromNumber (_0, &_0num, ctx); }
DecimalDecNumber exp(const DecimalDecNumber &val) { decContext contextMath; decContextDefault(&contextMath, DEC_INIT_BASE); // initialize contextMath.traps=0; // no traps, thank you contextMath.digits=DECNUMDIGITS; // set precision contextMath.emax = 1000000 - 1; // Max for mathematical functions like exp contextMath.emin = -contextMath.emax; // Max for mathematical functions DecimalDecNumber result; decNumberExp(&result.m_value, &val.m_value, &contextMath); return result; }