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-m68klinux.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-05  |  2.7 KB  |  98 lines

  1. /* ieee-utils/fp-m68klinux.c
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough
  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 <stdio.h>
  21. #include <fpu_control.h>
  22. #include <gsl/gsl_errno.h>
  23. #include <gsl/gsl_ieee_utils.h>
  24.  
  25. int
  26. gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  27. {
  28.   unsigned short mode = 0 ;
  29.  
  30.   switch (precision)
  31.     {
  32.     case GSL_IEEE_SINGLE_PRECISION:
  33.       mode |= _FPU_SINGLE ;
  34.       break ;
  35.     case GSL_IEEE_DOUBLE_PRECISION:
  36.       mode |= _FPU_DOUBLE ;
  37.       break ;
  38.     case GSL_IEEE_EXTENDED_PRECISION:
  39.       mode |= _FPU_EXTENDED ;
  40.       break ;
  41.     default:
  42.       mode |= _FPU_EXTENDED ;
  43.     }
  44.  
  45.   switch (rounding)
  46.     {
  47.     case GSL_IEEE_ROUND_TO_NEAREST:
  48.       mode |= _FPU_RC_NEAREST ;
  49.       break ;
  50.     case GSL_IEEE_ROUND_DOWN:
  51.       mode |= _FPU_RC_DOWN ;
  52.       break ;
  53.     case GSL_IEEE_ROUND_UP:
  54.       mode |= _FPU_RC_UP ;
  55.       break ;
  56.     case GSL_IEEE_ROUND_TO_ZERO:
  57.       mode |= _FPU_RC_ZERO ;
  58.       break ;
  59.     default:
  60.       mode |= _FPU_RC_NEAREST ;
  61.     }
  62.  
  63.   /* FIXME: I don't have documentation for the M68K so I'm not sure
  64.      about the mapping of the exceptions below. Maybe someone who does
  65.      know could correct this. */
  66.  
  67.   if (exception_mask & GSL_IEEE_MASK_INVALID)
  68.     mode |= _FPU_MASK_OPERR ;
  69.   
  70.   if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  71.     {
  72.       GSL_ERROR ("the denormalized operand exception has not been implemented for m68k linux yet. Use 'mask-denormalized' to work around this.", GSL_EUNSUP) ;
  73.       /*mode |= _FPU_MASK_DM ; ???? */ 
  74.     }
  75.   
  76.   if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  77.     mode |= _FPU_MASK_DZ ;
  78.  
  79.   if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  80.     mode |= _FPU_MASK_OVFL ;
  81.  
  82.   if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  83.     mode |= _FPU_MASK_UNFL ;
  84.  
  85.   if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  86.     {
  87.       mode &= ~ (_FPU_MASK_INEX1 | _FPU_MASK_INEX2) ;
  88.     }
  89.   else
  90.     {
  91.       mode |= (_FPU_MASK_INEX1 | _FPU_MASK_INEX2) ;
  92.     }
  93.  
  94.   _FPU_SETCW(mode) ;
  95.  
  96.   return GSL_SUCCESS ;
  97. }
  98.