crmf 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/crmf.gemspec +105 -3
- data/ext/crlibm-1.0beta5/AUTHORS +2 -0
- data/ext/crlibm-1.0beta5/CMakeLists.txt +154 -0
- data/ext/crlibm-1.0beta5/COPYING +340 -0
- data/ext/crlibm-1.0beta5/COPYING.LIB +504 -0
- data/ext/crlibm-1.0beta5/ChangeLog +125 -0
- data/ext/crlibm-1.0beta5/Makefile.am +134 -0
- data/ext/crlibm-1.0beta5/NEWS +0 -0
- data/ext/crlibm-1.0beta5/README +31 -0
- data/ext/crlibm-1.0beta5/README.DEV +23 -0
- data/ext/crlibm-1.0beta5/README.md +5 -0
- data/ext/crlibm-1.0beta5/TODO +66 -0
- data/ext/crlibm-1.0beta5/VERSION +1 -0
- data/ext/crlibm-1.0beta5/acos-td.c +1195 -0
- data/ext/crlibm-1.0beta5/acos-td.h +629 -0
- data/ext/crlibm-1.0beta5/asin-td.c +1297 -0
- data/ext/crlibm-1.0beta5/asin-td.h +620 -0
- data/ext/crlibm-1.0beta5/asincos.c +4488 -0
- data/ext/crlibm-1.0beta5/asincos.h +575 -0
- data/ext/crlibm-1.0beta5/atan-itanium.c +846 -0
- data/ext/crlibm-1.0beta5/atan-pentium.c +280 -0
- data/ext/crlibm-1.0beta5/atan-pentium.h +343 -0
- data/ext/crlibm-1.0beta5/atan_accurate.c +341 -0
- data/ext/crlibm-1.0beta5/atan_accurate.h +198 -0
- data/ext/crlibm-1.0beta5/atan_fast.c +506 -0
- data/ext/crlibm-1.0beta5/atan_fast.h +680 -0
- data/ext/crlibm-1.0beta5/configure.ac +419 -0
- data/ext/crlibm-1.0beta5/crlibm.h +204 -0
- data/ext/crlibm-1.0beta5/crlibm.spec +42 -0
- data/ext/crlibm-1.0beta5/crlibm_private.c +397 -0
- data/ext/crlibm-1.0beta5/crlibm_private.h +1048 -0
- data/ext/crlibm-1.0beta5/csh_fast.c +721 -0
- data/ext/crlibm-1.0beta5/csh_fast.h +771 -0
- data/ext/crlibm-1.0beta5/double-extended.h +496 -0
- data/ext/crlibm-1.0beta5/exp-itanium.c +723 -0
- data/ext/crlibm-1.0beta5/exp-td-standalone.c +87 -0
- data/ext/crlibm-1.0beta5/exp-td.c +1363 -0
- data/ext/crlibm-1.0beta5/exp-td.h +685 -0
- data/ext/crlibm-1.0beta5/exp_build_coeffs/exp_fast_table.c +125 -0
- data/ext/crlibm-1.0beta5/expm1-standalone.c +119 -0
- data/ext/crlibm-1.0beta5/expm1.c +2515 -0
- data/ext/crlibm-1.0beta5/expm1.h +715 -0
- data/ext/crlibm-1.0beta5/interval.h +238 -0
- data/ext/crlibm-1.0beta5/log-de.c +480 -0
- data/ext/crlibm-1.0beta5/log-de.h +747 -0
- data/ext/crlibm-1.0beta5/log-de2.c +280 -0
- data/ext/crlibm-1.0beta5/log-de2.h +2352 -0
- data/ext/crlibm-1.0beta5/log-td.c +1158 -0
- data/ext/crlibm-1.0beta5/log-td.h +819 -0
- data/ext/crlibm-1.0beta5/log.c +2244 -0
- data/ext/crlibm-1.0beta5/log.h +1592 -0
- data/ext/crlibm-1.0beta5/log10-td.c +906 -0
- data/ext/crlibm-1.0beta5/log10-td.h +823 -0
- data/ext/crlibm-1.0beta5/log1p.c +1295 -0
- data/ext/crlibm-1.0beta5/log2-td.c +1521 -0
- data/ext/crlibm-1.0beta5/log2-td.h +821 -0
- data/ext/crlibm-1.0beta5/log2_accurate.c +330 -0
- data/ext/crlibm-1.0beta5/log2_accurate.h +261 -0
- data/ext/crlibm-1.0beta5/log_accurate.c +133 -0
- data/ext/crlibm-1.0beta5/log_accurate.h +261 -0
- data/ext/crlibm-1.0beta5/log_fast.c +360 -0
- data/ext/crlibm-1.0beta5/log_fast.h +440 -0
- data/ext/crlibm-1.0beta5/pow.c +1396 -0
- data/ext/crlibm-1.0beta5/pow.h +3101 -0
- data/ext/crlibm-1.0beta5/prepare +20 -0
- data/ext/crlibm-1.0beta5/rem_pio2_accurate.c +219 -0
- data/ext/crlibm-1.0beta5/rem_pio2_accurate.h +53 -0
- data/ext/crlibm-1.0beta5/scs_lib/AUTHORS +3 -0
- data/ext/crlibm-1.0beta5/scs_lib/COPYING +504 -0
- data/ext/crlibm-1.0beta5/scs_lib/ChangeLog +16 -0
- data/ext/crlibm-1.0beta5/scs_lib/Doxyfile.dev +939 -0
- data/ext/crlibm-1.0beta5/scs_lib/Doxyfile.user +939 -0
- data/ext/crlibm-1.0beta5/scs_lib/INSTALL +215 -0
- data/ext/crlibm-1.0beta5/scs_lib/Makefile.am +17 -0
- data/ext/crlibm-1.0beta5/scs_lib/NEWS +0 -0
- data/ext/crlibm-1.0beta5/scs_lib/README +9 -0
- data/ext/crlibm-1.0beta5/scs_lib/README.DEV +38 -0
- data/ext/crlibm-1.0beta5/scs_lib/TODO +4 -0
- data/ext/crlibm-1.0beta5/scs_lib/VERSION +1 -0
- data/ext/crlibm-1.0beta5/scs_lib/addition_scs.c +623 -0
- data/ext/crlibm-1.0beta5/scs_lib/division_scs.c +110 -0
- data/ext/crlibm-1.0beta5/scs_lib/double2scs.c +174 -0
- data/ext/crlibm-1.0beta5/scs_lib/main.dox +104 -0
- data/ext/crlibm-1.0beta5/scs_lib/multiplication_scs.c +339 -0
- data/ext/crlibm-1.0beta5/scs_lib/poly_fct.c +112 -0
- data/ext/crlibm-1.0beta5/scs_lib/print_scs.c +73 -0
- data/ext/crlibm-1.0beta5/scs_lib/rand_scs.c +63 -0
- data/ext/crlibm-1.0beta5/scs_lib/scs.h +353 -0
- data/ext/crlibm-1.0beta5/scs_lib/scs2double.c +411 -0
- data/ext/crlibm-1.0beta5/scs_lib/scs2mpf.c +58 -0
- data/ext/crlibm-1.0beta5/scs_lib/scs2mpfr.c +61 -0
- data/ext/crlibm-1.0beta5/scs_lib/scs_private.c +23 -0
- data/ext/crlibm-1.0beta5/scs_lib/scs_private.h +133 -0
- data/ext/crlibm-1.0beta5/scs_lib/wrapper_scs.h +486 -0
- data/ext/crlibm-1.0beta5/scs_lib/zero_scs.c +52 -0
- data/ext/crlibm-1.0beta5/trigo_accurate.c +501 -0
- data/ext/crlibm-1.0beta5/trigo_accurate.h +331 -0
- data/ext/crlibm-1.0beta5/trigo_fast.c +1243 -0
- data/ext/crlibm-1.0beta5/trigo_fast.h +639 -0
- data/ext/crlibm-1.0beta5/trigpi.c +1169 -0
- data/ext/crlibm-1.0beta5/trigpi.h +556 -0
- data/ext/crlibm-1.0beta5/triple-double.c +57 -0
- data/ext/crlibm-1.0beta5/triple-double.h +1380 -0
- data/ext/crmf/crmf.c +117 -20
- data/ext/crmf/extconf.rb +12 -8
- data/lib/crmf/version.rb +1 -1
- data/tests/perf.rb +100 -219
- metadata +108 -10
- data/ext/crlibm-1.0beta4.tar.gz +0 -0
@@ -0,0 +1,486 @@
|
|
1
|
+
extern "C"
|
2
|
+
{
|
3
|
+
#include "scs.h"
|
4
|
+
}
|
5
|
+
#include <stdlib.h>
|
6
|
+
#include <stdio.h>
|
7
|
+
#include <math.h>
|
8
|
+
#include <iostream.h>
|
9
|
+
|
10
|
+
#ifndef SCS_WRAPPER_CPP
|
11
|
+
#define SCS_WRAPPER_CPP 1
|
12
|
+
|
13
|
+
extern "C" int scs_cmp_mant(scs_ptr , scs_ptr);
|
14
|
+
|
15
|
+
class Scs{
|
16
|
+
private:
|
17
|
+
scs scsnb;
|
18
|
+
|
19
|
+
public:
|
20
|
+
/* Constructors */
|
21
|
+
Scs(){}
|
22
|
+
Scs(double &d){scs_set_d(&scsnb, d);}
|
23
|
+
Scs(int &i){scs_set_si(&scsnb, i);}
|
24
|
+
Scs(const Scs& nb);
|
25
|
+
~Scs(){};
|
26
|
+
|
27
|
+
/* Mutators */
|
28
|
+
void scs_set_sign (int i) {this->scsnb.sign = i;}
|
29
|
+
void scs_set_index(int i) {this->scsnb.index = i;}
|
30
|
+
void scs_set_excep(double d) {this->scsnb.exception.d = d;}
|
31
|
+
void scs_set_words(unsigned int word[SCS_NB_WORDS]){for(int i=0; i<SCS_NB_WORDS; i++) this->scsnb.h_word[i] = word[i];}
|
32
|
+
|
33
|
+
/* Cast */
|
34
|
+
operator double();
|
35
|
+
operator int();
|
36
|
+
|
37
|
+
|
38
|
+
/* Negation */
|
39
|
+
Scs operator-() const;
|
40
|
+
friend Scs fabs(const Scs &a);
|
41
|
+
|
42
|
+
/* Assignment */
|
43
|
+
Scs &operator=(const Scs &nb1);
|
44
|
+
Scs &operator=(const double nb1);
|
45
|
+
Scs &operator=(const int i){scs_set_si(&scsnb, i);}
|
46
|
+
|
47
|
+
/* Addition */
|
48
|
+
friend Scs operator+(Scs &nb1,Scs &nb2);
|
49
|
+
friend Scs operator+(Scs &nb1, const double &nb2);
|
50
|
+
friend Scs operator+(const double &nb1,Scs &nb2);
|
51
|
+
void operator+=(Scs &nb);
|
52
|
+
void operator+=(const double nb);
|
53
|
+
|
54
|
+
/* Subtraction */
|
55
|
+
friend Scs operator-(Scs &nb1,Scs &nb2);
|
56
|
+
friend Scs operator-(Scs &nb1, const double &nb2);
|
57
|
+
friend Scs operator-(const double &nb1,Scs &nb2);
|
58
|
+
void operator-=(Scs &nb);
|
59
|
+
void operator-=(const double nb);
|
60
|
+
|
61
|
+
/* Multiplication */
|
62
|
+
friend Scs operator*(Scs &nb1,Scs &nb2);
|
63
|
+
friend Scs operator*(Scs &nb1, const double &nb2);
|
64
|
+
friend Scs operator*(const double &nb1,Scs &nb2);
|
65
|
+
friend Scs operator*(Scs &nb1, const int &nb2);
|
66
|
+
friend Scs operator*(const int &nb1,Scs &nb2);
|
67
|
+
void operator*=(Scs &nb);
|
68
|
+
void operator*=(const double nb);
|
69
|
+
void operator*=(const int nb);
|
70
|
+
|
71
|
+
/* Multiplication */
|
72
|
+
friend Scs operator/(Scs &nb1,Scs &nb2);
|
73
|
+
friend Scs operator/(Scs &nb1, const double &nb2);
|
74
|
+
friend Scs operator/(const double &nb1,Scs &nb2);
|
75
|
+
void operator/=(Scs &nb);
|
76
|
+
void operator/=(const double nb);
|
77
|
+
|
78
|
+
/* Comparisons */
|
79
|
+
friend bool operator==(Scs &nb1,Scs &nb2);
|
80
|
+
friend bool operator!=(Scs &nb1,Scs &nb2);
|
81
|
+
friend bool operator<=(Scs &nb1,Scs &nb2);
|
82
|
+
friend bool operator>=(Scs &nb1,Scs &nb2);
|
83
|
+
friend bool operator<(Scs &nb1,Scs &nb2);
|
84
|
+
friend bool operator>(Scs &nb1,Scs &nb2);
|
85
|
+
|
86
|
+
/* Random Number */
|
87
|
+
Scs rand(void);
|
88
|
+
|
89
|
+
/* Input/Output */
|
90
|
+
friend ostream& operator<<(ostream &s, const Scs &a);
|
91
|
+
friend istream& operator>>(istream &s, Scs &a);
|
92
|
+
|
93
|
+
};
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
/**************
|
99
|
+
* CONSTRUCTOR
|
100
|
+
**************/
|
101
|
+
Scs::Scs(const Scs& nb){
|
102
|
+
unsigned int i;
|
103
|
+
|
104
|
+
for(i=0; i<SCS_NB_WORDS; i++)
|
105
|
+
this->scsnb.h_word[i] = nb.scsnb.h_word[i];
|
106
|
+
|
107
|
+
this->scsnb.exception.d = nb.scsnb.exception.d;
|
108
|
+
this->scsnb.index = nb.scsnb.index;
|
109
|
+
this->scsnb.sign = nb.scsnb.sign;
|
110
|
+
}
|
111
|
+
|
112
|
+
/**************
|
113
|
+
* CAST
|
114
|
+
**************/
|
115
|
+
inline Scs::operator double() {
|
116
|
+
double d;
|
117
|
+
scs_get_d(&d, &(this->scsnb));
|
118
|
+
return d;
|
119
|
+
}
|
120
|
+
inline Scs::operator int() {
|
121
|
+
double d;
|
122
|
+
scs_get_d(&d, &(this->scsnb));
|
123
|
+
return ((int)d);
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
/**************
|
129
|
+
* ASSIGNATION
|
130
|
+
**************/
|
131
|
+
inline Scs &Scs::operator=(const Scs& nb){
|
132
|
+
unsigned int i;
|
133
|
+
|
134
|
+
for(i=0; i<SCS_NB_WORDS; i++)
|
135
|
+
scsnb.h_word[i] = nb.scsnb.h_word[i];
|
136
|
+
|
137
|
+
scsnb.exception.d = nb.scsnb.exception.d;
|
138
|
+
scsnb.index = nb.scsnb.index;
|
139
|
+
scsnb.sign = nb.scsnb.sign;
|
140
|
+
|
141
|
+
return *this;
|
142
|
+
}
|
143
|
+
inline Scs &Scs::operator=(const double nb){
|
144
|
+
scs_set_d(&(this->scsnb), nb);
|
145
|
+
return *this;
|
146
|
+
}
|
147
|
+
inline Scs fabs(const Scs &a){
|
148
|
+
Scs res(a);
|
149
|
+
res.scsnb.sign = 1;
|
150
|
+
return res;
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
/************
|
155
|
+
* ADDITION
|
156
|
+
************/
|
157
|
+
inline Scs operator+(Scs &nb1,Scs &nb2){
|
158
|
+
Scs res; scs_add(&(res.scsnb), &(nb1.scsnb), &(nb2.scsnb));
|
159
|
+
return res;
|
160
|
+
}
|
161
|
+
inline Scs operator+(Scs &nb1,const double &nb2){
|
162
|
+
Scs res, op;
|
163
|
+
scs_set_d(&(op.scsnb), nb2);
|
164
|
+
scs_add(&(res.scsnb), &(nb1.scsnb), &(op.scsnb));
|
165
|
+
return res;
|
166
|
+
}
|
167
|
+
inline Scs operator+(const double &nb1, Scs &nb2){
|
168
|
+
Scs res, op;
|
169
|
+
scs_set_d(&(op.scsnb), nb1);
|
170
|
+
scs_add(&(res.scsnb), &(nb2.scsnb), &(op.scsnb));
|
171
|
+
return res;
|
172
|
+
}
|
173
|
+
void inline Scs::operator+=(Scs &nb) {
|
174
|
+
scs_add(&(this->scsnb), &(this->scsnb), &(nb.scsnb));
|
175
|
+
}
|
176
|
+
void inline Scs::operator+=(const double nb) {
|
177
|
+
Scs op;
|
178
|
+
scs_set_d(&(op.scsnb), nb);
|
179
|
+
scs_add(&(this->scsnb), &(this->scsnb), &(op.scsnb));
|
180
|
+
}
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
/**************
|
186
|
+
* SUBTRACTION
|
187
|
+
**************/
|
188
|
+
inline Scs operator-(Scs &nb1,Scs &nb2){
|
189
|
+
Scs res; scs_sub(&(res.scsnb), &(nb1.scsnb), &(nb2.scsnb));
|
190
|
+
return res;
|
191
|
+
}
|
192
|
+
inline Scs operator-(Scs &nb1,const double &nb2){
|
193
|
+
Scs res, op;
|
194
|
+
scs_set_d(&(op.scsnb), nb2);
|
195
|
+
scs_sub(&(res.scsnb), &(nb1.scsnb), &(op.scsnb));
|
196
|
+
return res;
|
197
|
+
}
|
198
|
+
inline Scs operator-(const double &nb1, Scs &nb2){
|
199
|
+
Scs res, op;
|
200
|
+
scs_set_d(&(op.scsnb), nb1);
|
201
|
+
scs_sub(&(res.scsnb), &(nb2.scsnb), &(op.scsnb));
|
202
|
+
return res;
|
203
|
+
}
|
204
|
+
void inline Scs::operator-=(Scs &nb) {
|
205
|
+
scs_sub(&(this->scsnb), &(this->scsnb), &(nb.scsnb));
|
206
|
+
}
|
207
|
+
void inline Scs::operator-=(const double nb) {
|
208
|
+
Scs op;
|
209
|
+
scs_set_d(&(op.scsnb), nb);
|
210
|
+
scs_sub(&(this->scsnb), &(this->scsnb), &(op.scsnb));
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
/*****************
|
216
|
+
* MULTIPLICATION
|
217
|
+
*****************/
|
218
|
+
inline Scs operator*(Scs &nb1,Scs &nb2){
|
219
|
+
Scs res; scs_mul(&(res.scsnb), &(nb1.scsnb), &(nb2.scsnb));
|
220
|
+
return res;
|
221
|
+
}
|
222
|
+
inline Scs operator*(Scs &nb1,const double &nb2){
|
223
|
+
Scs res, op;
|
224
|
+
scs_set_d(&(op.scsnb), nb2);
|
225
|
+
scs_mul(&(res.scsnb), &(nb1.scsnb), &(op.scsnb));
|
226
|
+
return res;
|
227
|
+
}
|
228
|
+
inline Scs operator*(const double &nb1, Scs &nb2){
|
229
|
+
Scs res, op;
|
230
|
+
scs_set_d(&(op.scsnb), nb1);
|
231
|
+
scs_mul(&(res.scsnb), &(nb2.scsnb), &(op.scsnb));
|
232
|
+
return res;
|
233
|
+
}
|
234
|
+
inline Scs operator*(Scs &nb1, const int &nb2){
|
235
|
+
Scs res;
|
236
|
+
scs_set(&(res.scsnb), &(nb1.scsnb));
|
237
|
+
scs_mul_ui(&(res.scsnb), nb2);
|
238
|
+
return res;
|
239
|
+
}
|
240
|
+
inline Scs operator*(const int &nb1, Scs &nb2){
|
241
|
+
Scs res;
|
242
|
+
scs_set(&(res.scsnb), &(nb2.scsnb));
|
243
|
+
scs_mul_ui(&(res.scsnb), nb1);
|
244
|
+
return res;
|
245
|
+
}
|
246
|
+
void inline Scs::operator*=(Scs &nb) {
|
247
|
+
scs_mul(&(this->scsnb), &(this->scsnb), &(nb.scsnb));
|
248
|
+
}
|
249
|
+
void inline Scs::operator*=(const double nb) {
|
250
|
+
Scs op;
|
251
|
+
scs_set_d(&(op.scsnb), nb);
|
252
|
+
scs_mul(&(this->scsnb), &(this->scsnb), &(op.scsnb));
|
253
|
+
}
|
254
|
+
void inline Scs::operator*=(const int nb) {
|
255
|
+
scs_mul_ui(&(this->scsnb), nb);
|
256
|
+
}
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
/*****************
|
261
|
+
* DIVISION
|
262
|
+
*****************/
|
263
|
+
inline Scs operator/(Scs &nb1,Scs &nb2){
|
264
|
+
Scs res; scs_div(&(res.scsnb), &(nb1.scsnb), &(nb2.scsnb));
|
265
|
+
return res;
|
266
|
+
}
|
267
|
+
inline Scs operator/(Scs &nb1, const double &nb2){
|
268
|
+
Scs res, op;
|
269
|
+
scs_set_d(&(op.scsnb), nb2);
|
270
|
+
scs_div(&(res.scsnb), &(nb1.scsnb), &(op.scsnb));
|
271
|
+
return res;
|
272
|
+
}
|
273
|
+
inline Scs operator/(const double &nb1, Scs &nb2){
|
274
|
+
Scs res, op;
|
275
|
+
scs_set_d(&(op.scsnb), nb1);
|
276
|
+
scs_div(&(res.scsnb), &(nb2.scsnb), &(op.scsnb));
|
277
|
+
return res;
|
278
|
+
}
|
279
|
+
void inline Scs::operator/=(Scs &nb) {
|
280
|
+
scs_div(&(this->scsnb), &(this->scsnb), &(nb.scsnb));
|
281
|
+
}
|
282
|
+
void inline Scs::operator/=(const double nb) {
|
283
|
+
Scs op;
|
284
|
+
scs_set_d(&(op.scsnb), nb);
|
285
|
+
scs_div(&(this->scsnb), &(this->scsnb), &(op.scsnb));
|
286
|
+
}
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
/*************
|
291
|
+
* COMPARISON
|
292
|
+
*************/
|
293
|
+
inline bool operator==(Scs &nb1, Scs &nb2){
|
294
|
+
unsigned int i;
|
295
|
+
bool b=1;
|
296
|
+
|
297
|
+
for(i=0; i<SCS_NB_WORDS; i++)
|
298
|
+
if (nb1.scsnb.h_word[i] == nb2.scsnb.h_word[i]) b=0;
|
299
|
+
|
300
|
+
return ((nb1.scsnb.exception.d == nb2.scsnb.exception.d)&&
|
301
|
+
(nb1.scsnb.index == nb2.scsnb.index)&&
|
302
|
+
(nb1.scsnb.sign == nb2.scsnb.sign)&& b);
|
303
|
+
}
|
304
|
+
inline bool operator!=(Scs &nb1, Scs &nb2){
|
305
|
+
return !(nb1==nb2);
|
306
|
+
}
|
307
|
+
inline bool operator<=(Scs &nb1, Scs &nb2){
|
308
|
+
return ((nb1.scsnb.exception.d <= nb2.scsnb.exception.d)&&
|
309
|
+
(nb1.scsnb.sign <= nb2.scsnb.sign)&&
|
310
|
+
((nb1.scsnb.index < nb2.scsnb.index)||
|
311
|
+
((nb1.scsnb.index == nb2.scsnb.index)&&
|
312
|
+
(scs_cmp_mant(&(nb1.scsnb), &(nb2.scsnb))<=0))));
|
313
|
+
}
|
314
|
+
inline bool operator>=(Scs &nb1, Scs &nb2){
|
315
|
+
return ((nb1.scsnb.exception.d >= nb2.scsnb.exception.d)&&
|
316
|
+
(nb1.scsnb.sign >= nb2.scsnb.sign)&&
|
317
|
+
((nb1.scsnb.index > nb2.scsnb.index)||
|
318
|
+
((nb1.scsnb.index == nb2.scsnb.index)&&
|
319
|
+
(scs_cmp_mant(&(nb1.scsnb), &(nb2.scsnb))>=0))));
|
320
|
+
}
|
321
|
+
inline bool operator<(Scs &nb1, Scs &nb2){
|
322
|
+
return ((nb1.scsnb.exception.d <= nb2.scsnb.exception.d)&&
|
323
|
+
(nb1.scsnb.sign <= nb2.scsnb.sign)&&
|
324
|
+
((nb1.scsnb.index < nb2.scsnb.index)||
|
325
|
+
((nb1.scsnb.index == nb2.scsnb.index)&&
|
326
|
+
(scs_cmp_mant(&(nb1.scsnb), &(nb2.scsnb))<0))));
|
327
|
+
}
|
328
|
+
inline bool operator>(Scs &nb1, Scs &nb2){
|
329
|
+
return ((nb1.scsnb.exception.d >= nb2.scsnb.exception.d)&&
|
330
|
+
(nb1.scsnb.sign >= nb2.scsnb.sign)&&
|
331
|
+
((nb1.scsnb.index > nb2.scsnb.index)||
|
332
|
+
((nb1.scsnb.index == nb2.scsnb.index)&&
|
333
|
+
(scs_cmp_mant(&(nb1.scsnb), &(nb2.scsnb))>0))));
|
334
|
+
}
|
335
|
+
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
/****************
|
340
|
+
* RANDOM NUMBER
|
341
|
+
****************/
|
342
|
+
inline Scs Scs::rand(void){
|
343
|
+
scs_rand(&(this->scsnb), 200);
|
344
|
+
return *this;
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
/***************
|
351
|
+
* OUTPUT (in hexadecimal)
|
352
|
+
***************/
|
353
|
+
ostream &operator<<(ostream &os, const Scs &a){
|
354
|
+
Scs aa, p, zer;
|
355
|
+
double d;
|
356
|
+
char buffer[10];
|
357
|
+
int e, exposant;
|
358
|
+
bool bb;
|
359
|
+
|
360
|
+
if (a.scsnb.exception.d != 1.){
|
361
|
+
os << (double)a.scsnb.exception.d;
|
362
|
+
}else {
|
363
|
+
if (a.scsnb.sign == -1)
|
364
|
+
os << '-';
|
365
|
+
|
366
|
+
aa = fabs(a);
|
367
|
+
|
368
|
+
/* Compute the exposant in radix 16 */
|
369
|
+
d = ((a.scsnb.index)*SCS_NB_BITS)/4;
|
370
|
+
e = 4*(int)floor(d);
|
371
|
+
|
372
|
+
p = 1;
|
373
|
+
p.scsnb.index = (int)floor(((double)e)/SCS_NB_BITS);
|
374
|
+
p.scsnb.h_word[0] = 1 << e - p.scsnb.index*SCS_NB_BITS;
|
375
|
+
exposant = (int)floor(d);
|
376
|
+
p /= 16;
|
377
|
+
exposant--;
|
378
|
+
while(p <= aa){
|
379
|
+
p *= 16;
|
380
|
+
exposant++;
|
381
|
+
}
|
382
|
+
p /= 16;
|
383
|
+
exposant--;
|
384
|
+
|
385
|
+
/* Extract digits */
|
386
|
+
aa = aa / p;
|
387
|
+
sprintf(buffer,"%x", aa.scsnb.h_word[0]);
|
388
|
+
os << buffer << ".";
|
389
|
+
aa.scsnb.h_word[0] = 0;
|
390
|
+
aa *= 16;
|
391
|
+
|
392
|
+
bb = 1;
|
393
|
+
while(bb){
|
394
|
+
sprintf(buffer,"%x", aa.scsnb.h_word[0]);
|
395
|
+
os << buffer;
|
396
|
+
aa.scsnb.h_word[0] = 0;
|
397
|
+
aa *= 16;
|
398
|
+
|
399
|
+
bb = 0;
|
400
|
+
for(int i=0; i<SCS_NB_WORDS; i++)
|
401
|
+
if (aa.scsnb.h_word[i] != 0) bb=1;
|
402
|
+
}
|
403
|
+
|
404
|
+
/* Write the exponent */
|
405
|
+
os << " x16^(" << exposant <<")";
|
406
|
+
}
|
407
|
+
|
408
|
+
return os;
|
409
|
+
}
|
410
|
+
|
411
|
+
|
412
|
+
/***************
|
413
|
+
* INPUT (in decimal)
|
414
|
+
***************/
|
415
|
+
istream& operator>>(istream &is, Scs &a){
|
416
|
+
char c;
|
417
|
+
int nd = 0;
|
418
|
+
int point = -1;
|
419
|
+
int ex;
|
420
|
+
bool done = false;
|
421
|
+
Scs r;
|
422
|
+
|
423
|
+
r = 0;
|
424
|
+
|
425
|
+
/* Skip any leading spaces */
|
426
|
+
do{
|
427
|
+
is>>c;
|
428
|
+
}while (c == ' ');
|
429
|
+
|
430
|
+
/* Read sign, digits, and exponent */
|
431
|
+
while (!done && (c != '\0')) {
|
432
|
+
if (c >= '0' && c <= '9') {
|
433
|
+
int d = c - '0';
|
434
|
+
r *= 10.0;
|
435
|
+
r += d;
|
436
|
+
nd++;
|
437
|
+
} else {
|
438
|
+
switch (c) {
|
439
|
+
case '.':
|
440
|
+
point = nd;
|
441
|
+
break;
|
442
|
+
case '-':
|
443
|
+
case '+':
|
444
|
+
if (nd > 0){
|
445
|
+
a = 0;
|
446
|
+
done = true;
|
447
|
+
point = -1;
|
448
|
+
ex = 0;
|
449
|
+
}
|
450
|
+
a.scsnb.sign = (c == '-') ? -1 : 1;
|
451
|
+
break;
|
452
|
+
case 'E':
|
453
|
+
case 'e':
|
454
|
+
is >> ex;
|
455
|
+
done = true;
|
456
|
+
break;
|
457
|
+
default:
|
458
|
+
a = 0;
|
459
|
+
done = true;
|
460
|
+
point = -1;
|
461
|
+
ex = 0;
|
462
|
+
}
|
463
|
+
}
|
464
|
+
is>>c;
|
465
|
+
}
|
466
|
+
|
467
|
+
if (point >= 0)
|
468
|
+
ex -= (nd - point);
|
469
|
+
|
470
|
+
|
471
|
+
if (ex != 0) {
|
472
|
+
if (ex > 0)
|
473
|
+
for(int i=0; i<ex; i++)
|
474
|
+
r *= 10;
|
475
|
+
if (ex < 0){
|
476
|
+
Scs inv_ten, ten;
|
477
|
+
ten = 10;
|
478
|
+
scs_inv(&(inv_ten.scsnb), &(ten.scsnb) );
|
479
|
+
for(int i=0; i>ex; i--)
|
480
|
+
r *= inv_ten;
|
481
|
+
}
|
482
|
+
}
|
483
|
+
}
|
484
|
+
#endif
|
485
|
+
|
486
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
/** Function for setting an SCS number to zero
|
2
|
+
@file zero_scs.c
|
3
|
+
|
4
|
+
@author Defour David David.Defour@ens-lyon.fr
|
5
|
+
@author Florent de Dinechin Florent.de.Dinechin@ens-lyon.fr
|
6
|
+
|
7
|
+
This file is part of the SCS library.
|
8
|
+
*/
|
9
|
+
|
10
|
+
/*
|
11
|
+
Copyright (C) 2002 David Defour and Florent de Dinechin
|
12
|
+
|
13
|
+
This library is free software; you can redistribute it and/or
|
14
|
+
modify it under the terms of the GNU Lesser General Public
|
15
|
+
License as published by the Free Software Foundation; either
|
16
|
+
version 2.1 of the License, or (at your option) any later version.
|
17
|
+
|
18
|
+
This library is distributed in the hope that it will be useful,
|
19
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
21
|
+
Lesser General Public License for more details.
|
22
|
+
|
23
|
+
You should have received a copy of the GNU Lesser General Public
|
24
|
+
License along with this library; if not, write to the Free Software
|
25
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
26
|
+
|
27
|
+
*/
|
28
|
+
|
29
|
+
|
30
|
+
#include "scs.h"
|
31
|
+
#include "scs_private.h"
|
32
|
+
|
33
|
+
|
34
|
+
/** Set a SCS number to zero.
|
35
|
+
There should be a few simple functions in this library.
|
36
|
+
*/
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
void inline scs_zero(scs_ptr result) {
|
41
|
+
int i;
|
42
|
+
|
43
|
+
for(i=0; i<SCS_NB_WORDS; i++)
|
44
|
+
R_HW[i] = 0;
|
45
|
+
|
46
|
+
R_EXP = 0;
|
47
|
+
R_IND = 0;
|
48
|
+
R_SGN = 1;
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
|