intervals 0.3.56
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.txt +1 -0
- data/ext/crlibm/AUTHORS +2 -0
- data/ext/crlibm/COPYING +504 -0
- data/ext/crlibm/ChangeLog +80 -0
- data/ext/crlibm/INSTALL +182 -0
- data/ext/crlibm/Makefile.am +84 -0
- data/ext/crlibm/Makefile.in +530 -0
- data/ext/crlibm/NEWS +0 -0
- data/ext/crlibm/README +31 -0
- data/ext/crlibm/TODO +47 -0
- data/ext/crlibm/VERSION +1 -0
- data/ext/crlibm/aclocal.m4 +989 -0
- data/ext/crlibm/atan-itanium.c +846 -0
- data/ext/crlibm/atan-pentium.c +261 -0
- data/ext/crlibm/atan_accurate.c +244 -0
- data/ext/crlibm/atan_accurate.h +191 -0
- data/ext/crlibm/atan_fast.c +324 -0
- data/ext/crlibm/atan_fast.h +678 -0
- data/ext/crlibm/config.guess +1461 -0
- data/ext/crlibm/config.sub +1566 -0
- data/ext/crlibm/configure +7517 -0
- data/ext/crlibm/configure.ac +364 -0
- data/ext/crlibm/crlibm.h +125 -0
- data/ext/crlibm/crlibm_config.h +149 -0
- data/ext/crlibm/crlibm_config.h.in +148 -0
- data/ext/crlibm/crlibm_private.c +293 -0
- data/ext/crlibm/crlibm_private.h +658 -0
- data/ext/crlibm/csh_fast.c +631 -0
- data/ext/crlibm/csh_fast.h +771 -0
- data/ext/crlibm/double-extended.h +496 -0
- data/ext/crlibm/exp-td.c +962 -0
- data/ext/crlibm/exp-td.h +685 -0
- data/ext/crlibm/exp_accurate.c +197 -0
- data/ext/crlibm/exp_accurate.h +85 -0
- data/ext/crlibm/gappa/log-de-E0-logir0.gappa +106 -0
- data/ext/crlibm/gappa/log-de-E0.gappa +79 -0
- data/ext/crlibm/gappa/log-de.gappa +81 -0
- data/ext/crlibm/gappa/log-td-E0-logir0.gappa +126 -0
- data/ext/crlibm/gappa/log-td-E0.gappa +143 -0
- data/ext/crlibm/gappa/log-td-accurate-E0-logir0.gappa +230 -0
- data/ext/crlibm/gappa/log-td-accurate-E0.gappa +213 -0
- data/ext/crlibm/gappa/log-td-accurate.gappa +217 -0
- data/ext/crlibm/gappa/log-td.gappa +156 -0
- data/ext/crlibm/gappa/trigoSinCosCase3.gappa +204 -0
- data/ext/crlibm/gappa/trigoTanCase2.gappa +73 -0
- data/ext/crlibm/install-sh +269 -0
- data/ext/crlibm/log-de.c +431 -0
- data/ext/crlibm/log-de.h +732 -0
- data/ext/crlibm/log-td.c +852 -0
- data/ext/crlibm/log-td.h +819 -0
- data/ext/crlibm/log10-td.c +906 -0
- data/ext/crlibm/log10-td.h +823 -0
- data/ext/crlibm/log2-td.c +935 -0
- data/ext/crlibm/log2-td.h +821 -0
- data/ext/crlibm/maple/atan.mpl +359 -0
- data/ext/crlibm/maple/common-procedures.mpl +997 -0
- data/ext/crlibm/maple/csh.mpl +446 -0
- data/ext/crlibm/maple/double-extended.mpl +151 -0
- data/ext/crlibm/maple/exp-td.mpl +195 -0
- data/ext/crlibm/maple/log-de.mpl +243 -0
- data/ext/crlibm/maple/log-td.mpl +316 -0
- data/ext/crlibm/maple/log10-td.mpl +345 -0
- data/ext/crlibm/maple/log2-td.mpl +334 -0
- data/ext/crlibm/maple/trigo.mpl +728 -0
- data/ext/crlibm/maple/triple-double.mpl +58 -0
- data/ext/crlibm/missing +198 -0
- data/ext/crlibm/mkinstalldirs +40 -0
- data/ext/crlibm/rem_pio2_accurate.c +219 -0
- data/ext/crlibm/rem_pio2_accurate.h +53 -0
- data/ext/crlibm/scs_lib/AUTHORS +3 -0
- data/ext/crlibm/scs_lib/COPYING +504 -0
- data/ext/crlibm/scs_lib/ChangeLog +16 -0
- data/ext/crlibm/scs_lib/INSTALL +215 -0
- data/ext/crlibm/scs_lib/Makefile.am +18 -0
- data/ext/crlibm/scs_lib/Makefile.in +328 -0
- data/ext/crlibm/scs_lib/NEWS +0 -0
- data/ext/crlibm/scs_lib/README +9 -0
- data/ext/crlibm/scs_lib/TODO +4 -0
- data/ext/crlibm/scs_lib/addition_scs.c +623 -0
- data/ext/crlibm/scs_lib/config.guess +1461 -0
- data/ext/crlibm/scs_lib/config.sub +1566 -0
- data/ext/crlibm/scs_lib/configure +6226 -0
- data/ext/crlibm/scs_lib/division_scs.c +110 -0
- data/ext/crlibm/scs_lib/double2scs.c +174 -0
- data/ext/crlibm/scs_lib/install-sh +269 -0
- data/ext/crlibm/scs_lib/missing +198 -0
- data/ext/crlibm/scs_lib/mkinstalldirs +40 -0
- data/ext/crlibm/scs_lib/multiplication_scs.c +456 -0
- data/ext/crlibm/scs_lib/poly_fct.c +112 -0
- data/ext/crlibm/scs_lib/print_scs.c +73 -0
- data/ext/crlibm/scs_lib/rand_scs.c +63 -0
- data/ext/crlibm/scs_lib/scs.h +353 -0
- data/ext/crlibm/scs_lib/scs2double.c +391 -0
- data/ext/crlibm/scs_lib/scs2mpf.c +58 -0
- data/ext/crlibm/scs_lib/scs2mpfr.c +61 -0
- data/ext/crlibm/scs_lib/scs_private.c +23 -0
- data/ext/crlibm/scs_lib/scs_private.h +133 -0
- data/ext/crlibm/scs_lib/tests/tbx_timing.h +102 -0
- data/ext/crlibm/scs_lib/wrapper_scs.h +486 -0
- data/ext/crlibm/scs_lib/zero_scs.c +52 -0
- data/ext/crlibm/stamp-h.in +1 -0
- data/ext/crlibm/tests/Makefile.am +43 -0
- data/ext/crlibm/tests/Makefile.in +396 -0
- data/ext/crlibm/tests/blind_test.c +148 -0
- data/ext/crlibm/tests/generate_test_vectors.c +258 -0
- data/ext/crlibm/tests/soak_test.c +334 -0
- data/ext/crlibm/tests/test_common.c +627 -0
- data/ext/crlibm/tests/test_common.h +28 -0
- data/ext/crlibm/tests/test_perf.c +570 -0
- data/ext/crlibm/tests/test_val.c +249 -0
- data/ext/crlibm/trigo_accurate.c +500 -0
- data/ext/crlibm/trigo_accurate.h +331 -0
- data/ext/crlibm/trigo_fast.c +1219 -0
- data/ext/crlibm/trigo_fast.h +639 -0
- data/ext/crlibm/triple-double.h +878 -0
- data/ext/extconf.rb +31 -0
- data/ext/fpu.c +107 -0
- data/ext/jamis-mod.rb +591 -0
- data/lib/fpu.rb +287 -0
- data/lib/interval.rb +1170 -0
- data/lib/intervals.rb +212 -0
- data/lib/struct_float.rb +133 -0
- data/test/data_atan.txt +360 -0
- data/test/data_cos.txt +346 -0
- data/test/data_cosh.txt +3322 -0
- data/test/data_exp.txt +3322 -0
- data/test/data_log.txt +141 -0
- data/test/data_sin.txt +140 -0
- data/test/data_sinh.txt +3322 -0
- data/test/data_tan.txt +342 -0
- metadata +186 -0
@@ -0,0 +1,112 @@
|
|
1
|
+
/*
|
2
|
+
* Author : Defour David
|
3
|
+
* Contact : David.Defour@ens-lyon.fr
|
4
|
+
*
|
5
|
+
* This program is free software; you can redistribute it and/or modify
|
6
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
* the Free Software Foundation; either version 2 of the License, or
|
8
|
+
* (at your option) any later version.
|
9
|
+
*
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
* GNU General Public License for more details.
|
14
|
+
*
|
15
|
+
* You should have received a copy of the GNU Lesser General Public License
|
16
|
+
* along with this program; if not, write to the Free Software
|
17
|
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18
|
+
*/
|
19
|
+
#include "scs.h"
|
20
|
+
#include "scs_private.h"
|
21
|
+
|
22
|
+
|
23
|
+
/*
|
24
|
+
* result = z + (x * y)
|
25
|
+
*/
|
26
|
+
/* z->sign = X_SGN . Y_SGN */
|
27
|
+
void scs_fma(scs_ptr result, scs_ptr x, scs_ptr y, scs_ptr z){
|
28
|
+
uint64_t RES[2*SCS_NB_WORDS];
|
29
|
+
uint64_t val, tmp;
|
30
|
+
int i, j, ind, Diff;
|
31
|
+
|
32
|
+
ind = X_IND + Y_IND;
|
33
|
+
|
34
|
+
for(i=0; i<=SCS_NB_WORDS+1; i++)
|
35
|
+
RES[i]=0;
|
36
|
+
|
37
|
+
for(i=0 ; i<SCS_NB_WORDS; i++){
|
38
|
+
for(j=0; j<(SCS_NB_WORDS-i); j++){
|
39
|
+
RES[i+j] += (uint64_t)X_HW[i] * Y_HW[j];
|
40
|
+
}}
|
41
|
+
|
42
|
+
/* if we can perform an add */
|
43
|
+
if (z->sign == (X_SGN * Y_SGN)){
|
44
|
+
Diff = z->index - ind;
|
45
|
+
if (Diff >= 0){
|
46
|
+
for(i=(SCS_NB_WORDS-1), j=(SCS_NB_WORDS-Diff); j>=0; i--, j--)
|
47
|
+
RES[i] = z->h_word[i] + RES[j];
|
48
|
+
for( ; i>=0; i--)
|
49
|
+
RES[i] = z->h_word[i];
|
50
|
+
}else {
|
51
|
+
for(i=(SCS_NB_WORDS+Diff), j=(SCS_NB_WORDS-1); i>=0; i--, j--)
|
52
|
+
RES[j] = z->h_word[i] + RES[j];
|
53
|
+
}
|
54
|
+
|
55
|
+
/* Carry propagate */
|
56
|
+
RES[SCS_NB_WORDS-1] += (RES[SCS_NB_WORDS]>>SCS_NB_BITS);
|
57
|
+
for(i=(SCS_NB_WORDS-1); i>0; i--)
|
58
|
+
{tmp = RES[i]>>SCS_NB_BITS; RES[i-1] += tmp; RES[i] -= (tmp<<SCS_NB_BITS);}
|
59
|
+
|
60
|
+
val = RES[0] >> SCS_NB_BITS;
|
61
|
+
R_IND = X_IND + Y_IND;
|
62
|
+
|
63
|
+
/* Store the result */
|
64
|
+
if(val != 0){
|
65
|
+
/* shift all the digits ! */
|
66
|
+
R_HW[0] = (unsigned int)val;
|
67
|
+
R_HW[1] = (unsigned int)(RES[0] - (val<<SCS_NB_BITS));
|
68
|
+
for(i=2; i<SCS_NB_WORDS; i++)
|
69
|
+
R_HW[i] = (unsigned int)RES[i-1];
|
70
|
+
|
71
|
+
R_IND += 1;
|
72
|
+
}
|
73
|
+
else {
|
74
|
+
for(i=0; i<SCS_NB_WORDS; i++)
|
75
|
+
R_HW[i] = (unsigned int)RES[i];
|
76
|
+
}
|
77
|
+
|
78
|
+
R_EXP = (z->exception.d + (X_EXP * Y_EXP)) - 1;
|
79
|
+
R_SGN = X_SGN * Y_SGN;
|
80
|
+
|
81
|
+
}else {
|
82
|
+
/* we have to do a sub */
|
83
|
+
|
84
|
+
/* Carry propagate */
|
85
|
+
RES[SCS_NB_WORDS-1] += (RES[SCS_NB_WORDS]>>SCS_NB_BITS);
|
86
|
+
for(i=(SCS_NB_WORDS-1); i>0; i--)
|
87
|
+
{tmp = RES[i]>>SCS_NB_BITS; RES[i-1] += tmp; RES[i] -= (tmp<<SCS_NB_BITS);}
|
88
|
+
|
89
|
+
val = RES[0] >> SCS_NB_BITS;
|
90
|
+
R_IND = X_IND + Y_IND;
|
91
|
+
|
92
|
+
/* Store the result */
|
93
|
+
if(val != 0){
|
94
|
+
/* shift all the digits ! */
|
95
|
+
R_HW[0] = (unsigned int)val;
|
96
|
+
R_HW[1] = (unsigned int)(RES[0] - (val<<SCS_NB_BITS));
|
97
|
+
for(i=2; i<SCS_NB_WORDS; i++)
|
98
|
+
R_HW[i] = (unsigned int)RES[i-1];
|
99
|
+
|
100
|
+
R_IND += 1;
|
101
|
+
}
|
102
|
+
else {
|
103
|
+
for(i=0; i<SCS_NB_WORDS; i++)
|
104
|
+
R_HW[i] = (unsigned int)RES[i];
|
105
|
+
}
|
106
|
+
|
107
|
+
R_EXP = (X_EXP * Y_EXP);
|
108
|
+
R_SGN = X_SGN * Y_SGN;
|
109
|
+
|
110
|
+
scs_add(result, result, z);
|
111
|
+
}
|
112
|
+
}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
/*
|
2
|
+
* Author : Defour David
|
3
|
+
* Contact : David.Defour@ens-lyon.fr
|
4
|
+
*
|
5
|
+
* This program is free software; you can redistribute it and/or modify
|
6
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
* the Free Software Foundation; either version 2 of the License, or
|
8
|
+
* (at your option) any later version.
|
9
|
+
*
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
* GNU General Public License for more details.
|
14
|
+
*
|
15
|
+
* You should have received a copy of the GNU Lesser General Public License
|
16
|
+
* along with this program; if not, write to the Free Software
|
17
|
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18
|
+
*/
|
19
|
+
#include <stdio.h>
|
20
|
+
#include "scs.h"
|
21
|
+
#include "scs_private.h"
|
22
|
+
|
23
|
+
|
24
|
+
/*
|
25
|
+
* used by the next function to write
|
26
|
+
* bit of the integer in the right order ....
|
27
|
+
*/
|
28
|
+
static void print_order(unsigned int x, int nb, int b){
|
29
|
+
if (nb<=0)
|
30
|
+
return;
|
31
|
+
print_order(x/b, nb-1, b);
|
32
|
+
printf("%u",x%b);
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
/*
|
36
|
+
* print nb digits of the chain x in base "b"
|
37
|
+
* b must be between 1 and 10
|
38
|
+
*/
|
39
|
+
static void print_integer(unsigned int x, int b, int nb){
|
40
|
+
|
41
|
+
if ((b < 2)||(b>16)){
|
42
|
+
fprintf(stderr," ERROR: You musn't print number with a base larger than 10 or less than 2 \n");
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
print_order(x, nb, b);
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
/*
|
51
|
+
* Convert a double precision number in it scs multiprecision
|
52
|
+
* representation
|
53
|
+
*
|
54
|
+
* Rem. : We haven't tested all special cases yet.
|
55
|
+
*/
|
56
|
+
|
57
|
+
/*
|
58
|
+
*/
|
59
|
+
void scs_get_std( scs_ptr x){
|
60
|
+
int i;
|
61
|
+
db_number d;
|
62
|
+
|
63
|
+
scs_get_d(&d.d, x);
|
64
|
+
printf("Exception : %e \n", X_EXP);
|
65
|
+
printf("Index= %d \n Sign= %d \n Double value= %.30e \n Hex mantissa= %x %x\n",
|
66
|
+
X_IND, X_SGN, d.d, d.i[HI], d.i[LO]);
|
67
|
+
for(i=0;i<SCS_NB_WORDS;i++){
|
68
|
+
printf(" D %d : %8x %20u \n",i, X_HW[i], X_HW[i]);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
|
73
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
/*
|
2
|
+
* Author : Defour David
|
3
|
+
* Contact : David.Defour@ens-lyon.fr
|
4
|
+
*
|
5
|
+
* This program is free software; you can redistribute it and/or modify
|
6
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
* the Free Software Foundation; either version 2 of the License, or
|
8
|
+
* (at your option) any later version.
|
9
|
+
*
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
* GNU General Public License for more details.
|
14
|
+
*
|
15
|
+
* You should have received a copy of the GNU Lesser General Public License
|
16
|
+
* along with this program; if not, write to the Free Software
|
17
|
+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18
|
+
*/
|
19
|
+
#include <stdlib.h>
|
20
|
+
#include "scs.h"
|
21
|
+
#include "scs_private.h"
|
22
|
+
|
23
|
+
/*
|
24
|
+
* Return 'sizeof(int)' random bits
|
25
|
+
*/
|
26
|
+
|
27
|
+
|
28
|
+
int rand_val(void){
|
29
|
+
int val;
|
30
|
+
int i;
|
31
|
+
|
32
|
+
val = (rand() & 0x000000ff);
|
33
|
+
for(i=0; i<(sizeof(int)); i++){
|
34
|
+
val = val << 8;
|
35
|
+
val += (rand() & 0x000000ff ); /* we keep only 8 bits */
|
36
|
+
}
|
37
|
+
return val;
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
/*
|
42
|
+
* Put into 'result' a scs random number with the index field set
|
43
|
+
* with a value between -expo_max and +expo_max.
|
44
|
+
*
|
45
|
+
* Rem. :
|
46
|
+
* 1) If you want an scs number belonging to double precision floating
|
47
|
+
* point number you must call scs_rand with an expo_max less than 39.
|
48
|
+
* 2) expo_max must be less than RAND_MAX that is usually set a
|
49
|
+
* value greater than 32767
|
50
|
+
*/
|
51
|
+
void scs_rand(scs_ptr result, int expo_max){
|
52
|
+
int i;
|
53
|
+
|
54
|
+
R_EXP = 1;
|
55
|
+
R_IND = (rand() % (2*expo_max)) - expo_max;
|
56
|
+
R_SGN = ((2*rand()- RAND_MAX) > 0) ? (-1) : (1);
|
57
|
+
|
58
|
+
|
59
|
+
for(i=0; i<SCS_NB_WORDS; i++){
|
60
|
+
/* We keep the first SCS_NB_BITS bits of a random value */
|
61
|
+
R_HW[i] = rand_val() & SCS_MASK_RADIX;
|
62
|
+
}
|
63
|
+
}
|
@@ -0,0 +1,353 @@
|
|
1
|
+
/** This is the main header file of the SCS library, which defines the
|
2
|
+
SCS data structure, and the functions that implement arithmetic on it.
|
3
|
+
|
4
|
+
@file scs.h
|
5
|
+
|
6
|
+
@author David Defour David.Defour@ens-lyon.fr
|
7
|
+
@author Florent de Dinechin Florent.de.Dinechin@ens-lyon.fr
|
8
|
+
|
9
|
+
This file is part of the SCS library.
|
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
|
+
|
31
|
+
/* Avoid loading the header twice */
|
32
|
+
#ifndef INCLUDE_SCS
|
33
|
+
#define INCLUDE_SCS 1
|
34
|
+
|
35
|
+
#ifndef DOXYGEN_SHOULD_SKIP_THIS /* because it is not very clean */
|
36
|
+
|
37
|
+
#ifdef HAVE_CONFIG_H
|
38
|
+
#include "../crlibm_config.h"
|
39
|
+
#endif
|
40
|
+
#ifdef HAVE_INTTYPES_H
|
41
|
+
#include <inttypes.h>
|
42
|
+
#endif
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
/* 64 bit arithmetic may be standardised, but people still do want they want */
|
47
|
+
#ifdef HAVE_INTTYPES_H
|
48
|
+
#define ULL(bits) 0x##bits##uLL
|
49
|
+
#elif defined(WIN32)
|
50
|
+
/* TODO insert Windows garbage there */
|
51
|
+
/* Default, hoping it works, hopefully less and less relevant */
|
52
|
+
#else
|
53
|
+
typedef long long int64_t;
|
54
|
+
typedef unsigned long long uint64_t;
|
55
|
+
#define ULL(bits) 0x##bits##uLL
|
56
|
+
#endif
|
57
|
+
|
58
|
+
#ifndef SCS_DEF_INT64
|
59
|
+
#define SCS_DEF_INT64
|
60
|
+
#ifdef SCS_TYPEOS_HPUX
|
61
|
+
#ifndef __LP64__ /* To solve the problem with 64 bits integer */
|
62
|
+
typedef long long int64_t;
|
63
|
+
typedef unsigned long long uint64_t;
|
64
|
+
#define ULL(bits) 0x##bits##uLL
|
65
|
+
#endif
|
66
|
+
#endif
|
67
|
+
#endif
|
68
|
+
|
69
|
+
|
70
|
+
#ifdef HAVE_GMP_H
|
71
|
+
#include <gmp.h>
|
72
|
+
#endif
|
73
|
+
|
74
|
+
#ifdef HAVE_MPFR_H
|
75
|
+
#include <mpfr.h>
|
76
|
+
#endif
|
77
|
+
|
78
|
+
|
79
|
+
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
|
80
|
+
|
81
|
+
|
82
|
+
/** @internal An union to cast floats into doubles or the other way round. For
|
83
|
+
internal purpose only */
|
84
|
+
|
85
|
+
typedef union {
|
86
|
+
int32_t i[2]; /* Signed (may be useful) */
|
87
|
+
int64_t l; /* Signed (may be useful) */
|
88
|
+
double d;
|
89
|
+
} db_number;
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
/* ****************************************************************** */
|
96
|
+
/**@name SCS data-types */ /**@{*/
|
97
|
+
|
98
|
+
/** @struct scs
|
99
|
+
The SCS data type.
|
100
|
+
|
101
|
+
An SCS number is a a floating-point number in base 2^32.
|
102
|
+
|
103
|
+
- Its mantissa is formed of SCS_NB_WORDS digits (currently 32 bits by default)
|
104
|
+
|
105
|
+
- Its exponent is a 32-bit integer
|
106
|
+
|
107
|
+
- It also has a sign field, and an exception field used to store and
|
108
|
+
propagate IEEE-754 exceptions.
|
109
|
+
|
110
|
+
|
111
|
+
The real number represented by a scs structure is equal to:
|
112
|
+
@f$
|
113
|
+
\displaystyle
|
114
|
+
\sum_{i=0}^{\mathtt{SCS\_NB\_WORDS}}
|
115
|
+
2^{(\mathtt{index} -i)\mathtt{SCS\_NB\_BITS}}
|
116
|
+
\times
|
117
|
+
\mathtt{h\_word}[i]
|
118
|
+
@f$
|
119
|
+
*/
|
120
|
+
|
121
|
+
/*
|
122
|
+
(verbatim-mode formula for the above eqation:) the number represented by a
|
123
|
+
SCS structure is :
|
124
|
+
|
125
|
+
i<SCS_NB_WORDS (index - i).SCS_NB_BITS
|
126
|
+
sign . ( sum ( h_word[i] . 2^ )
|
127
|
+
i=0
|
128
|
+
*/
|
129
|
+
|
130
|
+
struct scs {
|
131
|
+
/** the digits, as 32 bits words */
|
132
|
+
uint32_t h_word[SCS_NB_WORDS];
|
133
|
+
/** Used to store Nan,+/-0, Inf, etc and then let the hardware handle them */
|
134
|
+
db_number exception;
|
135
|
+
/** This corresponds to the exponent in an FP format, but here we are
|
136
|
+
in base 2^32 */
|
137
|
+
int index;
|
138
|
+
/** The sign equals 1 or -1*/
|
139
|
+
int sign;
|
140
|
+
};
|
141
|
+
|
142
|
+
|
143
|
+
typedef struct scs scs;
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
/** scs_ptr is a pointer on a SCS structure */
|
148
|
+
typedef struct scs * scs_ptr;
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
/** scs_t is an array of one SCS struct to lighten syntax : you may
|
154
|
+
declare a scs_t object, and pass it to the scs functions (which
|
155
|
+
expect pointers) without using ampersands.
|
156
|
+
*/
|
157
|
+
typedef struct scs scs_t[1];
|
158
|
+
|
159
|
+
/**@}*/ /* end doxygen group for SCS data-types */
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
/* ****************************************************************** */
|
169
|
+
/**@name Conversion and initialization functions */ /**@{*/
|
170
|
+
|
171
|
+
/** Convert a SCS number to a double, rounding to the nearest */
|
172
|
+
void scs_get_d(double*, scs_ptr);
|
173
|
+
|
174
|
+
/** Convert a SCS number to a double, rounding towards minus infinity */
|
175
|
+
void scs_get_d_minf(double*, scs_ptr);
|
176
|
+
|
177
|
+
/** Convert a SCS number to a double, rounding towards plus infinity */
|
178
|
+
void scs_get_d_pinf(double*, scs_ptr);
|
179
|
+
|
180
|
+
/** Convert a SCS number to a double, rounding towards zero */
|
181
|
+
void scs_get_d_zero(double*, scs_ptr);
|
182
|
+
|
183
|
+
/** Convert a double into a SCS number (this is an exact operation) */
|
184
|
+
void scs_set_d(scs_ptr, double);
|
185
|
+
|
186
|
+
/** Convert a signed int into a SCS number (this is an exact operation) */
|
187
|
+
void scs_set_si(scs_ptr, signed int);
|
188
|
+
|
189
|
+
|
190
|
+
/** Print out a SCS number. Sorry for the strange name, we are mimicking GMP */
|
191
|
+
void scs_get_std(scs_ptr);
|
192
|
+
|
193
|
+
|
194
|
+
/** Copy a SCS number into another */
|
195
|
+
void scs_set(scs_ptr, scs_ptr);
|
196
|
+
|
197
|
+
|
198
|
+
/** Set a SCS number to zero */
|
199
|
+
void scs_zero(scs_ptr);
|
200
|
+
|
201
|
+
|
202
|
+
/** Generate a random SCS number.
|
203
|
+
The index field of result will be between -expo_max and +expo_max.
|
204
|
+
Example: to get a number in the double-precision floating-point range,
|
205
|
+
expo_max should be smaller than 39.
|
206
|
+
@warning No guarantee is made about the quality of the random algorithm
|
207
|
+
used... */
|
208
|
+
void scs_rand(scs_ptr result, int expo_max);
|
209
|
+
|
210
|
+
/**@}*/ /* end doxygen group for conversion / initialisation functions*/
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
/* ****************************************************************** */
|
216
|
+
/**@name Addition and renormalisation functions */ /**@{*/
|
217
|
+
|
218
|
+
|
219
|
+
/** Addition of two SCS numbers.
|
220
|
+
The arguments x, y and result may point to the same memory
|
221
|
+
location. The result is a normalised SCS number.
|
222
|
+
*/
|
223
|
+
void scs_add(scs_ptr result, scs_ptr x, scs_ptr y);
|
224
|
+
|
225
|
+
|
226
|
+
/** Subtraction of two SCS numbers.
|
227
|
+
The arguments x, y and result may point to the same memory
|
228
|
+
location. The result is a normalised SCS number.
|
229
|
+
*/
|
230
|
+
void scs_sub(scs_ptr result, scs_ptr x, scs_ptr y);
|
231
|
+
|
232
|
+
|
233
|
+
/** Addition without renormalisation, to be used for adding many
|
234
|
+
numbers.
|
235
|
+
@warning In case of a cancellation, severe loss of precision could
|
236
|
+
happen. Safe if the numbers are of the same sign.
|
237
|
+
*/
|
238
|
+
void scs_add_no_renorm(scs_ptr result, scs_ptr x, scs_ptr y);
|
239
|
+
|
240
|
+
|
241
|
+
/** Renormalisation (to be used after several scs_add_no_renorm).
|
242
|
+
This function removes the carry from each digit, and also shifts the
|
243
|
+
digits in case of a cancellation (so that if result != 0 then its
|
244
|
+
first digit is non-zero)
|
245
|
+
|
246
|
+
@warning THIS FUNCTION HAS NEVER BEEN PROPERLY TESTED and is
|
247
|
+
currently unused in the library: instead, specific renormalisation
|
248
|
+
steps are fused within the code of the operations which require it.
|
249
|
+
*/
|
250
|
+
|
251
|
+
void scs_renorm(scs_ptr);
|
252
|
+
|
253
|
+
|
254
|
+
/** Renormalisation assuming no cancellation. This function is useful
|
255
|
+
for example when adding many numbers of the same sign */
|
256
|
+
void scs_renorm_no_cancel_check(scs_ptr);
|
257
|
+
|
258
|
+
/**@}*/ /* end doxygen group for addition and normalisation functions*/
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
/* ****************************************************************** */
|
264
|
+
/**@name Multiplication functions */ /**@{*/
|
265
|
+
|
266
|
+
/** Multiplication of two SCS numbers. The arguments x, y and result
|
267
|
+
may point to the same memory location. The result is a normalised SCS
|
268
|
+
number.
|
269
|
+
*/
|
270
|
+
void scs_mul(scs_ptr result, const scs_ptr x, const scs_ptr y);
|
271
|
+
|
272
|
+
/** Multiplication of a SCS with an unsigned integer; result is
|
273
|
+
returned in x. */
|
274
|
+
void scs_mul_ui(scs_ptr, const unsigned int);
|
275
|
+
|
276
|
+
/** Square. Result is normalised */
|
277
|
+
void scs_square(scs_ptr result, scs_ptr x);
|
278
|
+
|
279
|
+
/** Fused multiply-and-add (ab+c); Result is normalised
|
280
|
+
\warning This function has not been tested thoroughly */
|
281
|
+
void scs_fma(scs_ptr result, scs_ptr a, scs_ptr b, scs_ptr c);
|
282
|
+
|
283
|
+
/**@}*/ /* end doxygen group for Multiplication functions*/
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
/* ****************************************************************** */
|
290
|
+
/**@name Divisions */ /**@{*/
|
291
|
+
|
292
|
+
/** SCS inverse.
|
293
|
+
Stores 1/x in result. Result is normalised
|
294
|
+
|
295
|
+
@warning This function is known not to work for most precisions: it
|
296
|
+
performs a fixed number of Newton-Raphson iterations (two), starting
|
297
|
+
with a FP number (53 bits), so provides roughly 210 bits of
|
298
|
+
precision. It should be modified to perform more iterations if more
|
299
|
+
precision is needed.
|
300
|
+
*/
|
301
|
+
void scs_inv(scs_ptr result, scs_ptr x);
|
302
|
+
|
303
|
+
/** SCS division. Computes x/y. Result is normalised
|
304
|
+
@warning This function is known not to work for most precisions: it
|
305
|
+
performs a fixed number of Newton-Raphson iterations (two), starting
|
306
|
+
with a FP number (53 bits), so provides roughly 210 bits of
|
307
|
+
precision. It should be modified to perform more iterations if more
|
308
|
+
precision is needed.
|
309
|
+
*/
|
310
|
+
void scs_div(scs_ptr result, scs_ptr x, scs_ptr y);
|
311
|
+
|
312
|
+
|
313
|
+
/** SCS division by 2. Computes x/2. Result is normalised */
|
314
|
+
void scs_div_2(scs_t x);
|
315
|
+
|
316
|
+
/**@}*/ /* end doxygen group for division functions*/
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
/* ****************************************************************** */
|
323
|
+
/**@name Functions for testing purpose */ /**@{*/
|
324
|
+
|
325
|
+
|
326
|
+
#ifdef HAVE_LIBGMP
|
327
|
+
/** Convert a SCS number into a GMP MPF (multiple precision,
|
328
|
+
floating-point) number. Should be exact if the target number has
|
329
|
+
more precision than the SCS number, otherwise the rounding is
|
330
|
+
unspecified (the conversion uses MPF functions) */
|
331
|
+
void scs_get_mpf(scs_ptr, mpf_t);
|
332
|
+
#endif
|
333
|
+
|
334
|
+
|
335
|
+
|
336
|
+
#ifdef HAVE_MPFR_H
|
337
|
+
/** Convert a SCS number into a MPFR (multiple precision,
|
338
|
+
floating-point) number. Should be exact if the target number has
|
339
|
+
more precision than the SCS number, otherwise should be correctly
|
340
|
+
rounded (the conversion uses MPFR functions). Not heavily tested
|
341
|
+
though */
|
342
|
+
void scs_get_mpfr(scs_ptr, mpfr_t);
|
343
|
+
#endif
|
344
|
+
|
345
|
+
|
346
|
+
/**@}*/ /* end doxygen group for functions for testing purpose */
|
347
|
+
|
348
|
+
#endif /* INCLUDE_SCS */
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
|