+++ /dev/null
-/* { dg-do run { target { ! ia32 } } } */
-/* { dg-options "-O0 -mfpmath=sse" } */
-/* { dg-require-effective-target fenv } */
-/* { dg-require-effective-target dfp } */
-
-#include <fenv.h>
-
-int main() {
- fesetround( FE_UPWARD );
- _Decimal128 x1 = 9825, x2 = 10000 ;
-
- double c = (double) (x1 / x2);
-
- if (c != 0.9825)
- __builtin_abort ();
-
- return 0 ;
-}
#define BID_128RES
#include "bid_div_macros.h"
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
+#include <fenv.h>
+
#define FE_ALL_FLAGS FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT
#endif
-#include <stdio.h>
-#include <fenv.h>
extern UINT32 convert_table[5][128][2];
extern SINT8 factors[][2];
extern UINT8 packed_10000_zeros[];
-
BID128_FUNCTION_ARG2 (bid128_div, x, y)
UINT256 CA4, CA4r, P256;
digits_q, amount;
int nzeros, i, j, k, d5;
unsigned rmode;
- int old_rm, rm_changed=0;
-
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
fexcept_t binaryflags = 0;
#endif
-// Set it to round-to-nearest (if different)
-if ((old_rm=fegetround()) != FE_TONEAREST) {
- rm_changed=1;
- fesetround(FE_TONEAREST);
-}
-
valid_y = unpack_BID128_value (&sign_y, &exponent_y, &CY, y);
// unpack arguments, check for NaN or Infinity
#endif
res.w[1] = (CX.w[1]) & QUIET_MASK64;
res.w[0] = CX.w[0];
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// x is Infinity?
#endif
res.w[1] = 0x7c00000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// y is NaN?
res.w[1] = ((x.w[1] ^ y.w[1]) & 0x8000000000000000ull) |
0x7800000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
// x=y=0, return NaN
res.w[1] = 0x7c00000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// return 0
exponent_x = 0;
res.w[1] |= (((UINT64) exponent_x) << 49);
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
#endif
res.w[1] = CY.w[1] & QUIET_MASK64;
res.w[0] = CY.w[0];
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// y is Infinity?
// return +/-0
res.w[1] = sign_x ^ sign_y;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// y is 0, return +/-Inf
res.w[1] =
((x.w[1] ^ y.w[1]) & 0x8000000000000000ull) | 0x7800000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// get number of decimal digits in CQ
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#endif
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
-// restore the rounding mode back if it has been changed
-if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
digits_q, amount;
int nzeros, i, j, k, d5;
unsigned rmode;
- int old_rm, rm_changed=0;
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
fexcept_t binaryflags = 0;
#endif
-// Set it to round-to-nearest (if different)
-if ((old_rm=fegetround()) != FE_TONEAREST) {
- rm_changed=1;
- fesetround(FE_TONEAREST);
-}
-
valid_y = unpack_BID64 (&sign_y, &exponent_y, &CY.w[0], y);
// unpack arguments, check for NaN or Infinity
res.w[0] = (CX.w[0] & 0x0003ffffffffffffull);
__mul_64x64_to_128 (res, res.w[0], power10_table_128[18].w[0]);
res.w[1] |= ((CX.w[0]) & 0xfc00000000000000ull);
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// x is Infinity?
#endif
res.w[1] = 0x7c00000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
- BID_RETURN (res);
+ BID_RETURN (res);
}
if ((((y) & 0x7c00000000000000ull) != 0x7c00000000000000ull)) {
// otherwise return +/-Inf
res.w[1] =
(((x) ^ (y)) & 0x8000000000000000ull) | 0x7800000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
// x=y=0, return NaN
res.w[1] = 0x7c00000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// return 0
exponent_x = 0;
res.w[1] |= (((UINT64) exponent_x) << 49);
res.w[0] = 0;
-// restore the rounding mode back if it has been changed
-if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
res.w[0] = (CY.w[0] & 0x0003ffffffffffffull);
__mul_64x64_to_128 (res, res.w[0], power10_table_128[18].w[0]);
res.w[1] |= ((CY.w[0]) & 0xfc00000000000000ull);
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
- BID_RETURN (res);
+ BID_RETURN (res);
}
// y is Infinity?
if (((y) & 0x7800000000000000ull) == 0x7800000000000000ull) {
// return +/-0
res.w[1] = sign_x ^ sign_y;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// y is 0, return +/-Inf
#ifdef SET_STATUS_FLAGS
__set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// get number of decimal digits in CQ
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#endif
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
-// restore the rounding mode back if it has been changed
-if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
digits_q, amount;
int nzeros, i, j, k, d5;
unsigned rmode;
- int old_rm, rm_changed=0;
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
fexcept_t binaryflags = 0;
#endif
-// Set it to round-to-nearest (if different)
-if ((old_rm=fegetround()) != FE_TONEAREST) {
- rm_changed=1;
- fesetround(FE_TONEAREST);
-}
-
valid_y = unpack_BID128_value (&sign_y, &exponent_y, &CY, y);
// unpack arguments, check for NaN or Infinity
res.w[0] = (CX.w[0] & 0x0003ffffffffffffull);
__mul_64x64_to_128 (res, res.w[0], power10_table_128[18].w[0]);
res.w[1] |= ((CX.w[0]) & 0xfc00000000000000ull);
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// x is Infinity?
#endif
res.w[1] = 0x7c00000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
if (((y.w[1] & 0x7c00000000000000ull) != 0x7c00000000000000ull)) {
res.w[1] =
((x ^ y.w[1]) & 0x8000000000000000ull) | 0x7800000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
// x=y=0, return NaN
res.w[1] = 0x7c00000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// return 0
exponent_x = 0;
res.w[1] |= (((UINT64) exponent_x) << 49);
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
#endif
res.w[1] = CY.w[1] & QUIET_MASK64;
res.w[0] = CY.w[0];
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// y is Infinity?
// return +/-0
res.w[1] = sign_x ^ sign_y;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// y is 0, return +/-Inf
#ifdef SET_STATUS_FLAGS
__set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// get number of decimal digits in CQ
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#endif
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
-// restore the rounding mode back if it has been changed
-if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
int exponent_x, exponent_y, bin_index, bin_expon, diff_expon, ed2,
digits_q, amount;
int nzeros, i, j, k, d5, rmode;
- int old_rm, rm_changed=0;
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
fexcept_t binaryflags = 0;
#endif
-// Set it to round-to-nearest (if different)
-if ((old_rm=fegetround()) != FE_TONEAREST) {
- rm_changed=1;
- fesetround(FE_TONEAREST);
-}
valid_y = unpack_BID64 (&sign_y, &exponent_y, &CY.w[0], y);
// unpack arguments, check for NaN or Infinity
#endif
res.w[1] = (CX.w[1]) & QUIET_MASK64;
res.w[0] = CX.w[0];
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// x is Infinity?
#endif
res.w[1] = 0x7c00000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// y is NaN?
res.w[1] = ((x.w[1] ^ y) & 0x8000000000000000ull) |
0x7800000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
// x=y=0, return NaN
res.w[1] = 0x7c00000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// return 0
exponent_x = 0;
res.w[1] |= (((UINT64) exponent_x) << 49);
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
res.w[0] = (CY.w[0] & 0x0003ffffffffffffull);
__mul_64x64_to_128 (res, res.w[0], power10_table_128[18].w[0]);
res.w[1] |= ((CY.w[0]) & 0xfc00000000000000ull);
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
- BID_RETURN (res);
+ BID_RETURN (res);
}
// y is Infinity?
if ((y & INFINITY_MASK64) == INFINITY_MASK64) {
// return +/-0
res.w[1] = ((x.w[1] ^ y) & 0x8000000000000000ull);
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// y is 0
#endif
res.w[1] = (sign_x ^ sign_y) | INFINITY_MASK64;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// get number of decimal digits in CQ
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#endif
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
-// restore the rounding mode back if it has been changed
-if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#define BID_128RES
#include "bid_div_macros.h"
-#include <fenv.h>
BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (UINT128, bid128_rem, x, y)
int_float f64, fx;
int exponent_x, exponent_y, diff_expon, bin_expon_cx, scale,
scale0;
- int old_rm, rm_changed=0;
// unpack arguments, check for NaN or Infinity
-// Set it to round-to-nearest (if different)
-if ((old_rm=fegetround()) != FE_TONEAREST) {
- rm_changed=1;
- fesetround(FE_TONEAREST);
-}
-
valid_y = unpack_BID128_value (&sign_y, &exponent_y, &CY, y);
if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) {
#endif
res.w[1] = CX.w[1] & QUIET_MASK64;
res.w[0] = CX.w[0];
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// x is Infinity?
#endif
res.w[1] = 0x7c00000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// x=y=0, return NaN
res.w[1] = 0x7c00000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
if (valid_y || ((y.w[1] & NAN_MASK64) == INFINITY_MASK64)) {
res.w[1] = sign_x | (((UINT64) exponent_x) << 49);
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
#endif
res.w[1] = CY.w[1] & QUIET_MASK64;
res.w[0] = CY.w[0];
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// y is Infinity?
// return x
res.w[1] = x.w[1];
res.w[0] = x.w[0];
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// y is 0
#endif
res.w[1] = 0x7c00000000000000ull;
res.w[0] = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
if (diff_expon > 34) {
// |x|<|y| in this case
res = x;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// set exponent of y to exponent_x, scale coefficient_y
if (P256.w[2] || P256.w[3]) {
// |x|<|y| in this case
res = x;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
if (__unsigned_compare_ge_128 (P256, CX2)) {
// |x|<|y| in this case
res = x;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
get_BID128_very_fast (&res, sign_x, exponent_x, CR);
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// 2^64
// check for remainder == 0
if (!CX.w[1] && !CX.w[0]) {
get_BID128_very_fast (&res, sign_x, exponent_y, CX);
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
}
get_BID128_very_fast (&res, sign_x, exponent_y, CX);
-// restore the rounding mode back if it has been changed
-if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#define BID_128RES
#include "bid_internal.h"
#include "bid_sqrt_macros.h"
-#include <fenv.h>
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
+#include <fenv.h>
+
#define FE_ALL_FLAGS FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT
#endif
int_float fx, f64;
int exponent_x, bin_expon_cx;
int digits, scale, exponent_q;
- int old_rm, rm_changed=0;
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
fexcept_t binaryflags = 0;
#endif
-// Set it to round-to-nearest (if different)
-if ((old_rm=fegetround()) != FE_TONEAREST) {
- rm_changed=1;
- fesetround(FE_TONEAREST);
-}
-
// unpack arguments, check for NaN or Infinity
if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) {
res.w[1] = CX.w[1];
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
res.w[1] = CX.w[1] & QUIET_MASK64;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// x is Infinity?
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
}
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// x is 0 otherwise
sign_x |
((((UINT64) (exponent_x + DECIMAL_EXPONENT_BIAS_128)) >> 1) << 49);
res.w[0] = 0;
-// restore the rounding mode back if it has been changed
-if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
if (sign_x) {
#ifdef SET_STATUS_FLAGS
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
-// restore the rounding mode back if it has been changed
-if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
int_float fx, f64;
int exponent_x, bin_expon_cx;
int digits, scale, exponent_q;
- int old_rm, rm_changed=0;
-
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
fexcept_t binaryflags = 0;
#endif
-// Set it to round-to-nearest (if different)
-if ((old_rm=fegetround()) != FE_TONEAREST) {
- rm_changed=1;
- fesetround(FE_TONEAREST);
-}
-
// unpack arguments, check for NaN or Infinity
// unpack arguments, check for NaN or Infinity
CX.w[1] = 0;
res.w[0] = (CX.w[0] & 0x0003ffffffffffffull);
__mul_64x64_to_128 (res, res.w[0], power10_table_128[18].w[0]);
res.w[1] |= ((CX.w[0]) & 0xfc00000000000000ull);
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// x is Infinity?
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
}
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// x is 0 otherwise
sign_x | ((((UINT64) (exponent_x + DECIMAL_EXPONENT_BIAS_128)) >> 1)
<< 49);
res.w[0] = 0;
-// restore the rounding mode back if it has been changed
-if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
if (sign_x) {
#ifdef SET_STATUS_FLAGS
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
-// restore the rounding mode back if it has been changed
-if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
+
}
#include "bid_internal.h"
#include "bid_div_macros.h"
-#include <fenv.h>
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
+#include <fenv.h>
+
#define FE_ALL_FLAGS FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT
#endif
extern SINT8 factors[][2];
extern UINT8 packed_10000_zeros[];
+
#if DECIMAL_CALL_BY_REFERENCE
void
int rmode, amount;
int nzeros, i, j, k, d5;
UINT32 QX32, tdigit[3], digit, digit_h, digit_low;
- int old_rm, rm_changed=0;
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
fexcept_t binaryflags = 0;
#endif
y = *py;
#endif
- // Set it to round-to-nearest (if different)
- if ((old_rm=fegetround()) != FE_TONEAREST) {
- rm_changed=1;
- fesetround(FE_TONEAREST);
- }
-
valid_x = unpack_BID64 (&sign_x, &exponent_x, &coefficient_x, x);
valid_y = unpack_BID64 (&sign_y, &exponent_y, &coefficient_y, y);
if ((x & SNAN_MASK64) == SNAN_MASK64) // sNaN
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (coefficient_x & QUIET_MASK64);
}
// x is Infinity?
#ifdef SET_STATUS_FLAGS
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (NAN_MASK64);
}
} else {
// otherwise return +/-Inf
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (((x ^ y) & 0x8000000000000000ull) |
INFINITY_MASK64);
}
#ifdef SET_STATUS_FLAGS
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (NAN_MASK64);
}
if (((y & INFINITY_MASK64) != INFINITY_MASK64)) {
exponent_x = DECIMAL_MAX_EXPON_64;
else if (exponent_x < 0)
exponent_x = 0;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN ((sign_x ^ sign_y) | (((UINT64) exponent_x) << 53));
}
if ((y & SNAN_MASK64) == SNAN_MASK64) // sNaN
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (coefficient_y & QUIET_MASK64);
}
// y is Infinity?
if ((y & INFINITY_MASK64) == INFINITY_MASK64) {
// return +/-0
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (((x ^ y) & 0x8000000000000000ull));
}
// y is 0
#ifdef SET_STATUS_FLAGS
__set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN ((sign_x ^ sign_y) | INFINITY_MASK64);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// get decimal digits of Q
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
} else {
// UF occurs
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
digits_q, amount;
int nzeros, i, j, k, d5, done = 0;
unsigned rmode;
-int old_rm, rm_changed=0;
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
fexcept_t binaryflags = 0;
#endif
-// Set it to round-to-nearest (if different)
-if ((old_rm=fegetround()) != FE_TONEAREST) {
- rm_changed=1;
- fesetround(FE_TONEAREST);
-}
-
valid_y = unpack_BID128_value (&sign_y, &exponent_y, &CY, y);
// unpack arguments, check for NaN or Infinity
// test if x is NaN
if (((x) & 0x7c00000000000000ull) == 0x7c00000000000000ull) {
res = CX.w[0];
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res & QUIET_MASK64);
}
// x is Infinity?
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
res = 0x7c00000000000000ull;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
- BID_RETURN (res);
- }
- if (((y.w[1] & 0x7c00000000000000ull) != 0x7c00000000000000ull)) {
- // otherwise return +/-Inf
- res =
- (((x) ^ y.w[1]) & 0x8000000000000000ull) | 0x7800000000000000ull;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
+ if (((y.w[1] & 0x7c00000000000000ull) != 0x7c00000000000000ull)) {
+ // otherwise return +/-Inf
+ res =
+ (((x) ^ y.w[1]) & 0x8000000000000000ull) | 0x7800000000000000ull;
+ BID_RETURN (res);
+ }
}
// x is 0
if ((y.w[1] & INFINITY_MASK64) != INFINITY_MASK64) {
#endif
// x=y=0, return NaN
res = 0x7c00000000000000ull;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// return 0
else if (exponent_x < 0)
exponent_x = 0;
res |= (((UINT64) exponent_x) << 53);
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
amount = recip_scale[18];
__shr_128 (Tmp, Qh, amount);
res = (CY.w[1] & 0xfc00000000000000ull) | Tmp.w[0];
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// y is Infinity?
if ((y.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) {
// return +/-0
res = sign_x ^ sign_y;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// y is 0, return +/-Inf
#ifdef SET_STATUS_FLAGS
__set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
}
- if(diff_expon>=0){
- res =
- fast_get_BID64_check_OF (sign_x ^ sign_y, diff_expon, CQ.w[0],
- rnd_mode, pfpsf);
+ if(diff_expon>=0){
+ res =
+ fast_get_BID64_check_OF (sign_x ^ sign_y, diff_expon, CQ.w[0],
+ rnd_mode, pfpsf);
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
- BID_RETURN (res);
- }
+ BID_RETURN (res);
+ }
}
#endif
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
} else {
// UF occurs
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
+
}
}
digits_q, amount;
int nzeros, i, j, k, d5, done = 0;
unsigned rmode;
-int old_rm, rm_changed=0;
-
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
fexcept_t binaryflags = 0;
#endif
-// Set it to round-to-nearest (if different)
-if ((old_rm=fegetround()) != FE_TONEAREST) {
- rm_changed=1;
- fesetround(FE_TONEAREST);
-}
-
valid_y = unpack_BID64 (&sign_y, &exponent_y, &CY.w[0], (y));
// unpack arguments, check for NaN or Infinity
amount = recip_scale[18];
__shr_128 (Tmp, Qh, amount);
res = (CX.w[1] & 0xfc00000000000000ull) | Tmp.w[0];
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
- BID_RETURN (res);
+ BID_RETURN (res);
}
// x is Infinity?
if ((x.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) {
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
res = 0x7c00000000000000ull;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
- BID_RETURN (res);
- }
- if (((y & 0x7c00000000000000ull) != 0x7c00000000000000ull)) {
- // otherwise return +/-Inf
- res =
- ((x.w[1] ^ (y)) & 0x8000000000000000ull) | 0x7800000000000000ull;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
+ if (((y & 0x7c00000000000000ull) != 0x7c00000000000000ull)) {
+ // otherwise return +/-Inf
+ res =
+ ((x.w[1] ^ (y)) & 0x8000000000000000ull) | 0x7800000000000000ull;
+ BID_RETURN (res);
+ }
}
// x is 0
if (((y & INFINITY_MASK64) != INFINITY_MASK64) &&
#endif
// x=y=0, return NaN
res = 0x7c00000000000000ull;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// return 0
if (((y & 0x7800000000000000ull) != 0x7800000000000000ull)) {
- if (!CY.w[0]) {
+ if (!CY.w[0]) {
#ifdef SET_STATUS_FLAGS
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
res = 0x7c00000000000000ull;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
- }
+ }
exponent_x =
exponent_x - exponent_y - DECIMAL_EXPONENT_BIAS_128 +
(DECIMAL_EXPONENT_BIAS << 1);
else if (exponent_x < 0)
exponent_x = 0;
res = (sign_x ^ sign_y) | (((UINT64) exponent_x) << 53);
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
if ((y & SNAN_MASK64) == SNAN_MASK64) // sNaN
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (CY.w[0] & QUIET_MASK64);
}
// y is Infinity?
if (((y) & 0x7800000000000000ull) == 0x7800000000000000ull) {
// return +/-0
res = sign_x ^ sign_y;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// y is 0, return +/-Inf
#ifdef SET_STATUS_FLAGS
__set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#endif
#ifndef LEAVE_TRAILING_ZEROS
// check whether result is exact
- {
- if(!done) {
- // check whether CX, CY are short
- if (!CX.w[1] && !CY.w[1] && (CX.w[0] <= 1024) && (CY.w[0] <= 1024)) {
- i = (int) CY.w[0] - 1;
- j = (int) CX.w[0] - 1;
- // difference in powers of 2 factors for Y and X
- nzeros = ed2 - factors[i][0] + factors[j][0];
- // difference in powers of 5 factors
- d5 = ed2 - factors[i][1] + factors[j][1];
- if (d5 < nzeros)
- nzeros = d5;
+ {
+ if(!done) {
+ // check whether CX, CY are short
+ if (!CX.w[1] && !CY.w[1] && (CX.w[0] <= 1024) && (CY.w[0] <= 1024)) {
+ i = (int) CY.w[0] - 1;
+ j = (int) CX.w[0] - 1;
+ // difference in powers of 2 factors for Y and X
+ nzeros = ed2 - factors[i][0] + factors[j][0];
+ // difference in powers of 5 factors
+ d5 = ed2 - factors[i][1] + factors[j][1];
+ if (d5 < nzeros)
+ nzeros = d5;
+ // get P*(2^M[extra_digits])/10^extra_digits
+ __mul_128x128_high (Qh, CQ, reciprocals10_128[nzeros]);
+ //__mul_128x128_to_256(P256, CQ, reciprocals10_128[nzeros]);Qh.w[1]=P256.w[3];Qh.w[0]=P256.w[2];
+
+ // now get P/10^extra_digits: shift Q_high right by M[extra_digits]-128
+ amount = recip_scale[nzeros];
+ __shr_128_long (CQ, Qh, amount);
+
+ diff_expon += nzeros;
+ } else {
+ // decompose Q as Qh*10^17 + Ql
+ //T128 = reciprocals10_128[17];
+ Q_low = CQ.w[0];
+
+ {
+ tdigit[0] = Q_low & 0x3ffffff;
+ tdigit[1] = 0;
+ QX = Q_low >> 26;
+ QX32 = QX;
+ nzeros = 0;
+
+ for (j = 0; QX32; j++, QX32 >>= 7) {
+ k = (QX32 & 127);
+ tdigit[0] += convert_table[j][k][0];
+ tdigit[1] += convert_table[j][k][1];
+ if (tdigit[0] >= 100000000) {
+ tdigit[0] -= 100000000;
+ tdigit[1]++;
+ }
+ }
+
+ if (tdigit[1] >= 100000000) {
+ tdigit[1] -= 100000000;
+ if (tdigit[1] >= 100000000)
+ tdigit[1] -= 100000000;
+ }
+
+ digit = tdigit[0];
+ if (!digit && !tdigit[1])
+ nzeros += 16;
+ else {
+ if (!digit) {
+ nzeros += 8;
+ digit = tdigit[1];
+ }
+ // decompose digit
+ PD = (UINT64) digit *0x068DB8BBull;
+ digit_h = (UINT32) (PD >> 40);
+ digit_low = digit - digit_h * 10000;
+
+ if (!digit_low)
+ nzeros += 4;
+ else
+ digit_h = digit_low;
+
+ if (!(digit_h & 1))
+ nzeros +=
+ 3 & (UINT32) (packed_10000_zeros[digit_h >> 3] >>
+ (digit_h & 7));
+ }
+
+ if (nzeros) {
// get P*(2^M[extra_digits])/10^extra_digits
__mul_128x128_high (Qh, CQ, reciprocals10_128[nzeros]);
- //__mul_128x128_to_256(P256, CQ, reciprocals10_128[nzeros]);Qh.w[1]=P256.w[3];Qh.w[0]=P256.w[2];
// now get P/10^extra_digits: shift Q_high right by M[extra_digits]-128
amount = recip_scale[nzeros];
- __shr_128_long (CQ, Qh, amount);
-
- diff_expon += nzeros;
- } else {
- // decompose Q as Qh*10^17 + Ql
- //T128 = reciprocals10_128[17];
- Q_low = CQ.w[0];
-
- {
- tdigit[0] = Q_low & 0x3ffffff;
- tdigit[1] = 0;
- QX = Q_low >> 26;
- QX32 = QX;
- nzeros = 0;
-
- for (j = 0; QX32; j++, QX32 >>= 7) {
- k = (QX32 & 127);
- tdigit[0] += convert_table[j][k][0];
- tdigit[1] += convert_table[j][k][1];
- if (tdigit[0] >= 100000000) {
- tdigit[0] -= 100000000;
- tdigit[1]++;
- }
- }
-
- if (tdigit[1] >= 100000000) {
- tdigit[1] -= 100000000;
- if (tdigit[1] >= 100000000)
- tdigit[1] -= 100000000;
- }
-
- digit = tdigit[0];
- if (!digit && !tdigit[1])
- nzeros += 16;
- else {
- if (!digit) {
- nzeros += 8;
- digit = tdigit[1];
- }
- // decompose digit
- PD = (UINT64) digit *0x068DB8BBull;
- digit_h = (UINT32) (PD >> 40);
- digit_low = digit - digit_h * 10000;
-
- if (!digit_low)
- nzeros += 4;
- else
- digit_h = digit_low;
-
- if (!(digit_h & 1))
- nzeros +=
- 3 & (UINT32) (packed_10000_zeros[digit_h >> 3] >>
- (digit_h & 7));
- }
-
- if (nzeros) {
- // get P*(2^M[extra_digits])/10^extra_digits
- __mul_128x128_high (Qh, CQ, reciprocals10_128[nzeros]);
-
- // now get P/10^extra_digits: shift Q_high right by M[extra_digits]-128
- amount = recip_scale[nzeros];
- __shr_128 (CQ, Qh, amount);
- }
- diff_expon += nzeros;
-
- }
+ __shr_128 (CQ, Qh, amount);
}
+ diff_expon += nzeros;
+
}
- if(diff_expon>=0){
- res =
- fast_get_BID64_check_OF (sign_x ^ sign_y, diff_expon, CQ.w[0],
- rnd_mode, pfpsf);
+ }
+ }
+ if(diff_expon>=0){
+ res =
+ fast_get_BID64_check_OF (sign_x ^ sign_y, diff_expon, CQ.w[0],
+ rnd_mode, pfpsf);
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
- (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
+ (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
- BID_RETURN (res);
- }
- }
+ BID_RETURN (res);
+ }
+ }
#endif
if (diff_expon >= 0) {
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
} else {
// UF occurs
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
+
}
}
digits_q, amount;
int nzeros, i, j, k, d5, done = 0;
unsigned rmode;
-int old_rm, rm_changed=0;
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
fexcept_t binaryflags = 0;
#endif
-// Set it to round-to-nearest (if different)
-if ((old_rm=fegetround()) != FE_TONEAREST) {
- rm_changed=1;
- fesetround(FE_TONEAREST);
-}
-
valid_y = unpack_BID128_value (&sign_y, &exponent_y, &CY, y);
// unpack arguments, check for NaN or Infinity
amount = recip_scale[18];
__shr_128 (Tmp, Qh, amount);
res = (CX.w[1] & 0xfc00000000000000ull) | Tmp.w[0];
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
- BID_RETURN (res);
+ BID_RETURN (res);
}
// x is Infinity?
if ((x.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) {
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
res = 0x7c00000000000000ull;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
- BID_RETURN (res);
- }
- if (((y.w[1] & 0x7c00000000000000ull) != 0x7c00000000000000ull)) {
- // otherwise return +/-Inf
- res =
- ((x.w[1] ^ y.
- w[1]) & 0x8000000000000000ull) | 0x7800000000000000ull;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
+ if (((y.w[1] & 0x7c00000000000000ull) != 0x7c00000000000000ull)) {
+ // otherwise return +/-Inf
+ res =
+ ((x.w[1] ^ y.
+ w[1]) & 0x8000000000000000ull) | 0x7800000000000000ull;
+ BID_RETURN (res);
+ }
}
// x is 0
if (((y.w[1] & 0x7800000000000000ull) != 0x7800000000000000ull)) {
#endif
// x=y=0, return NaN
res = 0x7c00000000000000ull;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// return 0
else if (exponent_x < 0)
exponent_x = 0;
res |= (((UINT64) exponent_x) << 53);
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
amount = recip_scale[18];
__shr_128 (Tmp, Qh, amount);
res = (CY.w[1] & 0xfc00000000000000ull) | Tmp.w[0];
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
- BID_RETURN (res);
+ BID_RETURN (res);
}
// y is Infinity?
if ((y.w[1] & 0x7800000000000000ull) == 0x7800000000000000ull) {
// return +/-0
res = sign_x ^ sign_y;
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// y is 0, return +/-Inf
#ifdef SET_STATUS_FLAGS
__set_status_flags (pfpsf, ZERO_DIVIDE_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifndef LEAVE_TRAILING_ZEROS
// check whether result is exact
{
- if(!done) {
- // check whether CX, CY are short
- if (!CX.w[1] && !CY.w[1] && (CX.w[0] <= 1024) && (CY.w[0] <= 1024)) {
- i = (int) CY.w[0] - 1;
- j = (int) CX.w[0] - 1;
- // difference in powers of 2 factors for Y and X
- nzeros = ed2 - factors[i][0] + factors[j][0];
- // difference in powers of 5 factors
- d5 = ed2 - factors[i][1] + factors[j][1];
- if (d5 < nzeros)
- nzeros = d5;
- // get P*(2^M[extra_digits])/10^extra_digits
- __mul_128x128_high (Qh, CQ, reciprocals10_128[nzeros]);
- //__mul_128x128_to_256(P256, CQ, reciprocals10_128[nzeros]);Qh.w[1]=P256.w[3];Qh.w[0]=P256.w[2];
-
- // now get P/10^extra_digits: shift Q_high right by M[extra_digits]-128
- amount = recip_scale[nzeros];
- __shr_128_long (CQ, Qh, amount);
-
- diff_expon += nzeros;
- } else {
- // decompose Q as Qh*10^17 + Ql
- //T128 = reciprocals10_128[17];
- Q_low = CQ.w[0];
-
- {
- tdigit[0] = Q_low & 0x3ffffff;
- tdigit[1] = 0;
- QX = Q_low >> 26;
- QX32 = QX;
- nzeros = 0;
-
- for (j = 0; QX32; j++, QX32 >>= 7) {
- k = (QX32 & 127);
- tdigit[0] += convert_table[j][k][0];
- tdigit[1] += convert_table[j][k][1];
- if (tdigit[0] >= 100000000) {
- tdigit[0] -= 100000000;
- tdigit[1]++;
- }
+ if(!done) {
+ // check whether CX, CY are short
+ if (!CX.w[1] && !CY.w[1] && (CX.w[0] <= 1024) && (CY.w[0] <= 1024)) {
+ i = (int) CY.w[0] - 1;
+ j = (int) CX.w[0] - 1;
+ // difference in powers of 2 factors for Y and X
+ nzeros = ed2 - factors[i][0] + factors[j][0];
+ // difference in powers of 5 factors
+ d5 = ed2 - factors[i][1] + factors[j][1];
+ if (d5 < nzeros)
+ nzeros = d5;
+ // get P*(2^M[extra_digits])/10^extra_digits
+ __mul_128x128_high (Qh, CQ, reciprocals10_128[nzeros]);
+ //__mul_128x128_to_256(P256, CQ, reciprocals10_128[nzeros]);Qh.w[1]=P256.w[3];Qh.w[0]=P256.w[2];
+
+ // now get P/10^extra_digits: shift Q_high right by M[extra_digits]-128
+ amount = recip_scale[nzeros];
+ __shr_128_long (CQ, Qh, amount);
+
+ diff_expon += nzeros;
+ } else {
+ // decompose Q as Qh*10^17 + Ql
+ //T128 = reciprocals10_128[17];
+ Q_low = CQ.w[0];
+
+ {
+ tdigit[0] = Q_low & 0x3ffffff;
+ tdigit[1] = 0;
+ QX = Q_low >> 26;
+ QX32 = QX;
+ nzeros = 0;
+
+ for (j = 0; QX32; j++, QX32 >>= 7) {
+ k = (QX32 & 127);
+ tdigit[0] += convert_table[j][k][0];
+ tdigit[1] += convert_table[j][k][1];
+ if (tdigit[0] >= 100000000) {
+ tdigit[0] -= 100000000;
+ tdigit[1]++;
}
+ }
- if (tdigit[1] >= 100000000) {
+ if (tdigit[1] >= 100000000) {
+ tdigit[1] -= 100000000;
+ if (tdigit[1] >= 100000000)
tdigit[1] -= 100000000;
- if (tdigit[1] >= 100000000)
- tdigit[1] -= 100000000;
- }
+ }
- digit = tdigit[0];
- if (!digit && !tdigit[1])
- nzeros += 16;
- else {
- if (!digit) {
- nzeros += 8;
- digit = tdigit[1];
- }
- // decompose digit
- PD = (UINT64) digit *0x068DB8BBull;
- digit_h = (UINT32) (PD >> 40);
- digit_low = digit - digit_h * 10000;
-
- if (!digit_low)
- nzeros += 4;
- else
- digit_h = digit_low;
-
- if (!(digit_h & 1))
- nzeros +=
- 3 & (UINT32) (packed_10000_zeros[digit_h >> 3] >>
- (digit_h & 7));
+ digit = tdigit[0];
+ if (!digit && !tdigit[1])
+ nzeros += 16;
+ else {
+ if (!digit) {
+ nzeros += 8;
+ digit = tdigit[1];
}
+ // decompose digit
+ PD = (UINT64) digit *0x068DB8BBull;
+ digit_h = (UINT32) (PD >> 40);
+ digit_low = digit - digit_h * 10000;
+
+ if (!digit_low)
+ nzeros += 4;
+ else
+ digit_h = digit_low;
- if (nzeros) {
- // get P*(2^M[extra_digits])/10^extra_digits
- __mul_128x128_high (Qh, CQ, reciprocals10_128[nzeros]);
+ if (!(digit_h & 1))
+ nzeros +=
+ 3 & (UINT32) (packed_10000_zeros[digit_h >> 3] >>
+ (digit_h & 7));
+ }
- // now get P/10^extra_digits: shift Q_high right by M[extra_digits]-128
- amount = recip_scale[nzeros];
- __shr_128 (CQ, Qh, amount);
- }
- diff_expon += nzeros;
+ if (nzeros) {
+ // get P*(2^M[extra_digits])/10^extra_digits
+ __mul_128x128_high (Qh, CQ, reciprocals10_128[nzeros]);
+ // now get P/10^extra_digits: shift Q_high right by M[extra_digits]-128
+ amount = recip_scale[nzeros];
+ __shr_128 (CQ, Qh, amount);
}
+ diff_expon += nzeros;
+
}
}
- if(diff_expon>=0){
- res =
- fast_get_BID64_check_OF (sign_x ^ sign_y, diff_expon, CQ.w[0],
- rnd_mode, pfpsf);
+ }
+ if(diff_expon>=0){
+ res =
+ fast_get_BID64_check_OF (sign_x ^ sign_y, diff_expon, CQ.w[0],
+ rnd_mode, pfpsf);
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
- (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
+ (void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
- BID_RETURN (res);
- }
+ BID_RETURN (res);
+ }
}
#endif
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
} else {
// UF occurs
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
+
}
}
#include "bid_internal.h"
#include "bid_sqrt_macros.h"
-#include <fenv.h>
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
+#include <fenv.h>
+
#define FE_ALL_FLAGS FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW|FE_INEXACT
#endif
int exponent_x, exponent_q, bin_expon_cx;
int digits_x;
int scale;
- int old_rm, rm_changed=0;
-
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
fexcept_t binaryflags = 0;
#endif
x = *px;
#endif
- // Set it to round-to-nearest (if different)
- if ((old_rm=fegetround()) != FE_TONEAREST) {
- rm_changed=1;
- fesetround(FE_TONEAREST);
- }
-
// unpack arguments, check for NaN or Infinity
if (!unpack_BID64 (&sign_x, &exponent_x, &coefficient_x, x)) {
// x is Inf. or NaN or 0
if ((x & SNAN_MASK64) == SNAN_MASK64) // sNaN
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res & QUIET_MASK64);
}
// x is 0
exponent_x = (exponent_x + DECIMAL_EXPONENT_BIAS) >> 1;
res = sign_x | (((UINT64) exponent_x) << 53);
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// x<0?
#ifdef SET_STATUS_FLAGS
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// if exponent is odd, scale coefficient by 10
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
fexcept_t binaryflags = 0;
#endif
-int old_rm, rm_changed=0;
-
-// Set it to round-to-nearest (if different)
-if ((old_rm=fegetround()) != FE_TONEAREST) {
- rm_changed=1;
- fesetround(FE_TONEAREST);
-}
// unpack arguments, check for NaN or Infinity
if (!unpack_BID128_value (&sign_x, &exponent_x, &CX, x)) {
amount = recip_scale[18];
__shr_128 (Tmp, Qh, amount);
res = (CX.w[1] & 0xfc00000000000000ull) | Tmp.w[0];
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// x is Infinity?
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
}
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
// x is 0 otherwise
exponent_x = DECIMAL_MAX_EXPON_64;
//res= sign_x | (((UINT64)exponent_x)<<53);
res = get_BID64 (sign_x, exponent_x, 0, rnd_mode, pfpsf);
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
if (sign_x) {
#ifdef SET_STATUS_FLAGS
__set_status_flags (pfpsf, INVALID_EXCEPTION);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
- // restore the rounding mode back if it has been changed
- if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
}
}
#ifdef UNCHANGED_BINARY_STATUS_FLAGS
(void) fesetexceptflag (&binaryflags, FE_ALL_FLAGS);
#endif
-// restore the rounding mode back if it has been changed
-if (rm_changed) fesetround(old_rm);
BID_RETURN (res);
+
}