Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ieee.c « sun4 « sys « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 28289761d3a339e2791a0db82fead50b2abb55e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

#include <ieeefp.h>


fp_rnd
_DEFUN_VOID(fpgetround)
{
  char *out;
  ieee_flags("get", "direction","", &out);
  if (strcmp(out,"nearest") == 0) return FP_RN;  
  if (strcmp(out,"negative") == 0) return FP_RM;  
  if (strcmp(out,"positive") == 0) return FP_RP;  
  if (strcmp(out,"tozero") == 0) return FP_RZ;  
  abort();
  
}

fp_rnd
_DEFUN(fpsetround,(new),
       fp_rnd new)
{
  fp_rnd old = fpgetround();
  char *dummy;
  
  switch (new) 
  {
  case FP_RN:
    ieee_flags("set", "direction", "nearest", &dummy);
    break;
  case FP_RM:
    ieee_flags("set", "direction", "negative", &dummy);
    break;
  case FP_RP:
    ieee_flags("set", "direction", "positive", &dummy);
    break;
  case FP_RZ:
    ieee_flags("set", "direction", "tozero", &dummy);
    break;
  default:
    break;
  }
  return old;
}


fp_except
_DEFUN_VOID(fpgetmask)
{
  char *out;
  int r = 0;

  int i = ieee_flags("get","exception","",&out);  
  if (i & 1) r |= FP_X_IMP;
  if (i & 2) r |= FP_X_DX;
  if (i & 4) r |= FP_X_UFL;
  if (i & 8) r |= FP_X_OFL;
  if (i & 16) r |= FP_X_INV;
  return r;

}

fp_except
_DEFUN(fpsetmask,(mask),
       fp_except mask)
{
  fp_except old = fpgetmask();  

  char *out;
  ieee_flags("clear","exception", "all", &out);


  if (mask & FP_X_IMP) 
   ieee_flags("set","exception","inexact", &out);
  if (mask  & FP_X_DX)
   ieee_flags("set","exception","division", &out);
  if (mask & FP_X_UFL)
   ieee_flags("set","exception","underflow", &out);
  if (mask & FP_X_OFL)
   ieee_flags("set","exception","overflow", &out);
  if (mask & FP_X_INV)
   ieee_flags("set","exception","invalid", &out);

  return old;

}

fp_except 
_DEFUN(fpsetsticky,(mask),
       fp_except mask)
{
  return fpsetmask(mask);
}

fp_except
_DEFUN_VOID(fpgetsticky)
{
  return fpgetmask();
}

int
_DEFUN(fpsetroundtoi,(rdi_mode),
       fp_rdi rdi_mode)
{
  
  return 0;
  
}

int 
_DEFUN_VOID(fpgetroundtoi)
{
  
  return 0;
  
}