ray 0.0.1 → 0.1.0.pre1
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.
- data/.gemtest +0 -0
- data/.yardopts +4 -0
- data/README.md +17 -21
- data/Rakefile +18 -139
- data/VERSION +1 -1
- data/ext/audio.cpp +723 -0
- data/ext/{color.c → color.cpp} +25 -13
- data/ext/drawable.cpp +91 -0
- data/ext/event.cpp +460 -0
- data/ext/extconf.rb +5 -104
- data/ext/font.cpp +190 -0
- data/ext/image.cpp +733 -0
- data/ext/input.cpp +74 -0
- data/ext/ray.cpp +168 -0
- data/ext/ray.hpp +356 -0
- data/ext/{rect.c → rect.cpp} +51 -37
- data/ext/shader.cpp +169 -0
- data/ext/shape.cpp +409 -0
- data/ext/sprite.cpp +306 -0
- data/ext/text.cpp +181 -0
- data/ext/vector.cpp +215 -0
- data/guide.md +619 -0
- data/lib/ray/audio.rb +0 -41
- data/lib/ray/color.rb +32 -10
- data/lib/ray/drawable.rb +16 -0
- data/lib/ray/dsl/event_listener.rb +25 -2
- data/lib/ray/dsl/event_runner.rb +33 -5
- data/lib/ray/dsl/event_translator.rb +66 -30
- data/lib/ray/dsl/handler.rb +3 -2
- data/lib/ray/dsl/matcher.rb +58 -14
- data/lib/ray/font.rb +38 -96
- data/lib/ray/font_set.rb +8 -8
- data/lib/ray/game.rb +87 -66
- data/lib/ray/helper.rb +105 -10
- data/lib/ray/image.rb +150 -24
- data/lib/ray/image_set.rb +3 -1
- data/lib/ray/input.rb +10 -0
- data/lib/ray/music_set.rb +5 -3
- data/lib/ray/ray.rb +21 -9
- data/lib/ray/rect.rb +48 -7
- data/lib/ray/rmagick.rb +41 -0
- data/lib/ray/scene.rb +99 -43
- data/lib/ray/scene_list.rb +67 -0
- data/lib/ray/shape.rb +132 -0
- data/lib/ray/sound_set.rb +4 -2
- data/lib/ray/sprite.rb +49 -111
- data/lib/ray/text.rb +101 -0
- data/lib/ray/text_helper.rb +37 -0
- data/lib/ray/turtle.rb +215 -0
- data/lib/ray/vector.rb +226 -0
- data/samples/audio/spacial.rb +44 -0
- data/samples/hello_world/hello.rb +9 -13
- data/samples/hello_world/hello_dsl.rb +8 -12
- data/samples/hello_world/text.rb +15 -0
- data/samples/opengl/binding.rb +38 -0
- data/samples/opengl/image.rb +32 -0
- data/samples/opengl/opengl.rb +34 -0
- data/samples/opengl/shader.rb +42 -0
- data/samples/pong/pong.rb +14 -10
- data/samples/run_scene.rb +53 -0
- data/samples/shaders/scene.rb +40 -0
- data/samples/shaders/shaders.rb +42 -0
- data/samples/shaders/shape.rb +34 -0
- data/samples/sokoban/sokoban.rb +18 -18
- data/samples/test/actual_scene.rb +41 -0
- data/samples/test/scene_riot.rb +39 -0
- data/samples/test/scene_spec.rb +32 -0
- data/samples/test/scene_test_unit.rb +25 -0
- data/samples/turtle/byzantium.rb +45 -0
- data/samples/turtle/hilbert.rb +48 -0
- data/samples/turtle/koch.rb +55 -0
- data/samples/turtle/mandala.rb +61 -0
- data/samples/turtle/tree.rb +57 -0
- data/test/audio_test.rb +69 -0
- data/test/color_test.rb +77 -0
- data/test/drawable_test.rb +19 -0
- data/test/dsl_test.rb +93 -0
- data/test/font_test.rb +57 -0
- data/test/helpers.rb +94 -0
- data/test/image_test.rb +82 -0
- data/test/ray_test.rb +25 -0
- data/test/rect_test.rb +121 -0
- data/{spec → test}/res/VeraMono.ttf +0 -0
- data/{spec → test}/res/aqua.bmp +0 -0
- data/{spec → test}/res/aqua.png +0 -0
- data/{spec → test}/res/aqua2.bmp +0 -0
- data/{spec → test}/res/not_a_jpeg.jpeg +0 -0
- data/{spec → test}/res/pop.wav +0 -0
- data/test/resource_set_test.rb +99 -0
- data/test/run_all.rb +7 -0
- data/test/shape_test.rb +101 -0
- data/test/sprite_test.rb +89 -0
- data/test/text_test.rb +78 -0
- data/test/turtle_test.rb +176 -0
- data/test/vector_test.rb +111 -0
- data/yard_ext.rb +0 -28
- metadata +95 -139
- data/.gitignore +0 -23
- data/.gitmodules +0 -3
- data/.rspec +0 -3
- data/ext/audio.c +0 -473
- data/ext/event.c +0 -557
- data/ext/font.c +0 -287
- data/ext/image.c +0 -933
- data/ext/joystick.c +0 -145
- data/ext/ray.c +0 -489
- data/ext/ray.h +0 -245
- data/ext/ray_osx.m +0 -161
- data/lib/ray/joystick.rb +0 -30
- data/psp/SDL_psp_main.c +0 -84
- data/psp/bigdecimal/README +0 -60
- data/psp/bigdecimal/bigdecimal.c +0 -4697
- data/psp/bigdecimal/bigdecimal.h +0 -216
- data/psp/bigdecimal/lib/bigdecimal/jacobian.rb +0 -85
- data/psp/bigdecimal/lib/bigdecimal/ludcmp.rb +0 -84
- data/psp/bigdecimal/lib/bigdecimal/math.rb +0 -235
- data/psp/bigdecimal/lib/bigdecimal/newton.rb +0 -77
- data/psp/bigdecimal/lib/bigdecimal/util.rb +0 -65
- data/psp/digest/bubblebabble/bubblebabble.c +0 -142
- data/psp/digest/defs.h +0 -20
- data/psp/digest/digest.c +0 -643
- data/psp/digest/digest.h +0 -32
- data/psp/digest/lib/digest.rb +0 -50
- data/psp/digest/lib/md5.rb +0 -27
- data/psp/digest/lib/sha1.rb +0 -27
- data/psp/digest/md5/md5.c +0 -420
- data/psp/digest/md5/md5.h +0 -80
- data/psp/digest/md5/md5init.c +0 -40
- data/psp/digest/rmd160/rmd160.c +0 -457
- data/psp/digest/rmd160/rmd160.h +0 -56
- data/psp/digest/rmd160/rmd160init.c +0 -40
- data/psp/digest/sha1/sha1.c +0 -269
- data/psp/digest/sha1/sha1.h +0 -39
- data/psp/digest/sha1/sha1init.c +0 -40
- data/psp/digest/sha2/lib/sha2.rb +0 -73
- data/psp/digest/sha2/sha2.c +0 -919
- data/psp/digest/sha2/sha2.h +0 -109
- data/psp/digest/sha2/sha2init.c +0 -52
- data/psp/enumerator/enumerator.c +0 -298
- data/psp/etc/etc.c +0 -559
- data/psp/ext.c +0 -289
- data/psp/fcntl/fcntl.c +0 -187
- data/psp/lib/rbconfig.rb +0 -178
- data/psp/nkf/lib/kconv.rb +0 -367
- data/psp/nkf/nkf-utf8/config.h +0 -88
- data/psp/nkf/nkf-utf8/nkf.c +0 -6040
- data/psp/nkf/nkf-utf8/utf8tbl.c +0 -8500
- data/psp/nkf/nkf-utf8/utf8tbl.h +0 -34
- data/psp/nkf/nkf.c +0 -654
- data/psp/socket/addrinfo.h +0 -173
- data/psp/socket/getaddrinfo.c +0 -676
- data/psp/socket/getnameinfo.c +0 -270
- data/psp/socket/pspsocket.c +0 -71
- data/psp/socket/pspsocket.h +0 -28
- data/psp/socket/socket.c +0 -4662
- data/psp/socket/sockport.h +0 -76
- data/psp/stringio/stringio.c +0 -1306
- data/psp/strscan/strscan.c +0 -1320
- data/psp/syck/bytecode.c +0 -1166
- data/psp/syck/emitter.c +0 -1242
- data/psp/syck/gram.c +0 -1894
- data/psp/syck/gram.h +0 -79
- data/psp/syck/handler.c +0 -174
- data/psp/syck/implicit.c +0 -2990
- data/psp/syck/node.c +0 -408
- data/psp/syck/rubyext.c +0 -2367
- data/psp/syck/syck.c +0 -504
- data/psp/syck/syck.h +0 -456
- data/psp/syck/token.c +0 -2725
- data/psp/syck/yaml2byte.c +0 -257
- data/psp/syck/yamlbyte.h +0 -170
- data/psp/thread/thread.c +0 -1175
- data/psp/zlib/zlib.c +0 -3547
- data/script.rb +0 -10
- data/spec/ray/audio_spec.rb +0 -146
- data/spec/ray/color_spec.rb +0 -57
- data/spec/ray/event_spec.rb +0 -80
- data/spec/ray/font_spec.rb +0 -93
- data/spec/ray/image_set_spec.rb +0 -48
- data/spec/ray/image_spec.rb +0 -162
- data/spec/ray/joystick_spec.rb +0 -21
- data/spec/ray/matcher_spec.rb +0 -50
- data/spec/ray/ray_spec.rb +0 -88
- data/spec/ray/rect_spec.rb +0 -154
- data/spec/ray/resource_set_spec.rb +0 -105
- data/spec/ray/sprite_spec.rb +0 -163
- data/spec/spec.opts +0 -4
- data/spec/spec_helper.rb +0 -8
data/psp/bigdecimal/bigdecimal.h
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
*
|
|
3
|
-
* Ruby BigDecimal(Variable decimal precision) extension library.
|
|
4
|
-
*
|
|
5
|
-
* Copyright(C) 2002 by Shigeo Kobayashi(shigeo@tinyforest.gr.jp)
|
|
6
|
-
*
|
|
7
|
-
* You may distribute under the terms of either the GNU General Public
|
|
8
|
-
* License or the Artistic License, as specified in the README file
|
|
9
|
-
* of this BigDecimal distribution.
|
|
10
|
-
*
|
|
11
|
-
* NOTES:
|
|
12
|
-
* 2003-03-28 V1.0 checked in.
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
#ifndef ____BIG_DECIMAL__H____
|
|
17
|
-
#define ____BIG_DECIMAL__H____
|
|
18
|
-
|
|
19
|
-
#if defined(__cplusplus)
|
|
20
|
-
extern "C" {
|
|
21
|
-
#endif
|
|
22
|
-
|
|
23
|
-
/*
|
|
24
|
-
* NaN & Infinity
|
|
25
|
-
*/
|
|
26
|
-
#define SZ_NaN "NaN"
|
|
27
|
-
#define SZ_INF "Infinity"
|
|
28
|
-
#define SZ_PINF "+Infinity"
|
|
29
|
-
#define SZ_NINF "-Infinity"
|
|
30
|
-
|
|
31
|
-
/*
|
|
32
|
-
* #define VP_EXPORT other than static to let VP_ routines
|
|
33
|
-
* be called from outside of this module.
|
|
34
|
-
*/
|
|
35
|
-
#define VP_EXPORT static
|
|
36
|
-
|
|
37
|
-
#define U_LONG unsigned long
|
|
38
|
-
#define S_LONG long
|
|
39
|
-
#define U_INT unsigned int
|
|
40
|
-
#define S_INT int
|
|
41
|
-
|
|
42
|
-
/* Exception codes */
|
|
43
|
-
#define VP_EXCEPTION_ALL ((unsigned short)0x00FF)
|
|
44
|
-
#define VP_EXCEPTION_INFINITY ((unsigned short)0x0001)
|
|
45
|
-
#define VP_EXCEPTION_NaN ((unsigned short)0x0002)
|
|
46
|
-
#define VP_EXCEPTION_UNDERFLOW ((unsigned short)0x0004)
|
|
47
|
-
#define VP_EXCEPTION_OVERFLOW ((unsigned short)0x0001) /* 0x0008) */
|
|
48
|
-
#define VP_EXCEPTION_ZERODIVIDE ((unsigned short)0x0001) /* 0x0010) */
|
|
49
|
-
|
|
50
|
-
/* Following 2 exceptions cann't controlled by user */
|
|
51
|
-
#define VP_EXCEPTION_OP ((unsigned short)0x0020)
|
|
52
|
-
#define VP_EXCEPTION_MEMORY ((unsigned short)0x0040)
|
|
53
|
-
|
|
54
|
-
/* Computation mode */
|
|
55
|
-
#define VP_ROUND_MODE ((unsigned short)0x0100)
|
|
56
|
-
#define VP_ROUND_UP 1
|
|
57
|
-
#define VP_ROUND_DOWN 2
|
|
58
|
-
#define VP_ROUND_HALF_UP 3
|
|
59
|
-
#define VP_ROUND_HALF_DOWN 4
|
|
60
|
-
#define VP_ROUND_CEIL 5
|
|
61
|
-
#define VP_ROUND_FLOOR 6
|
|
62
|
-
#define VP_ROUND_HALF_EVEN 7
|
|
63
|
-
|
|
64
|
-
#define VP_SIGN_NaN 0 /* NaN */
|
|
65
|
-
#define VP_SIGN_POSITIVE_ZERO 1 /* Positive zero */
|
|
66
|
-
#define VP_SIGN_NEGATIVE_ZERO -1 /* Negative zero */
|
|
67
|
-
#define VP_SIGN_POSITIVE_FINITE 2 /* Positive finite number */
|
|
68
|
-
#define VP_SIGN_NEGATIVE_FINITE -2 /* Negative finite number */
|
|
69
|
-
#define VP_SIGN_POSITIVE_INFINITE 3 /* Positive infinite number */
|
|
70
|
-
#define VP_SIGN_NEGATIVE_INFINITE -3 /* Negative infinite number */
|
|
71
|
-
|
|
72
|
-
/*
|
|
73
|
-
* VP representation
|
|
74
|
-
* r = 0.xxxxxxxxx *BASE**exponent
|
|
75
|
-
*/
|
|
76
|
-
typedef struct {
|
|
77
|
-
VALUE obj; /* Back pointer(VALUE) for Ruby object. */
|
|
78
|
-
U_LONG MaxPrec; /* Maximum precision size */
|
|
79
|
-
/* This is the actual size of pfrac[] */
|
|
80
|
-
/*(frac[0] to frac[MaxPrec] are available). */
|
|
81
|
-
U_LONG Prec; /* Current precision size. */
|
|
82
|
-
/* This indicates how much the. */
|
|
83
|
-
/* the array frac[] is actually used. */
|
|
84
|
-
S_INT exponent;/* Exponent part. */
|
|
85
|
-
short sign; /* Attributes of the value. */
|
|
86
|
-
/*
|
|
87
|
-
* ==0 : NaN
|
|
88
|
-
* 1 : Positive zero
|
|
89
|
-
* -1 : Negative zero
|
|
90
|
-
* 2 : Positive number
|
|
91
|
-
* -2 : Negative number
|
|
92
|
-
* 3 : Positive infinite number
|
|
93
|
-
* -3 : Negative infinite number
|
|
94
|
-
*/
|
|
95
|
-
short flag; /* Not used in vp_routines,space for user. */
|
|
96
|
-
U_LONG frac[1]; /* Pointer to array of fraction part. */
|
|
97
|
-
} Real;
|
|
98
|
-
|
|
99
|
-
/*
|
|
100
|
-
* ------------------
|
|
101
|
-
* EXPORTables.
|
|
102
|
-
* ------------------
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
|
-
VP_EXPORT Real *
|
|
106
|
-
VpNewRbClass(U_LONG mx,char *str,VALUE klass);
|
|
107
|
-
|
|
108
|
-
VP_EXPORT Real *VpCreateRbObject(U_LONG mx,const char *str);
|
|
109
|
-
|
|
110
|
-
VP_EXPORT U_LONG VpBaseFig(void);
|
|
111
|
-
VP_EXPORT U_LONG VpDblFig(void);
|
|
112
|
-
VP_EXPORT U_LONG VpBaseVal(void);
|
|
113
|
-
|
|
114
|
-
/* Zero,Inf,NaN (isinf(),isnan() used to check) */
|
|
115
|
-
VP_EXPORT double VpGetDoubleNaN(void);
|
|
116
|
-
VP_EXPORT double VpGetDoublePosInf(void);
|
|
117
|
-
VP_EXPORT double VpGetDoubleNegInf(void);
|
|
118
|
-
VP_EXPORT double VpGetDoubleNegZero(void);
|
|
119
|
-
|
|
120
|
-
/* These 2 functions added at v1.1.7 */
|
|
121
|
-
VP_EXPORT U_LONG VpGetPrecLimit(void);
|
|
122
|
-
VP_EXPORT U_LONG VpSetPrecLimit(U_LONG n);
|
|
123
|
-
|
|
124
|
-
/* Round mode */
|
|
125
|
-
VP_EXPORT int VpIsRoundMode(unsigned long n);
|
|
126
|
-
VP_EXPORT unsigned long VpGetRoundMode(void);
|
|
127
|
-
VP_EXPORT unsigned long VpSetRoundMode(unsigned long n);
|
|
128
|
-
|
|
129
|
-
VP_EXPORT int VpException(unsigned short f,const char *str,int always);
|
|
130
|
-
VP_EXPORT int VpIsNegDoubleZero(double v);
|
|
131
|
-
VP_EXPORT U_LONG VpNumOfChars(Real *vp,const char *pszFmt);
|
|
132
|
-
VP_EXPORT U_LONG VpInit(U_LONG BaseVal);
|
|
133
|
-
VP_EXPORT void *VpMemAlloc(U_LONG mb);
|
|
134
|
-
VP_EXPORT void VpFree(Real *pv);
|
|
135
|
-
VP_EXPORT Real *VpAlloc(U_LONG mx, const char *szVal);
|
|
136
|
-
VP_EXPORT int VpAsgn(Real *c,Real *a,int isw);
|
|
137
|
-
VP_EXPORT int VpAddSub(Real *c,Real *a,Real *b,int operation);
|
|
138
|
-
VP_EXPORT int VpMult(Real *c,Real *a,Real *b);
|
|
139
|
-
VP_EXPORT int VpDivd(Real *c,Real *r,Real *a,Real *b);
|
|
140
|
-
VP_EXPORT int VpComp(Real *a,Real *b);
|
|
141
|
-
VP_EXPORT S_LONG VpExponent10(Real *a);
|
|
142
|
-
VP_EXPORT void VpSzMantissa(Real *a,char *psz);
|
|
143
|
-
VP_EXPORT int VpToSpecialString(Real *a,char *psz,int fPlus);
|
|
144
|
-
VP_EXPORT void VpToString(Real *a,char *psz,int fFmt,int fPlus);
|
|
145
|
-
VP_EXPORT void VpToFString(Real *a,char *psz,int fFmt,int fPlus);
|
|
146
|
-
VP_EXPORT int VpCtoV(Real *a,const char *int_chr,U_LONG ni,const char *frac,U_LONG nf,const char *exp_chr,U_LONG ne);
|
|
147
|
-
VP_EXPORT int VpVtoD(double *d,S_LONG *e,Real *m);
|
|
148
|
-
VP_EXPORT void VpDtoV(Real *m,double d);
|
|
149
|
-
VP_EXPORT void VpItoV(Real *m,S_INT ival);
|
|
150
|
-
VP_EXPORT int VpSqrt(Real *y,Real *x);
|
|
151
|
-
VP_EXPORT int VpActiveRound(Real *y,Real *x,int f,int il);
|
|
152
|
-
VP_EXPORT int VpMidRound(Real *y, int f, int nf);
|
|
153
|
-
VP_EXPORT int VpLeftRound(Real *y, int f, int nf);
|
|
154
|
-
VP_EXPORT void VpFrac(Real *y,Real *x);
|
|
155
|
-
VP_EXPORT int VpPower(Real *y,Real *x,S_INT n);
|
|
156
|
-
|
|
157
|
-
/* VP constants */
|
|
158
|
-
VP_EXPORT Real *VpOne(void);
|
|
159
|
-
|
|
160
|
-
/*
|
|
161
|
-
* ------------------
|
|
162
|
-
* MACRO definitions.
|
|
163
|
-
* ------------------
|
|
164
|
-
*/
|
|
165
|
-
#define Abs(a) (((a)>= 0)?(a):(-(a)))
|
|
166
|
-
#define Max(a, b) (((a)>(b))?(a):(b))
|
|
167
|
-
#define Min(a, b) (((a)>(b))?(b):(a))
|
|
168
|
-
|
|
169
|
-
#define VpMaxPrec(a) ((a)->MaxPrec)
|
|
170
|
-
#define VpPrec(a) ((a)->Prec)
|
|
171
|
-
#define VpGetFlag(a) ((a)->flag)
|
|
172
|
-
|
|
173
|
-
/* Sign */
|
|
174
|
-
|
|
175
|
-
/* VpGetSign(a) returns 1,-1 if a>0,a<0 respectively */
|
|
176
|
-
#define VpGetSign(a) (((a)->sign>0)?1:(-1))
|
|
177
|
-
/* Change sign of a to a>0,a<0 if s = 1,-1 respectively */
|
|
178
|
-
#define VpChangeSign(a,s) {if((s)>0) (a)->sign=(short)Abs((S_LONG)(a)->sign);else (a)->sign=-(short)Abs((S_LONG)(a)->sign);}
|
|
179
|
-
/* Sets sign of a to a>0,a<0 if s = 1,-1 respectively */
|
|
180
|
-
#define VpSetSign(a,s) {if((s)>0) (a)->sign=(short)VP_SIGN_POSITIVE_FINITE;else (a)->sign=(short)VP_SIGN_NEGATIVE_FINITE;}
|
|
181
|
-
|
|
182
|
-
/* 1 */
|
|
183
|
-
#define VpSetOne(a) {(a)->frac[0]=(a)->exponent=(a)->Prec=1;(a)->sign=VP_SIGN_POSITIVE_FINITE;}
|
|
184
|
-
|
|
185
|
-
/* ZEROs */
|
|
186
|
-
#define VpIsPosZero(a) ((a)->sign==VP_SIGN_POSITIVE_ZERO)
|
|
187
|
-
#define VpIsNegZero(a) ((a)->sign==VP_SIGN_NEGATIVE_ZERO)
|
|
188
|
-
#define VpIsZero(a) (VpIsPosZero(a) || VpIsNegZero(a))
|
|
189
|
-
#define VpSetPosZero(a) ((a)->frac[0]=0,(a)->Prec=1,(a)->sign=VP_SIGN_POSITIVE_ZERO)
|
|
190
|
-
#define VpSetNegZero(a) ((a)->frac[0]=0,(a)->Prec=1,(a)->sign=VP_SIGN_NEGATIVE_ZERO)
|
|
191
|
-
#define VpSetZero(a,s) ( ((s)>0)?VpSetPosZero(a):VpSetNegZero(a) )
|
|
192
|
-
|
|
193
|
-
/* NaN */
|
|
194
|
-
#define VpIsNaN(a) ((a)->sign==VP_SIGN_NaN)
|
|
195
|
-
#define VpSetNaN(a) ((a)->frac[0]=0,(a)->Prec=1,(a)->sign=VP_SIGN_NaN)
|
|
196
|
-
|
|
197
|
-
/* Infinity */
|
|
198
|
-
#define VpIsPosInf(a) ((a)->sign==VP_SIGN_POSITIVE_INFINITE)
|
|
199
|
-
#define VpIsNegInf(a) ((a)->sign==VP_SIGN_NEGATIVE_INFINITE)
|
|
200
|
-
#define VpIsInf(a) (VpIsPosInf(a) || VpIsNegInf(a))
|
|
201
|
-
#define VpIsDef(a) ( !(VpIsNaN(a)||VpIsInf(a)) )
|
|
202
|
-
#define VpSetPosInf(a) ((a)->frac[0]=0,(a)->Prec=1,(a)->sign=VP_SIGN_POSITIVE_INFINITE)
|
|
203
|
-
#define VpSetNegInf(a) ((a)->frac[0]=0,(a)->Prec=1,(a)->sign=VP_SIGN_NEGATIVE_INFINITE)
|
|
204
|
-
#define VpSetInf(a,s) ( ((s)>0)?VpSetPosInf(a):VpSetNegInf(a) )
|
|
205
|
-
#define VpHasVal(a) (a->frac[0])
|
|
206
|
-
#define VpIsOne(a) ((a->Prec==1)&&(a->frac[0]==1)&&(a->exponent==1))
|
|
207
|
-
#define VpExponent(a) (a->exponent)
|
|
208
|
-
#ifdef _DEBUG
|
|
209
|
-
int VpVarCheck(Real * v);
|
|
210
|
-
VP_EXPORT int VPrint(FILE *fp,char *cntl_chr,Real *a);
|
|
211
|
-
#endif /* _DEBUG */
|
|
212
|
-
|
|
213
|
-
#if defined(__cplusplus)
|
|
214
|
-
} /* extern "C" { */
|
|
215
|
-
#endif
|
|
216
|
-
#endif /* ____BIG_DECIMAL__H____ */
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# require 'bigdecimal/jacobian'
|
|
3
|
-
#
|
|
4
|
-
# Provides methods to compute the Jacobian matrix of a set of equations at a
|
|
5
|
-
# point x. In the methods below:
|
|
6
|
-
#
|
|
7
|
-
# f is an Object which is used to compute the Jacobian matrix of the equations.
|
|
8
|
-
# It must provide the following methods:
|
|
9
|
-
#
|
|
10
|
-
# f.values(x):: returns the values of all functions at x
|
|
11
|
-
#
|
|
12
|
-
# f.zero:: returns 0.0
|
|
13
|
-
# f.one:: returns 1.0
|
|
14
|
-
# f.two:: returns 1.0
|
|
15
|
-
# f.ten:: returns 10.0
|
|
16
|
-
#
|
|
17
|
-
# f.eps:: returns the convergence criterion (epsilon value) used to determine whether two values are considered equal. If |a-b| < epsilon, the two values are considered equal.
|
|
18
|
-
#
|
|
19
|
-
# x is the point at which to compute the Jacobian.
|
|
20
|
-
#
|
|
21
|
-
# fx is f.values(x).
|
|
22
|
-
#
|
|
23
|
-
module Jacobian
|
|
24
|
-
#--
|
|
25
|
-
def isEqual(a,b,zero=0.0,e=1.0e-8)
|
|
26
|
-
aa = a.abs
|
|
27
|
-
bb = b.abs
|
|
28
|
-
if aa == zero && bb == zero then
|
|
29
|
-
true
|
|
30
|
-
else
|
|
31
|
-
if ((a-b)/(aa+bb)).abs < e then
|
|
32
|
-
true
|
|
33
|
-
else
|
|
34
|
-
false
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
#++
|
|
39
|
-
|
|
40
|
-
# Computes the derivative of f[i] at x[i].
|
|
41
|
-
# fx is the value of f at x.
|
|
42
|
-
def dfdxi(f,fx,x,i)
|
|
43
|
-
nRetry = 0
|
|
44
|
-
n = x.size
|
|
45
|
-
xSave = x[i]
|
|
46
|
-
ok = 0
|
|
47
|
-
ratio = f.ten*f.ten*f.ten
|
|
48
|
-
dx = x[i].abs/ratio
|
|
49
|
-
dx = fx[i].abs/ratio if isEqual(dx,f.zero,f.zero,f.eps)
|
|
50
|
-
dx = f.one/f.ten if isEqual(dx,f.zero,f.zero,f.eps)
|
|
51
|
-
until ok>0 do
|
|
52
|
-
s = f.zero
|
|
53
|
-
deriv = []
|
|
54
|
-
if(nRetry>100) then
|
|
55
|
-
raize "Singular Jacobian matrix. No change at x[" + i.to_s + "]"
|
|
56
|
-
end
|
|
57
|
-
dx = dx*f.two
|
|
58
|
-
x[i] += dx
|
|
59
|
-
fxNew = f.values(x)
|
|
60
|
-
for j in 0...n do
|
|
61
|
-
if !isEqual(fxNew[j],fx[j],f.zero,f.eps) then
|
|
62
|
-
ok += 1
|
|
63
|
-
deriv <<= (fxNew[j]-fx[j])/dx
|
|
64
|
-
else
|
|
65
|
-
deriv <<= f.zero
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
x[i] = xSave
|
|
69
|
-
end
|
|
70
|
-
deriv
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# Computes the Jacobian of f at x. fx is the value of f at x.
|
|
74
|
-
def jacobian(f,fx,x)
|
|
75
|
-
n = x.size
|
|
76
|
-
dfdx = Array::new(n*n)
|
|
77
|
-
for i in 0...n do
|
|
78
|
-
df = dfdxi(f,fx,x,i)
|
|
79
|
-
for j in 0...n do
|
|
80
|
-
dfdx[j*n+i] = df[j]
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
dfdx
|
|
84
|
-
end
|
|
85
|
-
end
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Solves a*x = b for x, using LU decomposition.
|
|
3
|
-
#
|
|
4
|
-
module LUSolve
|
|
5
|
-
# Performs LU decomposition of the n by n matrix a.
|
|
6
|
-
def ludecomp(a,n,zero=0,one=1)
|
|
7
|
-
prec = BigDecimal.limit(nil)
|
|
8
|
-
ps = []
|
|
9
|
-
scales = []
|
|
10
|
-
for i in 0...n do # pick up largest(abs. val.) element in each row.
|
|
11
|
-
ps <<= i
|
|
12
|
-
nrmrow = zero
|
|
13
|
-
ixn = i*n
|
|
14
|
-
for j in 0...n do
|
|
15
|
-
biggst = a[ixn+j].abs
|
|
16
|
-
nrmrow = biggst if biggst>nrmrow
|
|
17
|
-
end
|
|
18
|
-
if nrmrow>zero then
|
|
19
|
-
scales <<= one.div(nrmrow,prec)
|
|
20
|
-
else
|
|
21
|
-
raise "Singular matrix"
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
n1 = n - 1
|
|
25
|
-
for k in 0...n1 do # Gaussian elimination with partial pivoting.
|
|
26
|
-
biggst = zero;
|
|
27
|
-
for i in k...n do
|
|
28
|
-
size = a[ps[i]*n+k].abs*scales[ps[i]]
|
|
29
|
-
if size>biggst then
|
|
30
|
-
biggst = size
|
|
31
|
-
pividx = i
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
raise "Singular matrix" if biggst<=zero
|
|
35
|
-
if pividx!=k then
|
|
36
|
-
j = ps[k]
|
|
37
|
-
ps[k] = ps[pividx]
|
|
38
|
-
ps[pividx] = j
|
|
39
|
-
end
|
|
40
|
-
pivot = a[ps[k]*n+k]
|
|
41
|
-
for i in (k+1)...n do
|
|
42
|
-
psin = ps[i]*n
|
|
43
|
-
a[psin+k] = mult = a[psin+k].div(pivot,prec)
|
|
44
|
-
if mult!=zero then
|
|
45
|
-
pskn = ps[k]*n
|
|
46
|
-
for j in (k+1)...n do
|
|
47
|
-
a[psin+j] -= mult.mult(a[pskn+j],prec)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
raise "Singular matrix" if a[ps[n1]*n+n1] == zero
|
|
53
|
-
ps
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# Solves a*x = b for x, using LU decomposition.
|
|
57
|
-
#
|
|
58
|
-
# a is a matrix, b is a constant vector, x is the solution vector.
|
|
59
|
-
#
|
|
60
|
-
# ps is the pivot, a vector which indicates the permutation of rows performed
|
|
61
|
-
# during LU decomposition.
|
|
62
|
-
def lusolve(a,b,ps,zero=0.0)
|
|
63
|
-
prec = BigDecimal.limit(nil)
|
|
64
|
-
n = ps.size
|
|
65
|
-
x = []
|
|
66
|
-
for i in 0...n do
|
|
67
|
-
dot = zero
|
|
68
|
-
psin = ps[i]*n
|
|
69
|
-
for j in 0...i do
|
|
70
|
-
dot = a[psin+j].mult(x[j],prec) + dot
|
|
71
|
-
end
|
|
72
|
-
x <<= b[ps[i]] - dot
|
|
73
|
-
end
|
|
74
|
-
(n-1).downto(0) do |i|
|
|
75
|
-
dot = zero
|
|
76
|
-
psin = ps[i]*n
|
|
77
|
-
for j in (i+1)...n do
|
|
78
|
-
dot = a[psin+j].mult(x[j],prec) + dot
|
|
79
|
-
end
|
|
80
|
-
x[i] = (x[i]-dot).div(a[psin+i],prec)
|
|
81
|
-
end
|
|
82
|
-
x
|
|
83
|
-
end
|
|
84
|
-
end
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
#--
|
|
3
|
-
# Contents:
|
|
4
|
-
# sqrt(x, prec)
|
|
5
|
-
# sin (x, prec)
|
|
6
|
-
# cos (x, prec)
|
|
7
|
-
# atan(x, prec) Note: |x|<1, x=0.9999 may not converge.
|
|
8
|
-
# exp (x, prec)
|
|
9
|
-
# log (x, prec)
|
|
10
|
-
# PI (prec)
|
|
11
|
-
# E (prec) == exp(1.0,prec)
|
|
12
|
-
#
|
|
13
|
-
# where:
|
|
14
|
-
# x ... BigDecimal number to be computed.
|
|
15
|
-
# |x| must be small enough to get convergence.
|
|
16
|
-
# prec ... Number of digits to be obtained.
|
|
17
|
-
#++
|
|
18
|
-
#
|
|
19
|
-
# Provides mathematical functions.
|
|
20
|
-
#
|
|
21
|
-
# Example:
|
|
22
|
-
#
|
|
23
|
-
# require "bigdecimal"
|
|
24
|
-
# require "bigdecimal/math"
|
|
25
|
-
#
|
|
26
|
-
# include BigMath
|
|
27
|
-
#
|
|
28
|
-
# a = BigDecimal((PI(100)/2).to_s)
|
|
29
|
-
# puts sin(a,100) # -> 0.10000000000000000000......E1
|
|
30
|
-
#
|
|
31
|
-
module BigMath
|
|
32
|
-
|
|
33
|
-
# Computes the square root of x to the specified number of digits of
|
|
34
|
-
# precision.
|
|
35
|
-
#
|
|
36
|
-
# BigDecimal.new('2').sqrt(16).to_s
|
|
37
|
-
# -> "0.14142135623730950488016887242096975E1"
|
|
38
|
-
#
|
|
39
|
-
def sqrt(x,prec)
|
|
40
|
-
x.sqrt(prec)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# Computes the sine of x to the specified number of digits of precision.
|
|
44
|
-
#
|
|
45
|
-
# If x is infinite or NaN, returns NaN.
|
|
46
|
-
def sin(x, prec)
|
|
47
|
-
raise ArgumentError, "Zero or negative precision for sin" if prec <= 0
|
|
48
|
-
return BigDecimal("NaN") if x.infinite? || x.nan?
|
|
49
|
-
n = prec + BigDecimal.double_fig
|
|
50
|
-
one = BigDecimal("1")
|
|
51
|
-
two = BigDecimal("2")
|
|
52
|
-
x1 = x
|
|
53
|
-
x2 = x.mult(x,n)
|
|
54
|
-
sign = 1
|
|
55
|
-
y = x
|
|
56
|
-
d = y
|
|
57
|
-
i = one
|
|
58
|
-
z = one
|
|
59
|
-
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
|
|
60
|
-
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
|
61
|
-
sign = -sign
|
|
62
|
-
x1 = x2.mult(x1,n)
|
|
63
|
-
i += two
|
|
64
|
-
z *= (i-one) * i
|
|
65
|
-
d = sign * x1.div(z,m)
|
|
66
|
-
y += d
|
|
67
|
-
end
|
|
68
|
-
y
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# Computes the cosine of x to the specified number of digits of precision.
|
|
72
|
-
#
|
|
73
|
-
# If x is infinite or NaN, returns NaN.
|
|
74
|
-
def cos(x, prec)
|
|
75
|
-
raise ArgumentError, "Zero or negative precision for cos" if prec <= 0
|
|
76
|
-
return BigDecimal("NaN") if x.infinite? || x.nan?
|
|
77
|
-
n = prec + BigDecimal.double_fig
|
|
78
|
-
one = BigDecimal("1")
|
|
79
|
-
two = BigDecimal("2")
|
|
80
|
-
x1 = one
|
|
81
|
-
x2 = x.mult(x,n)
|
|
82
|
-
sign = 1
|
|
83
|
-
y = one
|
|
84
|
-
d = y
|
|
85
|
-
i = BigDecimal("0")
|
|
86
|
-
z = one
|
|
87
|
-
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
|
|
88
|
-
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
|
89
|
-
sign = -sign
|
|
90
|
-
x1 = x2.mult(x1,n)
|
|
91
|
-
i += two
|
|
92
|
-
z *= (i-one) * i
|
|
93
|
-
d = sign * x1.div(z,m)
|
|
94
|
-
y += d
|
|
95
|
-
end
|
|
96
|
-
y
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
# Computes the arctangent of x to the specified number of digits of precision.
|
|
100
|
-
#
|
|
101
|
-
# If x is infinite or NaN, returns NaN.
|
|
102
|
-
# Raises an argument error if x > 1.
|
|
103
|
-
def atan(x, prec)
|
|
104
|
-
raise ArgumentError, "Zero or negative precision for atan" if prec <= 0
|
|
105
|
-
return BigDecimal("NaN") if x.infinite? || x.nan?
|
|
106
|
-
raise ArgumentError, "x.abs must be less than 1.0" if x.abs>=1
|
|
107
|
-
n = prec + BigDecimal.double_fig
|
|
108
|
-
y = x
|
|
109
|
-
d = y
|
|
110
|
-
t = x
|
|
111
|
-
r = BigDecimal("3")
|
|
112
|
-
x2 = x.mult(x,n)
|
|
113
|
-
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
|
|
114
|
-
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
|
115
|
-
t = -t.mult(x2,n)
|
|
116
|
-
d = t.div(r,m)
|
|
117
|
-
y += d
|
|
118
|
-
r += 2
|
|
119
|
-
end
|
|
120
|
-
y
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
# Computes the value of e (the base of natural logarithms) raised to the
|
|
124
|
-
# power of x, to the specified number of digits of precision.
|
|
125
|
-
#
|
|
126
|
-
# If x is infinite or NaN, returns NaN.
|
|
127
|
-
#
|
|
128
|
-
# BigMath::exp(BigDecimal.new('1'), 10).to_s
|
|
129
|
-
# -> "0.271828182845904523536028752390026306410273E1"
|
|
130
|
-
def exp(x, prec)
|
|
131
|
-
raise ArgumentError, "Zero or negative precision for exp" if prec <= 0
|
|
132
|
-
return BigDecimal("NaN") if x.infinite? || x.nan?
|
|
133
|
-
n = prec + BigDecimal.double_fig
|
|
134
|
-
one = BigDecimal("1")
|
|
135
|
-
x1 = one
|
|
136
|
-
y = one
|
|
137
|
-
d = y
|
|
138
|
-
z = one
|
|
139
|
-
i = 0
|
|
140
|
-
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
|
|
141
|
-
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
|
142
|
-
x1 = x1.mult(x,n)
|
|
143
|
-
i += 1
|
|
144
|
-
z *= i
|
|
145
|
-
d = x1.div(z,m)
|
|
146
|
-
y += d
|
|
147
|
-
end
|
|
148
|
-
y
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
# Computes the natural logarithm of x to the specified number of digits
|
|
152
|
-
# of precision.
|
|
153
|
-
#
|
|
154
|
-
# Returns x if x is infinite or NaN.
|
|
155
|
-
#
|
|
156
|
-
def log(x, prec)
|
|
157
|
-
raise ArgumentError, "Zero or negative argument for log" if x <= 0 || prec <= 0
|
|
158
|
-
return x if x.infinite? || x.nan?
|
|
159
|
-
one = BigDecimal("1")
|
|
160
|
-
two = BigDecimal("2")
|
|
161
|
-
n = prec + BigDecimal.double_fig
|
|
162
|
-
x = (x - one).div(x + one,n)
|
|
163
|
-
x2 = x.mult(x,n)
|
|
164
|
-
y = x
|
|
165
|
-
d = y
|
|
166
|
-
i = one
|
|
167
|
-
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
|
|
168
|
-
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
|
169
|
-
x = x2.mult(x,n)
|
|
170
|
-
i += two
|
|
171
|
-
d = x.div(i,m)
|
|
172
|
-
y += d
|
|
173
|
-
end
|
|
174
|
-
y*two
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
# Computes the value of pi to the specified number of digits of precision.
|
|
178
|
-
def PI(prec)
|
|
179
|
-
raise ArgumentError, "Zero or negative argument for PI" if prec <= 0
|
|
180
|
-
n = prec + BigDecimal.double_fig
|
|
181
|
-
zero = BigDecimal("0")
|
|
182
|
-
one = BigDecimal("1")
|
|
183
|
-
two = BigDecimal("2")
|
|
184
|
-
|
|
185
|
-
m25 = BigDecimal("-0.04")
|
|
186
|
-
m57121 = BigDecimal("-57121")
|
|
187
|
-
|
|
188
|
-
pi = zero
|
|
189
|
-
|
|
190
|
-
d = one
|
|
191
|
-
k = one
|
|
192
|
-
w = one
|
|
193
|
-
t = BigDecimal("-80")
|
|
194
|
-
while d.nonzero? && ((m = n - (pi.exponent - d.exponent).abs) > 0)
|
|
195
|
-
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
|
196
|
-
t = t*m25
|
|
197
|
-
d = t.div(k,m)
|
|
198
|
-
k = k+two
|
|
199
|
-
pi = pi + d
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
d = one
|
|
203
|
-
k = one
|
|
204
|
-
w = one
|
|
205
|
-
t = BigDecimal("956")
|
|
206
|
-
while d.nonzero? && ((m = n - (pi.exponent - d.exponent).abs) > 0)
|
|
207
|
-
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
|
208
|
-
t = t.div(m57121,n)
|
|
209
|
-
d = t.div(k,m)
|
|
210
|
-
pi = pi + d
|
|
211
|
-
k = k+two
|
|
212
|
-
end
|
|
213
|
-
pi
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
# Computes e (the base of natural logarithms) to the specified number of
|
|
217
|
-
# digits of precision.
|
|
218
|
-
def E(prec)
|
|
219
|
-
raise ArgumentError, "Zero or negative precision for E" if prec <= 0
|
|
220
|
-
n = prec + BigDecimal.double_fig
|
|
221
|
-
one = BigDecimal("1")
|
|
222
|
-
y = one
|
|
223
|
-
d = y
|
|
224
|
-
z = one
|
|
225
|
-
i = 0
|
|
226
|
-
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
|
|
227
|
-
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
|
228
|
-
i += 1
|
|
229
|
-
z *= i
|
|
230
|
-
d = one.div(z,m)
|
|
231
|
-
y += d
|
|
232
|
-
end
|
|
233
|
-
y
|
|
234
|
-
end
|
|
235
|
-
end
|