Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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