| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <math.h> |
| 21 |
#include <ieeefp.h> |
| 22 |
#include "gsl_ieee_utils.h" |
| 23 |
#include "gsl_errno.h" |
| 24 |
|
| 25 |
int |
| 26 |
gsl_ieee_set_mode (int precision, int rounding, int exception_mask) |
| 27 |
{ |
| 28 |
fp_except mode = 0 ; |
| 29 |
fp_rnd rnd = 0 ; |
| 30 |
|
| 31 |
switch (precision) |
| 32 |
{ |
| 33 |
case GSL_IEEE_SINGLE_PRECISION: |
| 34 |
GSL_ERROR ("solaris only supports default precision rounding", |
| 35 |
GSL_EUNSUP) ; |
| 36 |
break ; |
| 37 |
case GSL_IEEE_DOUBLE_PRECISION: |
| 38 |
GSL_ERROR ("solaris only supports default precision rounding", |
| 39 |
GSL_EUNSUP) ; |
| 40 |
break ; |
| 41 |
case GSL_IEEE_EXTENDED_PRECISION: |
| 42 |
GSL_ERROR ("solaris only supports default precision rounding", |
| 43 |
GSL_EUNSUP) ; |
| 44 |
break ; |
| 45 |
} |
| 46 |
|
| 47 |
switch (rounding) |
| 48 |
{ |
| 49 |
case GSL_IEEE_ROUND_TO_NEAREST: |
| 50 |
rnd = FP_RN ; |
| 51 |
fpsetround (rnd) ; |
| 52 |
break ; |
| 53 |
case GSL_IEEE_ROUND_DOWN: |
| 54 |
rnd = FP_RM ; |
| 55 |
fpsetround (rnd) ; |
| 56 |
break ; |
| 57 |
case GSL_IEEE_ROUND_UP: |
| 58 |
rnd = FP_RP ; |
| 59 |
fpsetround (rnd) ; |
| 60 |
break ; |
| 61 |
case GSL_IEEE_ROUND_TO_ZERO: |
| 62 |
rnd = FP_RZ ; |
| 63 |
fpsetround (rnd) ; |
| 64 |
break ; |
| 65 |
default: |
| 66 |
rnd = FP_RN ; |
| 67 |
fpsetround (rnd) ; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
mode = FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL ; |
| 73 |
|
| 74 |
if (exception_mask & GSL_IEEE_MASK_INVALID) |
| 75 |
mode &= ~ FP_X_INV ; |
| 76 |
|
| 77 |
if (exception_mask & GSL_IEEE_MASK_DENORMALIZED) |
| 78 |
{ |
| 79 |
|
| 80 |
} |
| 81 |
else |
| 82 |
{ |
| 83 |
GSL_ERROR ("solaris does not support the denormalized operand exception. " |
| 84 |
"Use 'mask-denormalized' to work around this.", |
| 85 |
GSL_EUNSUP) ; |
| 86 |
} |
| 87 |
|
| 88 |
if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO) |
| 89 |
mode &= ~ FP_X_DZ ; |
| 90 |
|
| 91 |
if (exception_mask & GSL_IEEE_MASK_OVERFLOW) |
| 92 |
mode &= ~ FP_X_OFL ; |
| 93 |
|
| 94 |
if (exception_mask & GSL_IEEE_MASK_UNDERFLOW) |
| 95 |
mode &= ~ FP_X_UFL ; |
| 96 |
|
| 97 |
if (exception_mask & GSL_IEEE_TRAP_INEXACT) |
| 98 |
{ |
| 99 |
mode |= FP_X_IMP ; |
| 100 |
} |
| 101 |
else |
| 102 |
{ |
| 103 |
mode &= ~ FP_X_IMP ; |
| 104 |
} |
| 105 |
|
| 106 |
fpsetmask (mode) ; |
| 107 |
|
| 108 |
return GSL_SUCCESS ; |
| 109 |
|
| 110 |
} |