home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / src / ieee-utils / fp-darwin.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-04-20  |  3.1 KB  |  96 lines

  1. /* ieee-utils/fp-darwin.c
  2.  * 
  3.  * Copyright (C) 2001 Rodney Sparapani <rsparapa@mcw.edu>
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <architecture/ppc/fp_regs.h> 
  21. #include <gsl/gsl_ieee_utils.h>
  22. #include <gsl/gsl_errno.h>
  23.  
  24. int
  25. gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  26. {
  27.   ppc_fp_scr_t fp_scr = get_fp_scr() ;
  28.  
  29.   switch (precision)
  30.     {
  31.     case GSL_IEEE_SINGLE_PRECISION:
  32.       GSL_ERROR ("powerpc only supports default precision rounding", GSL_EUNSUP);
  33.       break ;
  34.     case GSL_IEEE_DOUBLE_PRECISION:
  35.       GSL_ERROR ("powerpc only supports default precision rounding", GSL_EUNSUP);
  36.       break ;
  37.     case GSL_IEEE_EXTENDED_PRECISION:
  38.       GSL_ERROR ("powerpc only supports default precision rounding", GSL_EUNSUP);
  39.       break ;
  40.     }
  41.  
  42.   switch (rounding)
  43.     {
  44.     case GSL_IEEE_ROUND_TO_NEAREST:
  45.       fp_scr.rn = RN_NEAREST ;
  46.       break ;
  47.     case GSL_IEEE_ROUND_DOWN:
  48.       fp_scr.rn = RN_TOWARD_MINUS ;
  49.       break ;
  50.     case GSL_IEEE_ROUND_UP:
  51.       fp_scr.rn = RN_TOWARD_PLUS ;
  52.       break ;
  53.     case GSL_IEEE_ROUND_TO_ZERO:
  54.       fp_scr.rn = RN_TOWARD_ZERO ;
  55.       break ;
  56.     default:
  57.       fp_scr.rn = RN_NEAREST ;
  58.     }
  59.  
  60.  
  61.   /* Turn on all the exceptions apart from 'inexact' */
  62.   /* I'm not sure what 'Turn on' means.              */
  63.   /* I'm assuming that enable = 1 and disable = 0    */
  64.   /* and that disable is what is wanted.             */
  65.  
  66.   if (exception_mask & GSL_IEEE_MASK_INVALID)
  67.     fp_scr.ve = 0 ;                //ve bit:  invalid op exception enable
  68.  
  69.   if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  70.     GSL_ERROR ("powerpc does not support the denormalized operand exception. "
  71.                "Use 'mask-denormalized' to work around this.", GSL_EUNSUP) ;
  72.  
  73.   if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  74.     fp_scr.ze = 0 ;                              //ze bit:  zero divide exception enable
  75.  
  76.   if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  77.     fp_scr.oe = 0 ;                             //oe bit:  overflow exception enable
  78.  
  79.   if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  80.     fp_scr.ue  = 0 ;                            //ue bit:  underflow exception enable
  81.  
  82.   if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  83.     {
  84.       fp_scr.xe = 1 ;                        //xe bit:  inexact exception enable
  85.     }
  86.   else
  87.     {
  88.       fp_scr.xe = 1 ;                  
  89.     }
  90.  
  91.   set_fp_scr(fp_scr);
  92.  
  93.   return GSL_SUCCESS ;
  94.  
  95. }
  96.