Blame ieee-utils/env.c

Packit 67cb25
/* ieee-utils/env.c
Packit 67cb25
 * 
Packit 67cb25
 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
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 <config.h>
Packit 67cb25
#include <stdlib.h>
Packit 67cb25
#include <gsl/gsl_ieee_utils.h>
Packit 67cb25
#include <gsl/gsl_errno.h>
Packit 67cb25
Packit 67cb25
void
Packit 67cb25
gsl_ieee_env_setup (void)
Packit 67cb25
{
Packit 67cb25
  const char * p = getenv("GSL_IEEE_MODE") ;
Packit 67cb25
Packit 67cb25
  int precision = 0, rounding = 0, exception_mask = 0 ;
Packit 67cb25
Packit 67cb25
  int comma = 0 ;
Packit 67cb25
Packit 67cb25
#if defined( _MSC_VER )
Packit 67cb25
Packit 67cb25
    extern const char *fp_env_string;
Packit 67cb25
	if(p == 0 || *p == '\0')
Packit 67cb25
        p = fp_env_string;
Packit 67cb25
Packit 67cb25
#else
Packit 67cb25
Packit 67cb25
  if (p == 0)  /* GSL_IEEE_MODE environment variable is not set */
Packit 67cb25
    return ;
Packit 67cb25
Packit 67cb25
  if (*p == '\0') /* GSL_IEEE_MODE environment variable is empty */
Packit 67cb25
    return ;
Packit 67cb25
Packit 67cb25
#endif
Packit 67cb25
Packit 67cb25
  gsl_ieee_read_mode_string (p, &precision, &rounding, &exception_mask) ;
Packit 67cb25
Packit 67cb25
  gsl_ieee_set_mode (precision, rounding, exception_mask) ;
Packit 67cb25
  
Packit 67cb25
  fprintf(stderr, "GSL_IEEE_MODE=\"") ;
Packit 67cb25
Packit 67cb25
  /* Print string with a preceeding comma if the list has already begun */
Packit 67cb25
Packit 67cb25
#define PRINTC(x) do {if(comma) fprintf(stderr,","); fprintf(stderr,x); comma++ ;} while(0)
Packit 67cb25
  
Packit 67cb25
  switch (precision) 
Packit 67cb25
    {
Packit 67cb25
    case GSL_IEEE_SINGLE_PRECISION:
Packit 67cb25
      PRINTC("single-precision") ;
Packit 67cb25
      break ;
Packit 67cb25
    case GSL_IEEE_DOUBLE_PRECISION:
Packit 67cb25
      PRINTC("double-precision") ;
Packit 67cb25
      break ;
Packit 67cb25
    case GSL_IEEE_EXTENDED_PRECISION:
Packit 67cb25
      PRINTC("extended-precision") ;
Packit 67cb25
      break ;
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  switch (rounding) 
Packit 67cb25
    {
Packit 67cb25
    case GSL_IEEE_ROUND_TO_NEAREST:
Packit 67cb25
      PRINTC("round-to-nearest") ;
Packit 67cb25
      break ;
Packit 67cb25
    case GSL_IEEE_ROUND_DOWN:
Packit 67cb25
      PRINTC("round-down") ;
Packit 67cb25
      break ;
Packit 67cb25
    case GSL_IEEE_ROUND_UP:
Packit 67cb25
      PRINTC("round-up") ;
Packit 67cb25
      break ;
Packit 67cb25
    case GSL_IEEE_ROUND_TO_ZERO:
Packit 67cb25
      PRINTC("round-to-zero") ;
Packit 67cb25
      break ;
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  if ((exception_mask & GSL_IEEE_MASK_ALL) == GSL_IEEE_MASK_ALL)
Packit 67cb25
    {
Packit 67cb25
      PRINTC("mask-all") ;
Packit 67cb25
    }
Packit 67cb25
  else if ((exception_mask & GSL_IEEE_MASK_ALL) == 0)
Packit 67cb25
    {
Packit 67cb25
      PRINTC("trap-common") ;
Packit 67cb25
    }
Packit 67cb25
  else 
Packit 67cb25
    {
Packit 67cb25
      if (exception_mask & GSL_IEEE_MASK_INVALID)
Packit 67cb25
        PRINTC("mask-invalid") ;
Packit 67cb25
      
Packit 67cb25
      if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
Packit 67cb25
        PRINTC("mask-denormalized") ;
Packit 67cb25
      
Packit 67cb25
      if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
Packit 67cb25
        PRINTC("mask-division-by-zero") ;
Packit 67cb25
      
Packit 67cb25
      if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
Packit 67cb25
        PRINTC("mask-overflow") ;
Packit 67cb25
      
Packit 67cb25
      if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
Packit 67cb25
        PRINTC("mask-underflow") ;
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  if (exception_mask & GSL_IEEE_TRAP_INEXACT)
Packit 67cb25
    PRINTC("trap-inexact") ;
Packit 67cb25
  
Packit 67cb25
  fprintf(stderr,"\"\n") ;
Packit 67cb25
}
Packit 67cb25
Packit 67cb25
Packit 67cb25
Packit 67cb25
Packit 67cb25