random_variable 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ext/random_variable.c +48 -1
- metadata +5 -5
data/lib/ext/random_variable.c
CHANGED
@@ -269,6 +269,24 @@ static type_t type(VALUE rb_obj)
|
|
269
269
|
/******************************************************************************/
|
270
270
|
/* functions and macros for parameter validity checks */
|
271
271
|
/******************************************************************************/
|
272
|
+
#define CHECK_NUMBER(x) \
|
273
|
+
do { \
|
274
|
+
\
|
275
|
+
if (isinf((x)) == 1) \
|
276
|
+
rb_raise(rb_eArgError, \
|
277
|
+
#x " parameter " \
|
278
|
+
"is Infinity"); \
|
279
|
+
if (isinf((x)) == -1) \
|
280
|
+
rb_raise(rb_eArgError, \
|
281
|
+
#x " parameter " \
|
282
|
+
"is -Infinity"); \
|
283
|
+
if (isnan((x))) \
|
284
|
+
rb_raise(rb_eArgError, \
|
285
|
+
#x " parameter " \
|
286
|
+
"is not a number" \
|
287
|
+
" (NaN)"); \
|
288
|
+
} while (0)
|
289
|
+
|
272
290
|
#define CHECK_POSITIVE(x) \
|
273
291
|
do { \
|
274
292
|
if ((x) <= 0.0) \
|
@@ -376,6 +394,8 @@ VALUE rb_create_instance(VALUE rb_obj, ...)
|
|
376
394
|
|
377
395
|
rb_p = GET_NEXT_ARG(ap);
|
378
396
|
p = NUM2DBL(rb_p);
|
397
|
+
|
398
|
+
CHECK_NUMBER(p);
|
379
399
|
|
380
400
|
/* 0 <= p <= 1 */
|
381
401
|
CHECK_PROBABILITY(p);
|
@@ -397,6 +417,9 @@ VALUE rb_create_instance(VALUE rb_obj, ...)
|
|
397
417
|
alpha = NUM2DBL(rb_alpha);
|
398
418
|
beta = NUM2DBL(rb_beta);
|
399
419
|
|
420
|
+
CHECK_NUMBER(alpha);
|
421
|
+
CHECK_NUMBER(beta);
|
422
|
+
|
400
423
|
/* alpha > 0 */
|
401
424
|
CHECK_POSITIVE(alpha);
|
402
425
|
|
@@ -423,6 +446,8 @@ VALUE rb_create_instance(VALUE rb_obj, ...)
|
|
423
446
|
|
424
447
|
n = NUM2LONG(rb_n);
|
425
448
|
p = NUM2DBL(rb_p);
|
449
|
+
|
450
|
+
CHECK_NUMBER(p);
|
426
451
|
|
427
452
|
/* n >= 0 */
|
428
453
|
CHECK_NON_NEGATIVE(n);
|
@@ -467,6 +492,9 @@ VALUE rb_create_instance(VALUE rb_obj, ...)
|
|
467
492
|
a = NUM2DBL(rb_a);
|
468
493
|
b = NUM2DBL(rb_b);
|
469
494
|
|
495
|
+
CHECK_NUMBER(a);
|
496
|
+
CHECK_NUMBER(b);
|
497
|
+
|
470
498
|
/* a < b */
|
471
499
|
CHECK_LESS_THAN(a,b);
|
472
500
|
|
@@ -478,7 +506,7 @@ VALUE rb_create_instance(VALUE rb_obj, ...)
|
|
478
506
|
|
479
507
|
CASE(discrete_uniform)
|
480
508
|
VALUE rb_a, rb_b;
|
481
|
-
|
509
|
+
long a,b;
|
482
510
|
|
483
511
|
SET_KLASS(discrete_uniform);
|
484
512
|
|
@@ -509,6 +537,8 @@ VALUE rb_create_instance(VALUE rb_obj, ...)
|
|
509
537
|
rb_mean = GET_NEXT_ARG(ap);
|
510
538
|
mean = NUM2DBL(rb_mean);
|
511
539
|
|
540
|
+
CHECK_NUMBER(mean);
|
541
|
+
|
512
542
|
/* mean > 0 */
|
513
543
|
CHECK_POSITIVE(mean);
|
514
544
|
|
@@ -529,6 +559,9 @@ VALUE rb_create_instance(VALUE rb_obj, ...)
|
|
529
559
|
d1 = NUM2DBL(rb_d1);
|
530
560
|
d2 = NUM2DBL(rb_d2);
|
531
561
|
|
562
|
+
CHECK_NUMBER(d1);
|
563
|
+
CHECK_NUMBER(d2);
|
564
|
+
|
532
565
|
/* d1 > 0 */
|
533
566
|
/* d2 > 0 */
|
534
567
|
CHECK_POSITIVE(d1);
|
@@ -555,6 +588,7 @@ VALUE rb_create_instance(VALUE rb_obj, ...)
|
|
555
588
|
r = NUM2LONG(rb_r);
|
556
589
|
p = NUM2DBL(rb_p);
|
557
590
|
|
591
|
+
CHECK_NUMBER(p);
|
558
592
|
/* r > 0 */
|
559
593
|
CHECK_POSITIVE(r);
|
560
594
|
/* 0 < p < 0 */
|
@@ -576,8 +610,12 @@ VALUE rb_create_instance(VALUE rb_obj, ...)
|
|
576
610
|
|
577
611
|
rb_mu = GET_NEXT_ARG(ap);
|
578
612
|
rb_sigma = GET_NEXT_ARG(ap);
|
613
|
+
|
579
614
|
mu = NUM2DBL(rb_mu);
|
580
615
|
sigma = NUM2DBL(rb_sigma);
|
616
|
+
|
617
|
+
CHECK_NUMBER(mu);
|
618
|
+
CHECK_NUMBER(sigma);
|
581
619
|
|
582
620
|
/* sigma > 0 */
|
583
621
|
CHECK_POSITIVE(sigma);
|
@@ -600,6 +638,9 @@ VALUE rb_create_instance(VALUE rb_obj, ...)
|
|
600
638
|
a = NUM2DBL(rb_a);
|
601
639
|
m = NUM2DBL(rb_m);
|
602
640
|
|
641
|
+
CHECK_NUMBER(a);
|
642
|
+
CHECK_NUMBER(m);
|
643
|
+
|
603
644
|
/* a > 0 */
|
604
645
|
CHECK_POSITIVE(a);
|
605
646
|
|
@@ -620,6 +661,9 @@ VALUE rb_create_instance(VALUE rb_obj, ...)
|
|
620
661
|
|
621
662
|
rb_mean = GET_NEXT_ARG(ap);
|
622
663
|
mean = NUM2DBL(rb_mean);
|
664
|
+
|
665
|
+
CHECK_NUMBER(mean);
|
666
|
+
|
623
667
|
/* mean > 0 */
|
624
668
|
CHECK_POSITIVE(mean);
|
625
669
|
|
@@ -643,6 +687,8 @@ VALUE rb_create_instance(VALUE rb_obj, ...)
|
|
643
687
|
rb_sigma = GET_NEXT_ARG(ap);
|
644
688
|
sigma = NUM2DBL(rb_sigma);
|
645
689
|
|
690
|
+
CHECK_NUMBER(sigma);
|
691
|
+
|
646
692
|
/* sigma > 0 */
|
647
693
|
CHECK_POSITIVE(sigma);
|
648
694
|
|
@@ -663,6 +709,7 @@ VALUE rb_create_instance(VALUE rb_obj, ...)
|
|
663
709
|
va_end(ap);
|
664
710
|
return rb_rv;
|
665
711
|
}
|
712
|
+
#undef CHECK_NUMBER
|
666
713
|
#undef CHECK_POSITIVE
|
667
714
|
#undef CHECK_NON_NEGATIVE
|
668
715
|
#undef CHECK_LESS_THAN
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: random_variable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
15
|
-
Pareto, Poisson, etc.
|
14
|
+
description: ! 'random variables for a wide variety of probability distributions such
|
15
|
+
as: Binomial, Beta, Chi-Squared, Normal, Pareto, Poisson, etc.'
|
16
16
|
email: jorge.madronal.rinaldi@gmail.com
|
17
17
|
executables: []
|
18
18
|
extensions:
|
@@ -59,5 +59,5 @@ rubyforge_project:
|
|
59
59
|
rubygems_version: 1.8.24
|
60
60
|
signing_key:
|
61
61
|
specification_version: 3
|
62
|
-
summary: Random Variables in Ruby
|
62
|
+
summary: Random Variables in Ruby
|
63
63
|
test_files: []
|