ccmath 0.2.71 → 0.2.718
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/CHANGELOG.md +1 -0
- data/README.md +14 -7
- data/ext/ccmath/ccmath.c +20 -20
- data/lib/ccmath/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 979543fe759c6e85612bd3a9d89558b259e3de58
|
4
|
+
data.tar.gz: 98123a1a0f6ab2947285814d8ebcc1a7a92e8472
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96f050ff40340b62ebf98609fde8ffd315f0907a302e36c9852807ce746c5efc4f77534f91b5eb32bd15d529a06ddfad49b47505d1b58633a224935a6e916e1c
|
7
|
+
data.tar.gz: edb0f7ec2e5d43e968ad51f707bfad35e97b70afa9d255857d5bad9b03072dd8c6e64ff4c21004d21a743627fb142952958d5c7494d34691a7c7b0101af46908
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
## Hopefully, CCMath is better than CMath...! (・ω・;)
|
2
2
|
|
3
3
|
[](https://travis-ci.org/gogotanaka/ccmath)
|
4
4
|
|
@@ -17,18 +17,25 @@ CCMath.cos(1)
|
|
17
17
|
|
18
18
|
```
|
19
19
|
Calculating -------------------------------------
|
20
|
-
CMath
|
21
|
-
CCMath
|
20
|
+
CMath 28.423k i/100ms
|
21
|
+
CCMath 61.123k i/100ms
|
22
22
|
-------------------------------------------------
|
23
|
-
CMath
|
24
|
-
CCMath 1.
|
23
|
+
CMath 379.852k (± 4.2%) i/s - 1.904M
|
24
|
+
CCMath 1.163M (± 4.0%) i/s - 5.807M
|
25
25
|
|
26
26
|
Comparison:
|
27
|
-
CCMath:
|
28
|
-
CMath:
|
27
|
+
CCMath: 1163020.7 i/s
|
28
|
+
CMath: 379852.3 i/s - 3.06x slower
|
29
29
|
|
30
30
|
```
|
31
31
|
|
32
|
+
## What's the difference between CCMath and CMath..?(・ω・;)
|
33
|
+
1. CCMath return Complex object even if image part is equivalent 0.
|
34
|
+
2. Faster(about 3 times)
|
35
|
+
3. Better error handling
|
36
|
+
|
37
|
+
Other behaviours suppose to be same.
|
38
|
+
|
32
39
|
## Installation
|
33
40
|
|
34
41
|
|
data/ext/ccmath/ccmath.c
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
VALUE rb_mCCMath;
|
4
4
|
VALUE rb_eMathDomainError;
|
5
5
|
|
6
|
-
static ID
|
6
|
+
static ID id_power;
|
7
7
|
|
8
8
|
#define RB_BIGNUM_TYPE_P(x) RB_TYPE_P((x), T_BIGNUM)
|
9
9
|
#define BIGNUM_POSITIVE_P(b) (FIX2LONG(rb_big_cmp((b), INT2FIX(0))) >= 0)
|
@@ -38,10 +38,23 @@ num2dbl_without_to_f(VALUE num)
|
|
38
38
|
|
39
39
|
#define NUM2DBL_F(x) num2dbl_without_to_f(x)
|
40
40
|
|
41
|
-
inline static
|
42
|
-
|
41
|
+
inline static int
|
42
|
+
real_p(VALUE x)
|
43
43
|
{
|
44
|
-
|
44
|
+
if (SPECIAL_CONST_P(x)){
|
45
|
+
if (FIXNUM_P(x) || FLONUM_P(x)) {
|
46
|
+
return 1;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
else {
|
50
|
+
switch (BUILTIN_TYPE(x)) {
|
51
|
+
case T_FLOAT: return 1;
|
52
|
+
case T_BIGNUM: return 1;
|
53
|
+
case T_RATIONAL: return 1;
|
54
|
+
case T_COMPLEX: return 0;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
rb_raise(rb_eTypeError, "Numeric Number required");
|
45
58
|
}
|
46
59
|
|
47
60
|
#define binop(n,op) \
|
@@ -60,8 +73,7 @@ binop(pow, id_power)
|
|
60
73
|
inline static VALUE
|
61
74
|
DBLS2COMP(double real, double imag)
|
62
75
|
{
|
63
|
-
NEWOBJ_OF(obj, struct RComplex, rb_cComplex,
|
64
|
-
T_COMPLEX | (RGENGC_WB_PROTECTED_COMPLEX ? FL_WB_PROTECTED : 0));
|
76
|
+
NEWOBJ_OF(obj, struct RComplex, rb_cComplex, T_COMPLEX | FL_WB_PROTECTED);
|
65
77
|
|
66
78
|
RCOMPLEX_SET_REAL(obj, DBL2NUM(real));
|
67
79
|
RCOMPLEX_SET_IMAG(obj, DBL2NUM(imag));
|
@@ -82,7 +94,7 @@ DBLS2COMP(double real, double imag)
|
|
82
94
|
#define EXTRACT_DBLS(z); \
|
83
95
|
double z##_real, z##_imag; \
|
84
96
|
do { \
|
85
|
-
if (
|
97
|
+
if (real_p(z)) { \
|
86
98
|
EXTRACT_DBLS_FROM_REAL(z) \
|
87
99
|
} else { \
|
88
100
|
EXTRACT_DBLS_FROM_COMP(z) \
|
@@ -156,7 +168,7 @@ ccmath_log(int argc, const VALUE* argv, VALUE obj)
|
|
156
168
|
EXTRACT_DBLS(z);
|
157
169
|
float r = hypot(z_real, z_imag);
|
158
170
|
if (argc == 2) {
|
159
|
-
|
171
|
+
real_p(base);
|
160
172
|
EXTRACT_DBLS(base);
|
161
173
|
if (base_imag != 0.0) domain_error("log");
|
162
174
|
if (base_real > 0.0) {
|
@@ -364,18 +376,9 @@ ccmath_gamma(VALUE obj, VALUE z)
|
|
364
376
|
}
|
365
377
|
}
|
366
378
|
|
367
|
-
// static VALUE
|
368
|
-
// ccmath_define_set(VALUE obj, VALUE str)
|
369
|
-
// {
|
370
|
-
// rb_ivar_set(obj, id_set, str);
|
371
|
-
// return obj;
|
372
|
-
// }
|
373
|
-
|
374
379
|
void Init_ccmath(void)
|
375
380
|
{
|
376
|
-
id_real_p = rb_intern("real?");
|
377
381
|
id_power = rb_intern("**");
|
378
|
-
id_set = rb_intern("set");
|
379
382
|
rb_mCCMath = rb_define_module("CCMath");
|
380
383
|
|
381
384
|
rb_eMathDomainError = rb_define_class_under(rb_mCCMath, "DomainError", rb_eStandardError);
|
@@ -409,7 +412,4 @@ void Init_ccmath(void)
|
|
409
412
|
rb_define_module_function(rb_mCCMath, "atanh", ccmath_atanh, 1);
|
410
413
|
rb_define_module_function(rb_mCCMath, "atan", ccmath_atan, 1);
|
411
414
|
rb_define_module_function(rb_mCCMath, "gamma", ccmath_gamma, 1);
|
412
|
-
// rb_define_module_function(rb_mCCMath, "set=", ccmath_define_set, 1);
|
413
|
-
|
414
|
-
// rb_ivar_set(rb_mCCMath, id_set, rb_str_new2("R"));
|
415
415
|
}
|
data/lib/ccmath/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ccmath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.718
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gogotanaka
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
110
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.4.5
|
111
|
+
rubygems_version: 2.4.5.1
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Implement CMath with C.
|