Beispiel #1
0
static void setrounding(TaskData *taskData, Handle args)
{
    switch (get_C_long(taskData, DEREFWORDHANDLE(args)))
    {
    case POLY_ROUND_TONEAREST: fpsetround(FP_RN); break; /* Choose nearest */
    case POLY_ROUND_DOWNWARD: fpsetround(FP_RM); break; /* Towards negative infinity */
    case POLY_ROUND_UPWARD: fpsetround(FP_RP); break; /* Towards positive infinity */
    case POLY_ROUND_TOZERO: fpsetround(FP_RZ); break; /* Truncate towards zero */
    }
}
Beispiel #2
0
int test_settings(void) {
  int failures = 0;
  fp_except mask_orig;

  printf("Testing settings on the chip... ");
  fflush(stdout);

  fpsetround(FP_RM);
  if(fpgetround() != FP_RM) FAIL_TEST;
  fpsetround(FP_RP);
  if(fpgetround() != FP_RP) FAIL_TEST;
  fpsetround(FP_RZ);
  if(fpgetround() != FP_RZ) FAIL_TEST;
  fpsetround(FP_RN);
  if(fpgetround() != FP_RN) FAIL_TEST;
 
  fpsetsticky(FP_X_INV | FP_X_DZ | FP_X_IMP);
  if(fpgetsticky() != (FP_X_INV | FP_X_DZ | FP_X_IMP)) FAIL_TEST;
  fpsetsticky(FP_X_OFL | FP_X_IMP);
  if(fpgetsticky() != (FP_X_OFL | FP_X_IMP)) FAIL_TEST;
  fpsetsticky(FP_X_UFL | FP_X_DZ);
  if(fpgetsticky() != (FP_X_UFL | FP_X_DZ)) FAIL_TEST;
  fpsetsticky(0);
  if(fpgetsticky() != 0) FAIL_TEST;

  mask_orig = fpsetmask(FP_X_INV | FP_X_DZ);
  if(fpgetmask() != (FP_X_INV | FP_X_DZ)) FAIL_TEST;
  fpsetmask(FP_X_OFL | FP_X_IMP);
  if(fpgetmask() != (FP_X_OFL | FP_X_IMP)) FAIL_TEST;
  fpsetmask(FP_X_UFL | FP_X_DZ | FP_X_INV);
  if(fpgetmask() != (FP_X_UFL | FP_X_DZ | FP_X_INV)) FAIL_TEST;
  fpsetmask(mask_orig);
  if(fpgetmask() != mask_orig) FAIL_TEST;

#ifdef __CYGWIN__
  fpsetprecision(FP_PC_SGL);
  if(fpgetprecision() != FP_PC_SGL) FAIL_TEST;
  fpsetprecision(FP_PC_DBL);
  if(fpgetprecision() != FP_PC_DBL) FAIL_TEST;
  fpsetprecision(FP_PC_EXT);
  if(fpgetprecision() != FP_PC_EXT) FAIL_TEST;
#endif

  if(failures == 0) {
    printf(" PASSED\n");
    return 0;
  }
  else {
    printf(" %d failures\n", failures);
    return 1;
  }
}
Beispiel #3
0
ATF_TC_BODY(fpsetround_basic, tc)
{

#ifndef _FLOAT_IEEE754
	atf_tc_skip("Test not applicable on this architecture.");
#else
	int r;

	ATF_CHECK_EQ(r = fpgetround(), FP_RN);
	if (FP_RN != r)
		fprintf(stderr, "default expected=%s got=%s\n", getname(FP_RN),
		    getname(r));
	ATF_CHECK_EQ(FLT_ROUNDS, 1);

	for (size_t i = 0; i < __arraycount(rnd); i++) {
		const size_t j = (i + 1) & 3;
		const int o = rnd[i].rm;
		const int n = rnd[j].rm;

		ATF_CHECK_EQ(r = fpsetround(n), o);
		if (o != r)
			fprintf(stderr, "set %s expected=%s got=%s\n",
			    getname(n), getname(o), getname(r));
		ATF_CHECK_EQ(r = fpgetround(), n);
		if (n != r)
			fprintf(stderr, "get expected=%s got=%s\n", getname(n),
			    getname(r));
		ATF_CHECK_EQ(r = FLT_ROUNDS, rnd[j].rf);
		if (r != rnd[j].rf)
			fprintf(stderr, "rounds expected=%x got=%x\n",
			    rnd[j].rf, r);
		test(r);
	}
#endif /* _FLOAT_IEEE754 */
}
Beispiel #4
0
void
TclpInitPlatform()
{
    tclPlatform = TCL_PLATFORM_UNIX;

    /*
     * The code below causes SIGPIPE (broken pipe) errors to
     * be ignored.  This is needed so that Tcl processes don't
     * die if they create child processes (e.g. using "exec" or
     * "open") that terminate prematurely.  The signal handler
     * is only set up when the first interpreter is created;
     * after this the application can override the handler with
     * a different one of its own, if it wants.
     */

#ifdef SIGPIPE
    (void) signal(SIGPIPE, SIG_IGN);
#endif /* SIGPIPE */

#ifdef __FreeBSD__
    fpsetround(FP_RN);
    fpsetmask(0L);
#endif

#if defined(__bsdi__) && (_BSDI_VERSION > 199501)
    /*
     * Find local symbols. Don't report an error if we fail.
     */
    (void) dlopen (NULL, RTLD_NOW);			/* INTL: Native. */
#endif
}
Beispiel #5
0
/* this enters native floating-point operation: */
void
tme_float_enter(int rounding_mode, void (*exception_handler)(int, void *), void *exception_handler_private)
{

  /* lock the native floating-point mutex: */
  tme_mutex_lock(&_tme_float_mutex);

  /* set any user exception handler: */
  _tme_float_exception_handler = exception_handler;
  _tme_float_exception_handler_private = exception_handler_private;

  /* establish a signal handler: */
  /* XXX FIXME this assumes that a handler installed once in one thread
     will catch signals for all threads.  obviously, whether or not this
     is true depends on how the threads package deals with signals: */
  if (!_tme_float_sigfpe_handler_installed) {
    signal(SIGFPE, _tme_float_sigfpe_handler);
    _tme_float_sigfpe_handler_installed = TRUE;
  }
  
  /* set the rounding mode: */
#ifdef HAVE_FPSETROUND
  fpsetround(rounding_mode);
#endif /* HAVE_FPSETROUND */

  /* clear the exception status: */
  _tme_float_exceptions = 0;
#ifdef HAVE_FPSETSTICKY
  fpsetsticky(0);
#endif /* HAVE_FPSETSTICKY */

  /* unmask all exceptions: */
#ifdef HAVE_FPSETMASK
  fpsetmask(0
#ifdef FP_X_INV
  | FP_X_INV
#endif
#ifdef FP_X_DNML
  | FP_X_DNML
#endif
#ifdef FP_X_DZ
  | FP_X_DZ
#endif
#ifdef FP_X_OFL
  | FP_X_OFL
#endif
#ifdef FP_X_UFL
  | FP_X_UFL
#endif
#ifdef FP_X_IMP
  | FP_X_IMP
#endif
#ifdef FP_X_IOV
  | FP_X_IOV
#endif
	    );
#endif /* HAVE_FPSETMASK */
}
Beispiel #6
0
void os_set_rounding_mode(int mode)
{
  assert(mode >= 0 && mode <= 3);
  assert(FP_RN == 0);
  assert(FP_RZ == 1);
  assert(FP_RP == 2);
  assert(FP_RM == 3);
  (void)fpsetround(mode);
}
Beispiel #7
0
int
main(int argc, char *argv[])
{
	struct sigaction sa;

	memset(&sa, 0, sizeof(sa));
	sa.sa_sigaction = sigfpe;
	sa.sa_flags = SA_SIGINFO;
	sigaction(SIGFPE, &sa, NULL);

	assert(rint(8.6) == 9.);
	assert(rintf(8.6F) == 9);
	assert(rintl(8.6L) == 9);
 	assert(lrint(8.6) == 9L);
 	assert(lrintf(8.6F) == 9L);
 	assert(llrint(8.6) == 9LL);
 	assert(llrintf(8.6F) == 9LL);

	assert(lrint(0.0) == 0L);
	assert(lrintf(0.0) == 0L);
	assert(lrint(-0.0) == 0L);
	assert(lrintf(-0.0) == 0L);

	assert(llrint(4503599627370496.0) == 4503599627370496LL);
	assert(llrintf(4503599627370496.0F) == 4503599627370496LL);
	assert(llrint(-4503599627370496.0) == -4503599627370496LL);
	assert(llrintf(-4503599627370496.0F) == -4503599627370496LL);

	assert(llrint(0x7ffffffffffffc00.0p0) == 0x7ffffffffffffc00LL);
	assert(llrintf(0x7fffff8000000000.0p0F) == 0x7fffff8000000000LL);
	assert(llrint(-0x8000000000000000.0p0) == -0x8000000000000000LL);
	assert(llrintf(-0x8000000000000000.0p0F) == -0x8000000000000000LL);

	fpsetround(FP_RM);
	assert(lrint(-0.1) == -1L);
	assert(lrintf(-0.1) == -1L);

	fpsetround(FP_RP);
	assert(lrint(0.1) == 1L);
	assert(lrintf(0.1) == 1L);

	exit(0);
}
void set_float_rounding_mode(int val STATUS_PARAM)
{
    STATUS(float_rounding_mode) = val;
#if (defined(CONFIG_BSD) && !defined(__APPLE__) && !defined(__GLIBC__)) || \
    (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
    fpsetround(val);
#else
    fesetround(val);
#endif
}
Beispiel #9
0
/*
 * The fesetenv() function shall attempt to establish the floating-point
 * environment represented by the object pointed to by envp. The fesetenv()
 * function does not raise floating-point exceptions, but only installs the
 * state of the floating-point status flags represented through its argument.
 */
int
fesetenv(const fenv_t *envp)
{
#ifdef __SOFTFP__
	(void)fpsetround(__SHIFTIN(*envp, VFP_FPSCR_RMODE));
	(void)fpsetmask(__SHIFTOUT(*envp, VFP_FPSCR_ESUM));
	(void)fpsetsticky(__SHIFTOUT(*envp, VFP_FPSCR_CSUM));
#else
	armreg_fpscr_write(*envp);
#endif
	return 0;
}
Beispiel #10
0
/*
 * The fesetround() function shall establish the rounding direction represented
 * by its argument round. If the argument is not equal to the value of a
 * rounding direction macro, the rounding direction is not changed.
 */
int
fesetround(int round)
{
#ifndef lint
	_DIAGASSERT(!(round & ~__SHIFTOUT(VFP_FPSCR_RMODE, VFP_FPSCR_RMODE)));
#endif
#ifdef __SOFTFP__
	(void)fpsetround(round);
#else
	int fpscr = armreg_fpscr_read() & ~VFP_FPSCR_RMODE;
	fpscr |= __SHIFTIN(round, VFP_FPSCR_RMODE);
	armreg_fpscr_write(fpscr);
#endif
	return 0;
}
Beispiel #11
0
/*
 * The feupdateenv() function shall attempt to save the currently raised
 * floating-point exceptions in its automatic storage, attempt to install the
 * floating-point environment represented by the object pointed to by envp,
 * and then attempt to raise the saved floating-point exceptions. 
 */
int
feupdateenv(const fenv_t *envp)
{
#ifndef lint
	_DIAGASSERT(envp != NULL);
#endif
#ifdef __SOFTFP__
	(void)fpsetround(__SHIFTIN(*envp, VFP_FPSCR_RMODE));
	(void)fpsetmask(fpgetmask() | __SHIFTOUT(*envp, VFP_FPSCR_ESUM));
	(void)fpsetsticky(fpgetsticky() | __SHIFTOUT(*envp, VFP_FPSCR_CSUM));
#else
	int fpscr = armreg_fpscr_read() & ~(VFP_FPSCR_ESUM|VFP_FPSCR_CSUM);
	fpscr |= *envp;
	armreg_fpscr_write(fpscr);
#endif

	/* Success */
	return 0;
}
Beispiel #12
0
unit
setfc(cerr er, int r, int p)
{
	fp_rnd mode;
	switch(r){
	case TO_NEAREST:	mode = FP_RN; break;
	case TO_ZERO:	mode = FP_RZ; break;
	case TO_POSINF:	mode = FP_RP; break;
	case TO_NEGINF:	mode = FP_RM; break;
	default:
		send_errmsg(er,Emode);
		return empty_record;
	}
	if(p != DOUBLE){
		send_errmsg(er,Eprecision);
		return empty_record;
	}
	fpsetround(mode);
	return empty_record;
}
Beispiel #13
0
void FPEnvironmentImpl::setRoundingModeImpl(RoundingModeImpl mode)
{
	fpsetround((fp_rnd) mode);
}
Beispiel #14
0
void FPEnvironmentImpl::keepCurrentImpl()
{
	fpsetround(_rnd);
	fpsetmask(_exc);
}
Beispiel #15
0
void
TclpInitPlatform(void)
{
#ifdef DJGPP
    tclPlatform = TCL_PLATFORM_WINDOWS;
#else
    tclPlatform = TCL_PLATFORM_UNIX;
#endif

    /*
     * Make sure, that the standard FDs exist. [Bug 772288]
     */

    if (TclOSseek(0, (Tcl_SeekOffset) 0, SEEK_CUR) == -1 && errno == EBADF) {
	open("/dev/null", O_RDONLY);
    }
    if (TclOSseek(1, (Tcl_SeekOffset) 0, SEEK_CUR) == -1 && errno == EBADF) {
	open("/dev/null", O_WRONLY);
    }
    if (TclOSseek(2, (Tcl_SeekOffset) 0, SEEK_CUR) == -1 && errno == EBADF) {
	open("/dev/null", O_WRONLY);
    }

    /*
     * The code below causes SIGPIPE (broken pipe) errors to be ignored. This
     * is needed so that Tcl processes don't die if they create child
     * processes (e.g. using "exec" or "open") that terminate prematurely.
     * The signal handler is only set up when the first interpreter is
     * created; after this the application can override the handler with a
     * different one of its own, if it wants.
     */

#ifdef SIGPIPE
    (void) signal(SIGPIPE, SIG_IGN);
#endif /* SIGPIPE */

#if defined(__FreeBSD__) && defined(__GNUC__)
    /*
     * Adjust the rounding mode to be more conventional. Note that FreeBSD
     * only provides the __fpsetreg() used by the following two for the GNU
     * Compiler. When using, say, Intel's icc they break. (Partially based on
     * patch in BSD ports system from [email protected])
     */

    fpsetround(FP_RN);
    (void) fpsetmask(0L);
#endif

#if defined(__bsdi__) && (_BSDI_VERSION > 199501)
    /*
     * Find local symbols. Don't report an error if we fail.
     */

    (void) dlopen(NULL, RTLD_NOW);			/* INTL: Native. */
#endif

    /*
     * Initialize the C library's locale subsystem. This is required for input
     * methods to work properly on X11. We only do this for LC_CTYPE because
     * that's the necessary one, and we don't want to affect LC_TIME here.
     * The side effect of setting the default locale should be to load any
     * locale specific modules that are needed by X. [BUG: 5422 3345 4236 2522
     * 2521].
     */

    setlocale(LC_CTYPE, "");

    /*
     * In case the initial locale is not "C", ensure that the numeric
     * processing is done in "C" locale regardless. This is needed because Tcl
     * relies on routines like strtod, but should not have locale dependent
     * behavior.
     */

    setlocale(LC_NUMERIC, "C");

#ifdef GET_DARWIN_RELEASE
    {
	struct utsname name;

	if (!uname(&name)) {
	    tclMacOSXDarwinRelease = strtol(name.release, NULL, 10);
	}
    }
#endif
}
Beispiel #16
0
int
gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
{
  fp_except mode = 0;
  fp_rnd    rnd  = 0;

  switch (precision)
    {
    case GSL_IEEE_SINGLE_PRECISION:
      GSL_ERROR ("OpenBSD only supports default precision rounding",
                 GSL_EUNSUP);
      break;
    case GSL_IEEE_DOUBLE_PRECISION:
      GSL_ERROR ("OpenBSD only supports default precision rounding",
                 GSL_EUNSUP);
      break;
    case GSL_IEEE_EXTENDED_PRECISION:
      GSL_ERROR ("OpenBSD only supports default precision rounding",
                 GSL_EUNSUP);
      break;
    }

  switch (rounding)
    {
    case GSL_IEEE_ROUND_TO_NEAREST:
      rnd = FP_RN;
      fpsetround (rnd);
      break;
    case GSL_IEEE_ROUND_DOWN:
      rnd = FP_RM;
      fpsetround (rnd);
      break;
    case GSL_IEEE_ROUND_UP:
      rnd = FP_RP;
      fpsetround (rnd);
      break;
    case GSL_IEEE_ROUND_TO_ZERO:
      rnd = FP_RZ;
      fpsetround (rnd);
      break;
    default:
      rnd = FP_RN;
      fpsetround (rnd);
    }

/* Turn on all available exceptions apart from 'inexact'.
   Denormalized operand exception not available on all platforms. */

  mode = FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL;
#ifdef FP_X_DNML
  mode = mode | FP_X_DNML;
#endif

  if (exception_mask & GSL_IEEE_MASK_INVALID)
    mode &= ~ FP_X_INV;

  if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
    {
#ifdef FP_X_DNML
      mode &= ~ FP_X_DNML;
#endif
    }
  else
    {
#ifndef FP_X_DNML
      GSL_ERROR ("OpenBSD does not support the denormalized operand exception on this platform. "
                 "Use 'mask-denormalized' to work around this.",
                 GSL_EUNSUP);
#endif
    }

  if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
    mode &= ~ FP_X_DZ;

  if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
    mode &= ~ FP_X_OFL;

  if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
    mode &=  ~ FP_X_UFL;

  if (exception_mask & GSL_IEEE_TRAP_INEXACT)
    {
      mode |= FP_X_IMP;
    }
  else
    {
      mode &= ~ FP_X_IMP;
    }

  fpsetmask (mode);

  return GSL_SUCCESS;

}
Beispiel #17
0
NativeFPUControlType changeFPUControl(unsigned int mipsFlag) {
  return fpsetround(FloatValue[mipsFlag & 0x3]);
}
Beispiel #18
0
void op(double num1, double num2, OPERATOR op, int dir, FILE *fp,
	int *nopdiffs, int *nansdiffs, int *nxdiffs, int *nclsdiffs) {
  double ans1;
  char snum1[(DBL2CHR * 2) + 1], snum2[(DBL2CHR * 2) + 1],
    sans1[(DBL2CHR * 2) + 1];
  fp_except x;
  fp_pctl pc;

  pc = fpsetprecision(FP_PC_DBL);
  fpsetsticky(0);
  if(dir >= 0 && dir <= 3) {
    fpsetround(fpdir[dir]);
  }
  else {
    abort();
  }
  switch(op) {
  case PLUS:
    ans1 = num1 + num2;
    break;
  case MINUS:
    ans1 = num1 - num2;
    break;
  case DIVIDE:
    ans1 = num1 / num2;
    break;
  case MULTIPLY:
    ans1 = num1 * num2;
    break;
  default:
    abort();
  }
  x = fpgetsticky();
  fpsetprecision(pc);
  print(num1, snum1);
  print(num2, snum2);
  print(ans1, sans1);
  if(fp == NULL) {
    printf("%s %s %s %s = %s [ %s ]",
	   snum1, operators[op], rnddir[dir], snum2, sans1,
	   fpcls[fpclass(ans1)]);
    if(x & FP_X_INV) printf(" INV");
    if(x & FP_X_DZ) printf(" DZ");
    if(x & FP_X_OFL) printf(" OFL");
    if(x & FP_X_UFL) printf(" UFL");
    if(x & FP_X_IMP) printf(" IMP");
#ifdef FP_X_DNML
    if(x & FP_X_DNML) printf(" DNML");
#endif
    printf(" end\n");
  }
  else {
    char fp_op[MAXOPLEN], fp_rnd[MAXRNDLEN];
    char fp_num1[(DBL2CHR * 2) + 1], fp_num2[(DBL2CHR * 2) + 1],
      fp_ans1[(DBL2CHR * 2) + 1];
    char fp_cls[MAXFPCLS];
    char xbuf[MAXXLEN];
    int inv = 0, dz = 0, ofl = 0, ufl = 0, imp = 0, dnml = 0;
    int thisopdiff = 0, thisansdiff = 0, thisxdiff = 0, thisclsdiff = 0;
    fpclass_t thiscls;

    if(fscanf(fp, "%s %s %s %s = %s [ %s ]",
	      fp_num1, fp_op, fp_rnd, fp_num2, fp_ans1, fp_cls) != 6) {
      fprintf(stderr, "Problem reading comparison file\n");
      abort();
    }
    
    if(strcmp(operators[op], fp_op) != 0) {
      fprintf(stderr, "Operator mismatch in comparison file "
	      "(expecting %s found %s)\n", operators[op], fp_op);
      abort();
    }
    if(strcmp(rnddir[dir], fp_rnd) != 0) {
      fprintf(stderr, "Rounding direction mismatch in comparison file "
	      "(expecting %s found %s)\n", rnddir[dir], fp_rnd);
      abort();
    }

    if(strcmp(fp_num1, snum1) != 0) {
      thisopdiff = 1;
    }
    if(strcmp(fp_num2, snum2) != 0) {
      thisopdiff = 1;
    }
    if(strcmp(fp_ans1, sans1) != 0) {
      thisansdiff = 1;
    }
    thiscls = fpclass(ans1);
    if(strcmp(fp_cls, fpcls[thiscls]) != 0) {
      thisclsdiff = 1;
    }
    do {
      if(fscanf(fp, "%s", xbuf) != 1) {
	fprintf(stderr, "Problem reading comparison file");
	abort();
      }
      if(strcmp(xbuf, "INV") == 0) inv = FP_X_INV;
      else if(strcmp(xbuf, "DZ") == 0) dz = FP_X_DZ;
      else if(strcmp(xbuf, "UFL") == 0) ufl = FP_X_UFL;
      else if(strcmp(xbuf, "OFL") == 0) ofl = FP_X_OFL;
      else if(strcmp(xbuf, "IMP") == 0) imp = FP_X_IMP;
#ifdef FP_X_DNML
      else if(strcmp(xbuf, "DNML") == 0) dnml = FP_X_DNML;
#else
      else if(strcmp(xbuf, "DNML") == 0) dnml = -1;
#endif
      else if(strcmp(xbuf, "end") != 0) {
	fprintf(stderr, "Problem reading comparison file");
	abort();
      }
    } while(strcmp(xbuf, "end") != 0);

    if(inv != (x & FP_X_INV)) thisxdiff = 1;
    if(dz != (x & FP_X_DZ)) thisxdiff = 1;
    if(ufl != (x & FP_X_UFL)) thisxdiff = 1;
    if(ofl != (x & FP_X_OFL)) thisxdiff = 1;
    if(imp != (x & FP_X_IMP)) thisxdiff = 1;
#ifdef FP_X_DNML
    if(dnml != (x & FP_X_DNML)) thisxdiff = 1;
#else
    if(dnml == -1) thisxdiff = 1;
#endif
    
    if(thisansdiff || thisxdiff || thisclsdiff) {
      printf("In calculation %g %s %g = %g (rounding %s):\n",
	     num1, operators[op], num2, ans1, rnddir[dir]);
      if(thisansdiff && thisopdiff) {
	printf("\tOperators differ leading to different answer:\n");
	printf("\t\tFILE: op1=%s op2=%s ans=%s (%g)\n"
	       "\t\tHERE: op1=%s op2=%s ans=%s\n",
	       fp_num1, fp_num2, fp_ans1, input(fp_ans1), snum1, snum2, sans1);
      }
      else if(thisansdiff) {
	printf("\tDifferent answer:\n\t\tFILE: ans=%s (%g)\n"
	       "\t\tHERE: ans=%s\n",
	       fp_ans1, input(fp_ans1), sans1);
      }
      else if(thisclsdiff) {
	printf("\tDifferent class:\n"
	       "\t\tFILE: %s\n\t\tHERE: %s\n",
	       fp_cls, fpcls[thiscls]);
      }
      if(thisxdiff) {
	printf("\tDifferent exceptions raised:\n"
	       "\t\tFILE: %s %s %s %s %s %s\n"
	       "\t\tHERE: %s %s %s %s %s %s\n",
	       inv ? "I" : "-", dz ? "Z" : "-", ufl ? "U" : "-",
	       ofl ? "O" : "-", imp ? "P" : "-", dnml ? "D" : "-",
	       (x & FP_X_INV) ? "I" : "-", (x & FP_X_DZ) ? "Z" : "-",
	       (x & FP_X_UFL) ? "U" : "-", (x & FP_X_OFL) ? "O" : "-",
	       (x & FP_X_IMP) ? "P" : "-",
#ifdef FP_X_DNML
	       (x & FP_X_DNML) ? "D" : "-"
#else
	       "-"
#endif
	       );
      }
    }
    if(thisopdiff) (*nopdiffs)++;
    else if(thisansdiff) (*nansdiffs)++;
    else {
      if(thisxdiff) (*nxdiffs)++;
      if(thisclsdiff) (*nclsdiffs)++;
    }
  }
}
Beispiel #19
0
void restoreFPUControl(NativeFPUControlType nativeFlag) {
  fpsetround((fp_rnd)nativeFlag );
}
Beispiel #20
0
void setFPUControl(unsigned int mipsFlag) {
  fpsetround(FloatValue[mipsFlag & 0x3]);
}
Beispiel #21
0
int test_rounding(void) {
  int failures = 0;
  double prp, prn, prz, prm;
  double nrp, nrn, nrz, nrm;

  printf("Testing rounding direction... ");
  fflush(stdout);

#ifdef __CYGWIN__
  fpsetprecision(FP_PC_DBL);
#endif

  fpsetround(FP_RP);

  prp = (ten / three) * three;
  nrp = (negten / three) * three;

  fpsetround(FP_RM);

  prm = (ten / three) * three;
  nrm = (negten / three) * three;

  fpsetround(FP_RZ);

  prz = (ten / three) * three;
  nrz = (negten / three) * three;

  fpsetround(FP_RN);

  prn = (ten / three) * three;
  nrn = (negten / three) * three;

  /* Positive answers should be ordered RZ == RM < RN < RP */

  if(prp <= prn) FAIL_TEST;
  if(prn <= prm) FAIL_TEST;
  if(prz != prm) FAIL_TEST;

  /* Negative answers should be ordered RM < RN < RP == RZ */

  if(nrm >= nrn) FAIL_TEST;
  if(nrn >= nrp) FAIL_TEST;
  if(nrz != nrp) FAIL_TEST;

  /* IEEE 754, Section 7.3 check. Of course Intel doesn't comply...

  fpsetround(FP_RP);
  if(fpclass(DBL_MAX * two) != FP_PINF) FAIL_TEST;
  if(-DBL_MAX * two != -DBL_MAX) FAIL_TEST;

  fpsetround(FP_RM);
  if(DBL_MAX * two != DBL_MAX) FAIL_TEST;
  if(fpclass(-DBL_MAX * two) != FP_NINF) FAIL_TEST;

  fpsetround(FP_RZ);
  if(DBL_MAX * two != DBL_MAX) FAIL_TEST;
  if(-DBL_MAX * two != -DBL_MAX) FAIL_TEST;

  fpsetround(FP_RN);
  if(fpclass(DBL_MAX * two) != FP_PINF) FAIL_TEST;
  if(fpclass(-DBL_MAX * two) != FP_NINF) FAIL_TEST;

  */

#ifdef __CYGWIN__
  fpsetprecision(FP_PC_EXT);
#endif

  if(failures == 0) {
    printf(" PASSED\n");
    return 0;
  }
  else {
    printf(" %d failures\n", failures);
    return 1;
  }
}
Beispiel #22
0
FPEnvironmentImpl::~FPEnvironmentImpl()
{
	fpsetround(_rnd);
	fpsetmask(_exc);
}
Beispiel #23
0
void setFPUControl(unsigned long mipsFlag)
{
  fpsetround(mipsFlag & 0x3);
}
Beispiel #24
0
void
syst_float_set_rounding_mode(fp_rnd direction)
{
    fpsetround(direction);
    fpsetmask(0);
}
int
gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
{
    fp_prec_t prec = 0 ;
    fp_except_t mode = 0 ;
    fp_rnd_t    rnd  = 0 ;

    switch (precision)
    {
    case GSL_IEEE_SINGLE_PRECISION:
        prec = FP_PS;
        fpsetprec(prec);
        break ;
    case GSL_IEEE_DOUBLE_PRECISION:
        prec = FP_PD;
        fpsetprec(prec);
        break ;
    case GSL_IEEE_EXTENDED_PRECISION:
        prec = FP_PE;
        fpsetprec(prec);
        break ;
    }

    switch (rounding)
    {
    case GSL_IEEE_ROUND_TO_NEAREST:
        rnd = FP_RN ;
        fpsetround (rnd) ;
        break ;
    case GSL_IEEE_ROUND_DOWN:
        rnd = FP_RM ;
        fpsetround (rnd) ;
        break ;
    case GSL_IEEE_ROUND_UP:
        rnd = FP_RP ;
        fpsetround (rnd) ;
        break ;
    case GSL_IEEE_ROUND_TO_ZERO:
        rnd = FP_RZ ;
        fpsetround (rnd) ;
        break ;
    default:
        rnd = FP_RN ;
        fpsetround (rnd) ;
    }

    /* Turn on all the exceptions apart from 'inexact' */

    mode = FP_X_INV | FP_X_DNML | FP_X_DZ | FP_X_OFL | FP_X_UFL ;

    if (exception_mask & GSL_IEEE_MASK_INVALID)
        mode &= ~ FP_X_INV ;

    if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
        mode &= ~ FP_X_DNML ;

    if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
        mode &= ~ FP_X_DZ ;

    if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
        mode &= ~ FP_X_OFL ;

    if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
        mode &=  ~ FP_X_UFL ;

    if (exception_mask & GSL_IEEE_TRAP_INEXACT)
    {
        mode |= FP_X_IMP ;
    }
    else
    {
        mode &= ~ FP_X_IMP ;
    }

    fpsetmask (mode) ;

    return GSL_SUCCESS ;

}
Beispiel #26
0
/*
-------------------------------------------------------------------------------
Sets the system's IEC/IEEE floating-point rounding mode.
-------------------------------------------------------------------------------
*/
void syst_float_set_rounding_mode( int8 roundingMode )
{

    (void) fpsetround( roundingMode );

}