Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    Copyright (c) 1993 Open Software Foundation, Inc.
3
 
4
 
5
    All Rights Reserved
6
 
7
 
8
    Permission to use, copy, modify, and distribute this software
9
    and its documentation for any purpose and without fee is hereby
10
    granted, provided that the above copyright notice appears in all
11
    copies and that both the copyright notice and this permission
12
    notice appear in supporting documentation.
13
 
14
 
15
    OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING
16
    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17
    PARTICULAR PURPOSE.
18
 
19
 
20
    IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
21
    CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22
    LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
23
    NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
24
    WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25
*/
26
 
27
/*
28
    		 Crown Copyright (c) 1997
29
 
30
    This TenDRA(r) Computer Program is subject to Copyright
31
    owned by the United Kingdom Secretary of State for Defence
32
    acting through the Defence Evaluation and Research Agency
33
    (DERA).  It is made available to Recipients with a
34
    royalty-free licence for its use, reproduction, transfer
35
    to other parties and amendment for any purpose not excluding
36
    product development provided that any such use et cetera
37
    shall be deemed to be acceptance of the following conditions:-
38
 
39
        (1) Its Recipients shall ensure that this Notice is
40
        reproduced upon any copies or amended versions of it;
41
 
42
        (2) Any amended version of it shall be clearly marked to
43
        show both the nature of and the organisation responsible
44
        for the relevant amendment or amendments;
45
 
46
        (3) Its onward transfer from a recipient to another
47
        party shall be deemed to be that party's acceptance of
48
        these conditions;
49
 
50
        (4) DERA gives no warranty or assurance as to its
51
        quality or suitability for any purpose and DERA accepts
52
        no liability whatsoever in relation to any use to which
53
        it may be put.
54
*/
55
 
56
 
57
#include "ossg.h"
58
 
59
/* from float.h */
60
#define FP_RND_RZ		0
61
#define FP_RND_RN		1
62
#define FP_RND_RP		2
63
#define FP_RND_RM		3
64
 
65
typedef unsigned short fprnd_t ;
66
extern fprnd_t fp_read_rnd PROTO_S ( ( void ) ) ;
67
extern fprnd_t fp_swap_rnd PROTO_S ( ( fprnd_t ) ) ;
68
 
69
/* from math.h */
70
extern unsigned uitrunc PROTO_S ( ( double ) ) ;
71
extern int itrunc PROTO_S ( ( double ) ) ;
72
extern double rint PROTO_S ( ( double ) ) ;
73
 
74
/* from limits.h */
75
#define INT_MAX			( 2147483647 )
76
#define INT_MIN			( -( INT_MAX + 1 ) ) 
77
 
78
extern int __TDFrnd_error ;
79
extern unsigned int __TDFrnd_unsgned PROTO_S ( ( double, fprnd_t ) ) ;
80
extern int __TDFrnd_sgned PROTO_S ( ( double, fprnd_t ) ) ;
81
extern void __TDFerr_rnd_unsgned PROTO_S ( ( double, fprnd_t ) ) ;
82
extern void __TDFerr_rnd_sgned PROTO_S ( ( double, fprnd_t ) ) ;
83
 
84
int __TDFrnd_error = 0 ;
85
 
86
unsigned int __TDFrnd_unsgned
87
    PROTO_N ( ( f, rnd_mode ) ) 
88
    PROTO_T ( double f X fprnd_t rnd_mode )
89
{
90
    fprnd_t swap ;
91
    unsigned int ret_value ;
92
    swap = fp_swap_rnd ( rnd_mode ) ;
93
    ret_value = uitrunc ( rint ( f ) ) ;
94
    ( void ) fp_swap_rnd ( swap ) ;
95
    return ( ret_value ) ;
96
}
97
 
98
int __TDFrnd_sgned
99
    PROTO_N ( ( f, rnd_mode ) ) 
100
    PROTO_T ( double f X fprnd_t rnd_mode )
101
{
102
    fprnd_t swap ;
103
    int ret_value ;
104
    swap = fp_swap_rnd ( rnd_mode ) ;
105
    ret_value = itrunc ( rint ( f ) ) ;
106
    ( void ) fp_swap_rnd ( swap ) ;
107
    return ( ret_value );
108
}
109
 
110
void __TDFerr_rnd_unsgned
111
    PROTO_N ( ( f, rnd_mode ) ) 
112
    PROTO_T ( double f X fprnd_t rnd_mode )
113
{
114
    double fmin = 0.0 ;
115
    double fmax = 4294967295.0 ;
116
    switch ( rnd_mode ) {
117
	case FP_RND_RN : {
118
	    fmin += -0.5 ;
119
	    fmax += 0.5 ;
120
	    if ( f < fmin || f > fmax ) {
121
		__TDFrnd_error = 1 ;
122
	    } else {
123
		__TDFrnd_error = -1 ;
124
	    }
125
	    break ;
126
	}
127
	case FP_RND_RZ : {
128
	    fmin += -1.0 ;
129
	    fmax += 1.0 ;
130
	    if ( f <= fmin || f >= fmax ) {
131
		__TDFrnd_error = 1 ;
132
	    } else {
133
		__TDFrnd_error = -1 ;
134
	    }
135
	    break ;
136
	}
137
	case FP_RND_RP : {
138
	    fmin += -1.0 ;
139
	    if ( f <= fmin || f > fmax ) {
140
		__TDFrnd_error = 1 ;
141
	    } else {
142
		__TDFrnd_error = -1 ;
143
	    }
144
	    break ;
145
	}
146
	case FP_RND_RM : {
147
	    fmax += 1.0 ;
148
	    if ( f < fmin || f >= fmax ) {
149
		__TDFrnd_error = 1 ;
150
	    } else {
151
		__TDFrnd_error = -1 ;
152
	    }
153
	    break ;
154
	}
155
    }
156
    return ;
157
}
158
 
159
void __TDFerr_rnd_sgned
160
    PROTO_N ( ( f, rnd_mode ) ) 
161
    PROTO_T ( double f X fprnd_t rnd_mode )
162
{
163
    double fmin = -2147483648.0 ;
164
    double fmax = 2147483647.0 ;
165
 
166
    switch ( rnd_mode ) {
167
	case FP_RND_RN : {
168
	    fmin += -0.5 ;
169
	    fmax += 0.5 ;
170
	    if ( f < fmin || f > fmax ) {
171
		__TDFrnd_error = 1 ;
172
	    } else {
173
		 __TDFrnd_error = -1 ;
174
	    }
175
	    break ;
176
	}
177
	case FP_RND_RZ : {
178
	    fmin += -1.0 ;
179
	    fmax += 1.0 ;
180
	    if ( f <= fmin || f >= fmax ) {
181
		__TDFrnd_error = 1 ;
182
	    } else {
183
		__TDFrnd_error = -1 ;
184
	    }
185
	    break ;
186
	}
187
	case FP_RND_RP : {
188
	    fmin += -1.0 ;
189
	    if ( f <= fmin || f > fmax ) {
190
		__TDFrnd_error = 1 ;
191
	    } else {
192
		__TDFrnd_error = -1 ;
193
	    }
194
	    break ;
195
	}
196
	case FP_RND_RM : {
197
	    fmax += 1.0 ;
198
	    if ( f < fmin || f >= fmax ) {
199
		__TDFrnd_error = 1 ;
200
	    } else {
201
		__TDFrnd_error = -1 ;
202
	    }
203
	    break;
204
	}
205
    }
206
    return ;
207
}