Blame ieee-utils/fp-freebsd.c

Packit 67cb25
/* ieee-utils/fp-freebsd.c
Packit 67cb25
 * 
Packit 67cb25
 * Copyright (C) 2000 Vladimir Kushnir
Packit 67cb25
 * 
Packit 67cb25
 * This program is free software; you can redistribute it and/or modify
Packit 67cb25
 * it under the terms of the GNU General Public License as published by
Packit 67cb25
 * the Free Software Foundation; either version 3 of the License, or (at
Packit 67cb25
 * your option) any later version.
Packit 67cb25
 * 
Packit 67cb25
 * This program is distributed in the hope that it will be useful, but
Packit 67cb25
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 67cb25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 67cb25
 * General Public License for more details.
Packit 67cb25
 * 
Packit 67cb25
 * You should have received a copy of the GNU General Public License
Packit 67cb25
 * along with this program; if not, write to the Free Software
Packit 67cb25
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit 67cb25
 */
Packit 67cb25
Packit 67cb25
#include <ieeefp.h>
Packit 67cb25
#include <gsl/gsl_ieee_utils.h>
Packit 67cb25
#include <gsl/gsl_errno.h>
Packit 67cb25
Packit 67cb25
int
Packit 67cb25
gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
Packit 67cb25
{
Packit 67cb25
  fp_prec_t prec = 0 ;
Packit 67cb25
  fp_except_t mode = 0 ;
Packit 67cb25
  fp_rnd_t    rnd  = 0 ;
Packit 67cb25
Packit 67cb25
  switch (precision)
Packit 67cb25
    {
Packit 67cb25
    case GSL_IEEE_SINGLE_PRECISION:
Packit 67cb25
      prec = FP_PS;
Packit 67cb25
      fpsetprec(prec);      
Packit 67cb25
      break ;
Packit 67cb25
    case GSL_IEEE_DOUBLE_PRECISION:
Packit 67cb25
      prec = FP_PD;
Packit 67cb25
      fpsetprec(prec);
Packit 67cb25
      break ;
Packit 67cb25
    case GSL_IEEE_EXTENDED_PRECISION:
Packit 67cb25
      prec = FP_PE;
Packit 67cb25
      fpsetprec(prec);
Packit 67cb25
      break ;
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  switch (rounding)
Packit 67cb25
    {
Packit 67cb25
    case GSL_IEEE_ROUND_TO_NEAREST:
Packit 67cb25
      rnd = FP_RN ;
Packit 67cb25
      fpsetround (rnd) ;
Packit 67cb25
      break ;
Packit 67cb25
    case GSL_IEEE_ROUND_DOWN:
Packit 67cb25
      rnd = FP_RM ;
Packit 67cb25
      fpsetround (rnd) ;
Packit 67cb25
      break ;
Packit 67cb25
    case GSL_IEEE_ROUND_UP:
Packit 67cb25
      rnd = FP_RP ;
Packit 67cb25
      fpsetround (rnd) ;
Packit 67cb25
      break ;
Packit 67cb25
    case GSL_IEEE_ROUND_TO_ZERO:
Packit 67cb25
      rnd = FP_RZ ;
Packit 67cb25
      fpsetround (rnd) ;
Packit 67cb25
      break ;
Packit 67cb25
    default:
Packit 67cb25
      rnd = FP_RN ;
Packit 67cb25
      fpsetround (rnd) ;
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  /* Turn on all the exceptions apart from 'inexact' */
Packit 67cb25
Packit 67cb25
  mode = FP_X_INV | FP_X_DNML | FP_X_DZ | FP_X_OFL | FP_X_UFL ;
Packit 67cb25
Packit 67cb25
  if (exception_mask & GSL_IEEE_MASK_INVALID)
Packit 67cb25
    mode &= ~ FP_X_INV ;
Packit 67cb25
Packit 67cb25
  if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
Packit 67cb25
    mode &= ~ FP_X_DNML ;
Packit 67cb25
Packit 67cb25
  if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
Packit 67cb25
    mode &= ~ FP_X_DZ ;
Packit 67cb25
Packit 67cb25
  if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
Packit 67cb25
    mode &= ~ FP_X_OFL ;
Packit 67cb25
Packit 67cb25
  if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
Packit 67cb25
    mode &=  ~ FP_X_UFL ;
Packit 67cb25
Packit 67cb25
  if (exception_mask & GSL_IEEE_TRAP_INEXACT)
Packit 67cb25
    {
Packit 67cb25
      mode |= FP_X_IMP ;
Packit 67cb25
    }
Packit 67cb25
  else
Packit 67cb25
    {
Packit 67cb25
      mode &= ~ FP_X_IMP ;
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  fpsetmask (mode) ;
Packit 67cb25
Packit 67cb25
  return GSL_SUCCESS ;
Packit 67cb25
Packit 67cb25
}