_RETURN_TYPE INTERNAL_FUNCTION_NAME (DEC_TYPE x) { DEC_TYPE result; decContext context; decNumber dn_result; decNumber dn_x; decNumber dn_absx; decNumber dn_logx; decNumber dn_one; decNumber dn_cmp; enum rounding round; FUNC_CONVERT_TO_DN (&x, &dn_x); if (decNumberIsZero (&dn_x)) { DFP_EXCEPT (FE_INVALID); DFP_ERRNO (EDOM); return _FBLOG0; } if (decNumberIsInfinite (&dn_x)) { DFP_EXCEPT (FE_INVALID); DFP_ERRNO (EDOM); return decNumberIsNegative (&dn_x) ? _MIN_VALUE : _MAX_VALUE; } if (decNumberIsNaN (&dn_x)) { DFP_EXCEPT (FE_INVALID); DFP_ERRNO (EDOM); return _FBLOGNAN; } decContextDefault (&context, DEFAULT_CONTEXT); decNumberAbs (&dn_absx, &dn_x, &context); /* For DFP, we use radix 10 instead of whatever FLT_RADIX happens to be */ decNumberLog10 (&dn_logx, &dn_absx, &context); /* Capture the case where truncation will return the wrong result, by rounding up if -1.0 < x < 1.0 */ round = DEC_ROUND_DOWN; decNumberFromInt32 (&dn_one, 1); decNumberCompare (&dn_cmp, &dn_x, &dn_one, &context); if (-decNumberIsNegative(&dn_cmp)) { decNumberFromInt32 (&dn_one, -1); decNumberCompare (&dn_cmp, &dn_x, &dn_one, &context); if (!decNumberIsNegative(&dn_cmp) && !decNumberIsZero(&dn_cmp)) round = DEC_ROUND_UP; } context.round = round; decNumberToIntegralValue (&dn_result, &dn_logx, &context); FUNC_CONVERT_FROM_DN (&dn_result, &result, &context); /* Use _Decimal* to int casting. */ return (_RETURN_TYPE) result; }
DEC_TYPE INTERNAL_FUNCTION_NAME (DEC_TYPE x) { DEC_TYPE z = IEEE_FUNCTION_NAME (x); if (!FUNC_D(__isfinite) (z) && FUNC_D(__isfinite) (x)) DFP_ERRNO (ERANGE); if (x < DFP_CONSTANT(0.0) && (FUNC_D (__isinf) (x) && FUNC_D (__rint) (x) == x) ) DFP_ERRNO (EDOM); return z; }
DEC_TYPE INTERNAL_FUNCTION_NAME (DEC_TYPE x) { DEC_TYPE z = IEEE_FUNCTION_NAME (x); if (x == DFP_CONSTANT(0.0)) DFP_ERRNO (ERANGE); if (x < DFP_CONSTANT(0.0)) DFP_ERRNO (EDOM); return z; }
DEC_TYPE INTERNAL_FUNCTION_NAME (DEC_TYPE x) { DEC_TYPE z = IEEE_FUNCTION_NAME (x); if (x < DFP_CONSTANT(-1.0) || x > DFP_CONSTANT(1.0)) DFP_ERRNO (EDOM); /* The normal glibc ieee754 k_standard.c file does not follow c99 or POSIX * with regard to atanh pole errors. atan(+-1.0) [the binary version] will * set errno to EDOM. Hopefully this will get worked out soon. */ if (x == DFP_CONSTANT(-1.0) || x == DFP_CONSTANT(1.0)) DFP_ERRNO (ERANGE); return z; }
DEC_TYPE INTERNAL_FUNCTION_NAME (DEC_TYPE x) { DEC_TYPE z = IEEE_FUNCTION_NAME (x); if (!FUNC_D(__isfinite) (z) && FUNC_D(__isfinite) (x)) DFP_ERRNO (ERANGE); return z; }
DEC_TYPE INTERNAL_FUNCTION_NAME (DEC_TYPE x, DEC_TYPE y) { DEC_TYPE z = IEEE_FUNCTION_NAME (x, y); /* Pole error: x = 0, y < 0 (non-inf). Set ERANGE in accordance with C99 */ if (x == DFP_CONSTANT(0.0) && FUNC_D(__isfinite)(y) && y < DFP_CONSTANT(0.0)) DFP_ERRNO (ERANGE); if (!FUNC_D(__isfinite) (z) && FUNC_D(__isfinite) (x) && FUNC_D(__isfinite) (y)) { if (FUNC_D(__isnan) (z)) /* Domain error was triggered, x < 0 and y was not an odd int */ DFP_ERRNO (EDOM); else /* Overflow */ DFP_ERRNO (ERANGE); } return z; }
DEC_TYPE INTERNAL_FUNCTION_NAME (DEC_TYPE x) { DEC_TYPE z = IEEE_FUNCTION_NAME (x); if (x > DFP_CONSTANT(1.0) || x < DFP_CONSTANT(-1.0)) DFP_ERRNO (EDOM); return z; }
__ROUND_RETURN_TYPE INTERNAL_FUNCTION_NAME (DEC_TYPE x) { __ROUND_RETURN_TYPE z = IEEE_FUNCTION_NAME (x); if (FUNC_D(__isnan) (x) || FUNC_D(__isinf) (x) || x > __MAX_VALUE || x < __MIN_VALUE) DFP_ERRNO (EDOM); return z; }
DEC_TYPE INTERNAL_FUNCTION_NAME (DEC_TYPE x) { decContext context; decNumber dn_result; DEC_TYPE result; decNumber dn_x; decNumber dn_tmp; decNumber dn_log10; decNumber dn_one; decNumber dn_cmp; enum rounding round; FUNC_CONVERT_TO_DN (&x, &dn_x); if (decNumberIsNaN (&dn_x)) return x+x; if (decNumberIsInfinite (&dn_x)) /* +-Inf: Inf */ return DEC_INFINITY; if (decNumberIsZero (&dn_x)) /* Pole Error if x==0 */ { DFP_ERRNO (ERANGE); DFP_EXCEPT (FE_DIVBYZERO); return -DFP_HUGE_VAL; } if (decNumberIsInfinite (&dn_x) && decNumberIsNegative (&dn_x)) return -x; decContextDefault (&context, DEFAULT_CONTEXT); decNumberAbs (&dn_tmp, &dn_x, &context); /* For DFP, we use radix 10 instead of whatever FLT_RADIX happens to be */ decNumberLog10 (&dn_log10, &dn_tmp, &context); /* Capture the case where truncation will return the wrong result, by rounding up if -1.0 < x < 1.0 */ round = DEC_ROUND_DOWN; decNumberFromInt32 (&dn_one, 1); decNumberCompare (&dn_cmp, &dn_x, &dn_one, &context); if (-decNumberIsNegative(&dn_cmp)) { decNumberFromInt32 (&dn_one, -1); decNumberCompare (&dn_cmp, &dn_x, &dn_one, &context); if (!decNumberIsNegative(&dn_cmp) && !decNumberIsZero(&dn_cmp)) round = DEC_ROUND_UP; } context.round = round; decNumberToIntegralValue (&dn_result, &dn_log10, &context); FUNC_CONVERT_FROM_DN (&dn_result, &result, &context); return result; }