-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruby_class_mods.c
2115 lines (1843 loc) · 81 KB
/
ruby_class_mods.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// encoding: UTF-8
/*____________________________________________________________________________________________________________________________________________________________________
__ __ __ __ __ __ ___ __
| | |__) |__) /\ |__) \ / | |\/| |__) / \ |__) | /__`
|___ | |__) | \ /~~\ | \ | | | | | \__/ | \ | .__/
____________________________________________________________________________________________________________________________________________________________________ */
#include "ruby.h"
#include "ruby/ruby.h"
#include "ruby/config.h"
#include <ruby/defines.h>
#include <ruby/version.h>
#include <ruby/vm.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <inttypes.h>
#include <float.h>
//#include <math.h>
#include <tgmath.h>
//#include <complex.h>
#ifdef RUUUBY_F98_DEBUG
#ifdef RUUUBY_F98_TIMER
#include <time.h>
#include <sys/time.h>
#endif
#endif
#ifndef CRUUUBY_H
#include "ruby_class_mods.h"
#endif
#ifdef RUUUBY_DEBUGGING
#include "optional_00_debugging.h"
#include "optional_01_universal_math_funcs.h"
#include "optional_02_stats_funcs.h"
#endif
/*____________________________________________________________________________________________________________________
__ __ ___ __ __
/ ` /\ / ` |__| |__ . |__) | | |__) \ /
\__, /~~\ \__, | | |___ . | \ \__/ |__) |
_____________________________________________________________________________________________________________________ */
#ifdef RUUUBY_F06_B08
static VALUE Ⓒmatrix;
static inline VALUE is_a_matrix(const VALUE arg);
static inline VALUE is_a_matrix(const VALUE arg){return rb_obj_is_instance_of(arg, Ⓒmatrix);}
#endif
#ifdef RUUUBY_F06_B09
static VALUE Ⓒvector;
static inline VALUE is_a_vector(const VALUE arg);
static inline VALUE is_a_vector(const VALUE arg){return rb_obj_is_instance_of(arg, Ⓒvector);}
#endif
/* __ ___ __
__ /\ \__ /\_ \ /\ \__
/\_\ ___\ \ ,_\ __ _ __ ___ __ \//\ \ ____ __\ \ ,_\ __ __ _____
\/\ \ /' _ `\ \ \/ /'__`\/\`'__\/' _ `\ /'__`\ \ \ \ /',__\ /'__`\ \ \/ /\ \/\ \/\ '__`\
\ \ \/\ \/\ \ \ \_/\ __/\ \ \/ /\ \/\ \/\ \L\.\_ \_\ \_ /\__, `\/\ __/\ \ \_\ \ \_\ \ \ \L\ \
\ \_\ \_\ \_\ \__\ \____\\ \_\ \ \_\ \_\ \__/.\_\/\____\ \/\____/\ \____\\ \__\\ \____/\ \ ,__/
\/_/\/_/\/_/\/__/\/____/ \/_/ \/_/\/_/\/__/\/_/\/____/ \/___/ \/____/ \/__/ \/___/ \ \ \/
\ \_\
\/_/ */
#define bsearch_power(val_to_find) (ID *) bsearch (&val_to_find, exponential_ids, NUM_EXPONENTS, sizeof(ID), _compare_func_4_object_id);
#define bsearch_power_position(arg_index) ((int)(((int)arg_index - (int)exponential_ids) / sizeof(ID)))
static inline int bsearch_result(ID * the_result) {return exponential_indexes[bsearch_power_position(the_result)];}
static inline int bsearch_operation(const VALUE them) {
const ID id_to_find = rb_sym2id(them);
ID * the_result = bsearch_power(id_to_find);
if (the_result != NULL) {
return bsearch_result(the_result);
} else {
return -1337;
}
}
static inline int is_num(const VALUE arg) {
switch(TYPE(arg)){
case RUBY_T_FIXNUM:case RUBY_T_FLOAT:case RUBY_T_RATIONAL:case RUBY_T_COMPLEX:case RUBY_T_BIGNUM:
re_c_ye
default:
re_as_c_bool(rb_obj_is_instance_of(arg, Ⓒbig_decimal))
}
}
static inline int is_non_simple_num(const VALUE arg) {
switch(TYPE(arg)){
case RUBY_T_RATIONAL:case RUBY_T_COMPLEX:
re_c_ye
default:
re_as_c_bool(rb_obj_is_instance_of(arg, Ⓒbig_decimal))
}
}
static void internal_only_prepare_f16(void) {
rb_gc_disable();
// | ∉ | 8713 |
// | ∅ | 8709 |
cached_flt_inf = rb_const_get_at(R_FLT, rb_intern("INFINITY"));
cached_flt_negative_inf = rb_const_get_at(R_FLT, rb_intern("INFINITY_NEGATIVE"));
cached_flt_inf_complex = rb_const_get_at(R_FLT, rb_intern("INFINITY_COMPLEX"));
VALUE pack_as_utf8 = rb_str_new_cstr("U*");
ID rb_intern_pack = rb_intern("pack");
VALUE code_points = 💎new_ary_size2(INT2FIX(8713), INT2FIX(8709));
💎PROCEDURE_00(🅽_no_empty)
rb_ary_modify(code_points);
r_ary_set_p0_p1(code_points, INT2FIX(8712), INT2FIX(8469))
💎PROCEDURE_00(🅽_natural)
r_ary_set_p1(code_points, INT2FIX(120142))
💎PROCEDURE_00(🅽_whole)
r_ary_set_p1(code_points, INT2FIX(8484))
💎PROCEDURE_00(🅽_integer)
r_ary_set_p1(code_points, INT2FIX(120140))
💎PROCEDURE_00(🅽_universal)
r_ary_set_p1(code_points, INT2FIX(94))
💎PROCEDURE_00(🅽_superscripts)
r_ary_set_p1_p2(code_points, INT2FIX(8469), INT2FIX(120138))
💎PROCEDURE_00(🅽_natural_w_str_allowed)
r_ary_set_p1(code_points, INT2FIX(120142))
💎PROCEDURE_00(🅽_whole_w_str_allowed)
r_ary_set_p1(code_points, INT2FIX(8484))
💎PROCEDURE_00(🅽_integer_w_str_allowed)
r_ary_set_p1(code_points, INT2FIX(120140))
💎PROCEDURE_00(🅽_universal_w_str_allowed)
//rb_ary_free(code_points);
VALUE code_points2 = 💎new_ary_size2(INT2FIX(8315), INT2FIX(8313));
💎PROCEDURE_01(obj_id_n9, code_points2)
rb_ary_modify(code_points2);
r_ary_set_p1(code_points2, INT2FIX(8312))
💎PROCEDURE_01(obj_id_n8, code_points2)
r_ary_set_p1(code_points2, INT2FIX(8311))
💎PROCEDURE_01(obj_id_n7, code_points2)
r_ary_set_p1(code_points2, INT2FIX(8310))
💎PROCEDURE_01(obj_id_n6, code_points2)
r_ary_set_p1(code_points2, INT2FIX(8309))
💎PROCEDURE_01(obj_id_n5, code_points2)
r_ary_set_p1(code_points2, INT2FIX(8308))
💎PROCEDURE_01(obj_id_n4, code_points2)
r_ary_set_p1(code_points2, INT2FIX(179))
💎PROCEDURE_01(obj_id_n3, code_points2)
r_ary_set_p1(code_points2, INT2FIX(178))
💎PROCEDURE_01(obj_id_n2, code_points2)
r_ary_set_p1(code_points2, INT2FIX(185))
💎PROCEDURE_01(obj_id_n1, code_points2)
r_ary_set_p0_p1(code_points2, INT2FIX(8734), INT2FIX(8450))
💎PROCEDURE_01(obj_id_inf_complex, code_points2)
rb_ary_pop(code_points2);
r_ary_set_p0(code_points2, INT2FIX(8304))
💎PROCEDURE_01(obj_id_0, code_points2)
r_ary_set_p0(code_points2, INT2FIX(8313))
💎PROCEDURE_01(obj_id_9, code_points2)
r_ary_set_p0(code_points2, INT2FIX(8312))
💎PROCEDURE_01(obj_id_8, code_points2)
r_ary_set_p0(code_points2, INT2FIX(8311))
💎PROCEDURE_01(obj_id_7, code_points2)
r_ary_set_p0(code_points2, INT2FIX(8310))
💎PROCEDURE_01(obj_id_6, code_points2)
r_ary_set_p0(code_points2, INT2FIX(8309))
💎PROCEDURE_01(obj_id_5, code_points2)
r_ary_set_p0(code_points2, INT2FIX(8308))
💎PROCEDURE_01(obj_id_4, code_points2)
r_ary_set_p0(code_points2, INT2FIX(179))
💎PROCEDURE_01(obj_id_3, code_points2)
r_ary_set_p0(code_points2, INT2FIX(178))
💎PROCEDURE_01(obj_id_2, code_points2)
r_ary_set_p0(code_points2, INT2FIX(185))
💎PROCEDURE_01(obj_id_1, code_points2)
r_ary_set_p0(code_points2, INT2FIX(8734))
💎PROCEDURE_01(obj_id_inf, code_points2)
r_ary_set_p0_p1(code_points2, INT2FIX(45), INT2FIX(8734))
const ID obj_id_inf_negative = rb_sym2id(rb_to_symbol(rb_funcall(code_points2, rb_intern_pack, 1, pack_as_utf8)));
//rb_ary_free(code_points2);
//rb_str_free(pack_as_utf8);
exponential_ids[0] = obj_id_n9;
exponential_ids[1] = obj_id_n8;
exponential_ids[2] = obj_id_n7;
exponential_ids[3] = obj_id_n6;
exponential_ids[4] = obj_id_n5;
exponential_ids[5] = obj_id_n4;
exponential_ids[6] = obj_id_n3;
exponential_ids[7] = obj_id_n2;
exponential_ids[8] = obj_id_n1;
exponential_ids[9] = obj_id_0;
exponential_ids[10] = obj_id_1;
exponential_ids[11] = obj_id_2;
exponential_ids[12] = obj_id_3;
exponential_ids[13] = obj_id_4;
exponential_ids[14] = obj_id_5;
exponential_ids[15] = obj_id_6;
exponential_ids[16] = obj_id_7;
exponential_ids[17] = obj_id_8;
exponential_ids[18] = obj_id_9;
exponential_ids[19] = obj_id_inf;
exponential_ids[20] = obj_id_inf_negative;
exponential_ids[21] = obj_id_inf_complex;
qsort(exponential_ids, NUM_EXPONENTS, sizeof(ID), _compare_func_4_object_id);
ID * the_index;
💎PROCEDURE_02(the_index, obj_id_n9, -9);
💎PROCEDURE_02(the_index, obj_id_n8, -8);
💎PROCEDURE_02(the_index, obj_id_n7, -7);
💎PROCEDURE_02(the_index, obj_id_n6, -6);
💎PROCEDURE_02(the_index, obj_id_n5, -5);
💎PROCEDURE_02(the_index, obj_id_n4, -4);
💎PROCEDURE_02(the_index, obj_id_n3, -3);
💎PROCEDURE_02(the_index, obj_id_n2, -2);
💎PROCEDURE_02(the_index, obj_id_n1, -1);
💎PROCEDURE_02(the_index, obj_id_0, 0);
💎PROCEDURE_02(the_index, obj_id_9, 9);
💎PROCEDURE_02(the_index, obj_id_8, 8);
💎PROCEDURE_02(the_index, obj_id_7, 7);
💎PROCEDURE_02(the_index, obj_id_6, 6);
💎PROCEDURE_02(the_index, obj_id_5, 5);
💎PROCEDURE_02(the_index, obj_id_4, 4);
💎PROCEDURE_02(the_index, obj_id_3, 3);
💎PROCEDURE_02(the_index, obj_id_2, 2);
💎PROCEDURE_02(the_index, obj_id_1, 1);
💎PROCEDURE_02(the_index, obj_id_inf, CACHE_INDEX_INF);
💎PROCEDURE_02(the_index, obj_id_inf_negative, CACHE_INDEX_INF_NEGATIVE);
💎PROCEDURE_02(the_index, obj_id_inf_complex, CACHE_INDEX_INF_COMPLEX);
rb_gc_enable();
rb_ary_free(code_points);
rb_ary_free(code_points2);
rb_str_free(pack_as_utf8);
}
static void startup_step5_protect_against_gc(void) {
rb_gc_register_address(& Ⓒset);
rb_gc_register_address(& Ⓒbig_decimal);
//rb_gc_verify_internal_consistency();
}
#ifdef RUUUBY_F98_DEBUG
#define ensure_file_loaded(path) if (rb_require(path) != Qtrue){printf("path already loaded {%s}\n", path);};
#else
#define ensure_file_loaded(path) rb_require(path);
#endif
static void startup_step4_load_needed_ruuuby_files(void) {
ensure_loaded_class(bitwise_flag)
ensure_all_loaded_for_ruuuby_engine()
ensure_all_loaded_for_attribute_includable()
ensure_all_loaded_for_module()
ensure_loaded_class(obj)
ensure_loaded_class(re)
ensure_loaded_ruuuby(arg_err)
ensure_loaded_enumerable(ary)
ensure_loaded_enumerable(hsh) // must be after{ary}
ensure_all_loaded_for_nums()
ensure_loaded_enumerable(set)
ensure_loaded_attribute_extendable(syntax_cache)
ensure_loaded_class(sym) // must be after{attribute_cardinality}
ensure_loaded_class(str) // must be after{attribute_syntax_cache, attribute_cardinality}
ensure_all_loaded_for_set_theory()
ensure_all_loaded_for_io() // must be after{attribute_syntax_cache}
ensure_loaded_math(cryptography/crypto)
internal_only_prepare_f16(); // must be after{ruuuby/types, ruuuby/class/str}
ensure_all_loaded_for_math_space()
ensure_loaded_math(expr/sequence)
#ifdef RUUUBY_F06_B08
ensure_loaded_nums(matrix)
#endif
#ifdef RUUUBY_F06_B09
ensure_loaded_nums(vector)
#endif
#ifdef RUUUBY_F38
ensure_all_loaded_for_tropical_algebra()
#endif
#ifdef RUUUBY_OPTIONAL_01
ensure_loaded_math(universal_functions/gamma)
#endif
#ifdef RUUUBY_F38
ensure_loaded_math(graph_theory/graph_theory)
ensure_loaded_math(finance/currency_matrix)
ensure_loaded_math(graph_theory/pseudo_graph)
#endif
ensure_loaded_math(finance/forex)
ensure_loaded_math(number_theory/number_theory) // must be after{expression/sequence/recursive_sequence}
ensure_all_loaded_for_statistics()
ensure_all_loaded_for_geometry()
ensure_loaded_ruuuby(heuristics/heuristics)
ensure_loaded_ruuuby(protocol/unix_socket)
ensure_loaded_ruuuby(protocol/http_request)
ensure_all_loaded_for_ruuuby()
#ifdef RUUUBY_F22_B00
ensure_loaded_ruuuby(ruuuby/engine/f22/b00)
#endif
#ifdef RUUUBY_F22_B01
ensure_loaded_ruuuby(ruuuby/engine/f22/b01)
#endif
#ifdef RUUUBY_F22_B05
ensure_loaded_ruuuby(ruuuby/engine/f22/b05)
#endif
#ifdef RUUUBY_F22_B06
ensure_loaded_ruuuby(ruuuby/engine/f22/b06)
#endif
#ifdef RUUUBY_F43
ensure_loaded_ruuuby(ruuuby/api/f43_api_iconv)
#endif
#ifdef RUUUBY_F92_B00
ensure_loaded_default(sqlite3)
#endif
#ifdef RUUUBY_F92_B01
ensure_loaded_default(active_record)
ensure_loaded_db(db_connection)
ensure_loaded_ruuuby(ruuuby/ruuuby_orm)
#endif
#ifdef RUUUBY_F92_B02
ensure_loaded_default(pg)
#endif
#ifdef RUUUBY_F92_B03
ensure_loaded_db(model_attributes/extendable/uid)
ensure_loaded_db(model_attributes/includable/uid)
ensure_loaded_db(model_attributes/application_record)
#endif
}
/*____________________________________________________________________________________________________________________________________________________________________
___ __ __ __ ___ __ __ ___ __ __ __ ___ ___ ___ ___ __ __
|__ | | |\ | / ` /__` . | \ |__ / ` | /\ |__) /\ | | / \ |\ | /__` __|__ | |\/| |__) | |__ |\/| |__ |\ | | /\ | | / \ |\ | /__`
| \__/ | \| \__, .__/ . |__/ |___ \__, |___ /~~\ | \ /~~\ | | \__/ | \| .__/ | | | | | |___ |___ | | |___ | \| | /~~\ | | \__/ | \| .__/
____________________________________________________________________________________________________________________________________________________________________ */
/*____________________________________________________________________________________________________________________
__ __ ___ __ ___
/ \ |__) | |__ / ` |
\__/ |__) \__/ |___ \__, |
_____________________________________________________________________________________________________________________ */
// | func{ary?} |
ⓡ𝑓_kargs(m_obj_is_ary,
💎parse_kargs_with_normalizer("ary?", re_as_bool(is_ary(self)),
if (them == 🅽_no_empty) {
if (is_ary(self)) {
if (r_ary_is_empty(self)) {re_no} else {re_ye}
} else {re_no}
} else {🛑normalizer_value("ary?", them)})
)
// | func{bool?} |
ⓡ𝑓_def(m_obj_is_bool, re_as_bool(is_bool(self)))
// | func{hash?} |
ⓡ𝑓_def(m_obj_is_hash, re_as_bool(is_hsh(self)))
// | func{flt?} |
ⓡ𝑓_kargs(m_obj_is_flt,
💎parse_kargs_with_normalizer("flt?", re_as_bool(is_float(self)),
if (them == 🅽_universal) {
if (is_float(self)) {
return c_flt_is_universal(NUM2DBL(self));
} else {re_no}
} else {🛑normalizer_value("flt?", them)})
)
// | func{sym?} |
ⓡ𝑓_kargs(m_obj_is_sym,
💎parse_kargs_with_normalizer("sym?", re_as_bool(is_sym(self)),
if (them == 🅽_superscripts) {
if (is_sym(self)) {
const int power_to_raise_to = bsearch_operation(self);
if (power_to_raise_to != -1337) {
if (power_to_raise_to < 10) {
return INT2FIX(power_to_raise_to);
} else if (power_to_raise_to > 1336 && power_to_raise_to < 1400) {
if (power_to_raise_to == CACHE_INDEX_INF) {
re_inf
} else if (power_to_raise_to == CACHE_INDEX_INF_NEGATIVE) {
return cached_flt_negative_inf;
} else {
re_inf_complex
}
} else {re_no}
} else {re_no}
} else {re_no}
} else {🛑normalizer_value("sym?", them)})
)
// | func{int?} |
ⓡ𝑓_kargs(m_obj_is_int,
💎parse_kargs_with_normalizer("int?", re_as_bool(is_int(self)),
if (is_fixnum(self)) {
r_int_passes_normalizer(self, them, "int?", FIX2INT)
} else if (is_bignum(self)) {
r_int_passes_normalizer(self, them, "int?", NUM2INT)
} else {re_no})
)
// | func{chr?} |
ⓡ𝑓_def(m_obj_is_chr, if (is_str(self)) {re_as_bool(r_str_len(self) == 1)} else {re_no})
// | func{set?} |
ⓡ𝑓_def(m_obj_is_set, return rb_obj_is_instance_of(self, Ⓒset);)
// | func{str?} |
ⓡ𝑓_kargs(m_obj_is_str,
💎parse_kargs_with_normalizer("str?", re_as_bool(is_str(self)),
if (them == 🅽_no_empty) {
if (is_str(self)) {
if (r_str_is_empty(self)) {re_no} else {re_ye}
} else {re_no}
} else {🛑normalizer_value("str?", them)})
)
// | func(num?} |
ⓡ𝑓_kargs(m_obj_is_num,
💎parse_kargs_with_normalizer("num?", re_as_bool(is_num(self)),
if (is_fixnum(self)) {
r_int_passes_normalizer(self, them, "num?", FIX2INT)
} else if (is_bignum(self)) {
r_int_passes_normalizer(self, them, "num?", NUM2INT)
} else if (is_float(self)) {
r_flt_passes_normalizer(self, them, "num?")
} else if (is_non_simple_num(self)) {
r_non_simple_num_passes_normalizer(self, them, "num?")
} else if (is_str(self)) {
r_str_passes_normalizer(self, them, "num?")
} else {re_no})
)
/*___________________________________________________________________________________________________________________
___ ___ __ ___ __
| |\ | | |__ / _` |__ |__)
| | \| | |___ \__> |___ | \
_____________________________________________________________________________________________________________________ */
// | func{finite?} |
ⓡ𝑓_const(m_int_is_finite, re_ye)
// | func{infinite?} |
ⓡ𝑓_const(m_int_is_not_finite, re_no)
// | func{^} |
ⓡ𝑓_self_them(m_int_patch_for_exponentials,
if (is_fixnum(them)) {
return INT2FIX(FIX2INT(self) ^ FIX2INT(them));
} else if (is_bignum(them)) {
return rb_big_xor(self, them);
} else if (is_sym(them)) {
const int power_to_raise_to = bsearch_operation(them);
if (power_to_raise_to != -1337) {
if (power_to_raise_to < 2) {
switch(power_to_raise_to) {
case -9: re_me_func_1args(ID_OF_POW, ℤn9)
case -8: re_me_func_1args(ID_OF_POW, ℤn8)
case -7: re_me_func_1args(ID_OF_POW, ℤn7)
case -6: re_me_func_1args(ID_OF_POW, ℤn6)
case -5: re_me_func_1args(ID_OF_POW, ℤn5)
case -4: re_me_func_1args(ID_OF_POW, ℤn4)
case -3: re_me_func_1args(ID_OF_POW, ℤn3)
case -2: re_me_func_1args(ID_OF_POW, ℤn2)
case -1: return rb_rational_new(ℤ1, self);
case 0: re_1
default: re_me
}
} else if (power_to_raise_to < 10) {
switch(power_to_raise_to) {
case 2: re_me_func_1args(ID_OF_POW, ℤ2)
case 3: re_me_func_1args(ID_OF_POW, ℤ3)
case 4: re_me_func_1args(ID_OF_POW, ℤ4)
case 5: re_me_func_1args(ID_OF_POW, ℤ5)
case 6: re_me_func_1args(ID_OF_POW, ℤ6)
case 7: re_me_func_1args(ID_OF_POW, ℤ7)
case 8: re_me_func_1args(ID_OF_POW, ℤ8)
default: re_me_func_1args(ID_OF_POW, ℤ9)
}
} else {
const int val_self = NUM2INT(self);
if (power_to_raise_to == CACHE_INDEX_INF_COMPLEX) {
if (val_self == 0) {
re_0
} else {
re_nan
}
}
if (val_self == 1 || val_self == -1) {
re_nan
} else if (val_self == 0) {
if (power_to_raise_to == CACHE_INDEX_INF) {
re_0
} else {
re_inf_complex
}
} else if (power_to_raise_to == CACHE_INDEX_INF_NEGATIVE) {
re_0
} else if (val_self > 1) {
re_inf
} else {
re_negative_inf
}
}
} else {ERR_c_self_arg_err__print_self_them("| c{Integer}-> m{^} self(%"PRIsVALUE") unable to match exponential(%"PRIsVALUE") |")}
} else {ERR_c_self_arg_err__print_self_them("| c{Integer}-> m{^} self(%"PRIsVALUE") unable to match exponential(%"PRIsVALUE") |")}
)
/*___________________________________________________________________________________________________________________
___ __ ___
|__ | / \ /\ |
| |___ \__/ /~~\ |
_____________________________________________________________________________________________________________________ */
// | func{one?} |
ⓡ𝑓_def(m_flt_is_one, re_me_eq_to(ℤd1);)
// | func{has_decimals?} |
ⓡ𝑓_def(m_flt_has_decimals, return c_flt_has_decimals(NUM2DBL(self));)
// | func{smells_like_int?} |
ⓡ𝑓_def(m_flt_smells_like_int, return c_flt_smells_like_int(NUM2DBL(self));)
// original source code referenced from:
// @see https://floating-point-gui.de/errors/NearlyEqualsTest.java
//
// | func{≈≈} |
ⓡ𝑓_self_them(m_flt_basically_equal,
if (rb_obj_equal(self, them) || self == them) {re_ye}
else if (!is_int_or_flt(them)) {re_no}
else {
const double val_self = NUM2DBL(self);
const double val_them = NUM2DBL(them);
if (val_self == val_them) {re_ye}
else {
const double diff = fabs(val_self - val_them);
const double summed = fabs(val_self) + fabs(val_them);
if (val_self == 0.0 || val_them == 0.0 || (summed < M_FLT_EPSILON)) {
re_as_bool(diff < (M_FLT_RELATIVE_ERR_RELAXED * M_FLT_EPSILON))
} else {
if (summed <= M_FLT_MAX) {
re_as_bool((diff / summed) < M_FLT_EPSILON)
} else {
re_as_bool((diff / M_FLT_MAX) < M_FLT_RELATIVE_ERR)
}
}
}
}
)
// | func{^} |
ⓡ𝑓_self_them(m_flt_patch_for_exponentials,
if (is_sym(them)) {
const int power_to_raise_to = bsearch_operation(them);
if (power_to_raise_to != -1337) {
const double val_self = NUM2DBL(self);
if (isnan(val_self)) {
raise_err_runtime("| c{Float}-> m{^} self{%"PRIsVALUE"} may not be raised to an exponential power |", self)
}
if (val_self == 0.0 && power_to_raise_to < 0) {
raise_err_zero_division("| c{Float}-> m{^} self{%"PRIsVALUE"} may not be raised to the negative power{%d} |", self, power_to_raise_to)
}
if (power_to_raise_to < 10) {
switch(power_to_raise_to) {
case -9: re_me_func_1args(ID_OF_POW, ℤn9)
case -8: re_me_func_1args(ID_OF_POW, ℤn8)
case -7: re_me_func_1args(ID_OF_POW, ℤn7)
case -6: re_me_func_1args(ID_OF_POW, ℤn6)
case -5: re_me_func_1args(ID_OF_POW, ℤn5)
case -4: re_me_func_1args(ID_OF_POW, ℤn4)
case -3: re_me_func_1args(ID_OF_POW, ℤn3)
case -2: re_me_func_1args(ID_OF_POW, ℤn2)
case -1: re_me_func_1args(ID_OF_POW, ℤn1)
case 0: if (isinf(val_self)) {re_nan} else { re_1 }
case 1: re_me
case 2: re_me_func_1args(ID_OF_POW, ℤ2)
case 3: re_me_func_1args(ID_OF_POW, ℤ3)
case 4: re_me_func_1args(ID_OF_POW, ℤ4)
case 5: re_me_func_1args(ID_OF_POW, ℤ5)
case 6: re_me_func_1args(ID_OF_POW, ℤ6)
case 7: re_me_func_1args(ID_OF_POW, ℤ7)
case 8: re_me_func_1args(ID_OF_POW, ℤ8)
case 9: re_me_func_1args(ID_OF_POW, ℤ9)
default: raise_err_runtime("| c{Float}-> m{^} self(%"PRIsVALUE") unable to match exponential(%"PRIsVALUE") |", self, them)
}
} else {
if (val_self == 1.0 || val_self == -1.0) {
re_nan
} else if (power_to_raise_to == CACHE_INDEX_INF) {
if (isinf(val_self)) {
re_inf_complex
} else if (val_self >= 0.0 && val_self < 1.0) {
re_0
} else if (val_self > 1.0) {
re_inf
} else if (val_self < 0.0 && val_self > -1.0) {
re_0
} else {
re_negative_inf
}
} else if (power_to_raise_to == CACHE_INDEX_INF_NEGATIVE) {
if (val_self == 0.0) {
re_inf_complex
} else if (val_self > 0.0 && val_self < 1.0) {
re_inf
} else if (val_self > 1.0) {
re_0
} else if (val_self < 0.0 && val_self > -1.0) {
re_negative_inf
} else {
re_0
}
} else {
if (val_self == 0.0) {
re_0
} else {
re_nan
}
}
}
} else {ERR_c_self_arg_err__print_self_them("| c{Float}-> m{^} self(%"PRIsVALUE") unable to match exponential(%"PRIsVALUE") |")}
} else {ERR_c_self_arg_err__print_self_them("| c{Float}-> m{^} self(%"PRIsVALUE") unable to match exponential(%"PRIsVALUE") |")}
)
/*___________________________________________________________________________________________________________________
|\ | | |
| \| | |___
_____________________________________________________________________________________________________________________ */
// | function{empty?} |
ⓡ𝑓_const(m_nil_empty, re_ye)
// | function{include?} |
ⓡ𝑓_self_them_returning_const(m_nil_include, re_no)
/*____________________________________________________________________________________________________________________
__ ___ __ __
/__` | |__) | |\ | / _`
.__/ | | \ | | \| \__>
_____________________________________________________________________________________________________________________ */
// | function{>>} |
ⓡ𝑓_self_them(m_str_prepend,
if (is_str(them)) {
if (!(r_str_is_empty(them))) {
r_str_pre_modify(self)
r_str_prepend(self, them)
}
re_me
} else {🛑param_str(">>", them)}
)
/*___________________________________________________________________________________________________________________
__ __
/\ |__) |__) /\ \ /
/~~\ | \ | \ /~~\ |
_____________________________________________________________________________________________________________________ */
// | func{>>} |
ⓡ𝑓_self_them(m_ary_prepend,
r_ary_pre_modify(self)
r_ary_prepend(self, them)
re_me
)
// | func{remove_empty!} |
ⓡ𝑓_def(m_ary_remove_empty,
r_ary_pre_modify(self)
long len_me = r_ary_len(self);
if (len_me == 0){re_me}
long i;
int delete_node = 0;
VALUE v;
for (i = 0; i < len_me;) {
v = r_ary_get(self, i);
if (is_nil(v)) {
r_ary_del(self, i);
--len_me;
} else {
delete_node = 0;
switch(TYPE(v)) {
case RUBY_T_NIL:
delete_node = 1; break;
case RUBY_T_STRING:
if (r_str_is_empty(v)) {delete_node = 1;} ; break;
case RUBY_T_ARRAY:
if (r_ary_is_empty(v)) {delete_node = 1;} ; break;
case RUBY_T_HASH:
if (r_hsh_is_empty(v)) {delete_node = 1;} ; break;
default:
if (is_empty_generic(v)) {
delete_node = 1;
}
break;
}
if (delete_node) {
r_ary_del(self, i);
--len_me;
} else {
++i;
}
}
}
re_me
)
// | func{disjunctive_union} |
ⓡ𝑓_self_them(m_ary_disjunctive_union,
if (is_ary(them)) {
const long len_me = r_ary_len(self);
const long len_them = r_ary_len(them);
if ((len_me == 0 && len_them == 0) || len_them == 0) {
re_me
} else if (len_me == 0) {
return them;
} else {
long i = 0L;
VALUE n;
VALUE output = 💎new_ary(len_me + len_them);
if (len_me >= len_them) {
for (; i < len_them; i++) {
n = r_ary_get(them, i); if(!r_ary_has(self, n)){r_ary_add(output, n)}
n = r_ary_get(self, i); if(!r_ary_has(them, n)){r_ary_add(output, n)}
}
for (; i < len_me; i++) {
n = r_ary_get(self, i); if(!r_ary_has(them, n)){r_ary_add(output, n)}
}
} else {
for (; i < len_me; i++) {
n = r_ary_get(self, i); if(!r_ary_has(them, n)){r_ary_add(output, n)}
n = r_ary_get(them, i); if(!r_ary_has(self, n)){r_ary_add(output, n)}
}
for (; i < len_them; i++) {
n = r_ary_get(them, i); if(!r_ary_has(self, n)){r_ary_add(output, n)}
}
}
return output;
}
} else {ERR_c_self_got_non_ary_param("disjunctive_union", them)}
)
/* __ __
/\ \ __ /\ \__ __
___ ___ ___ ___\ \ \____/\_\ ___ __ \ \ ,_\ ___ _ __ /\_\ ___ ____
/'___\ / __`\ /' __` __`\ \ '__`\/\ \ /' _ `\ /'__`\ \ \ \/ / __`\/\`'__\/\ \ /'___\ /',__\
/\ \__//\ \L\ \/\ \/\ \/\ \ \ \L\ \ \ \/\ \/\ \/\ \L\.\_\ \ \_/\ \L\ \ \ \/ \ \ \/\ \__//\__, `\
\ \____\ \____/\ \_\ \_\ \_\ \_,__/\ \_\ \_\ \_\ \__/.\_\\ \__\ \____/\ \_\ \ \_\ \____\/\____/
\/____/\/___/ \/_/\/_/\/_/\/___/ \/_/\/_/\/_/\/__/\/_/ \/__/\/___/ \/_/ \/_/\/____/\/___/ */
// source solution credit: https://blog.plover.com/math/choose.html
ⓡ𝑓_self_a_b(m_combinatorics_n_choose_k,
if (is_int(param_a) && is_int(param_b)) {
unsigned int n = RB_FIX2UINT(param_a);
unsigned int k = RB_FIX2UINT(param_b);
if (k == 0 || n == k) {
re_1
} else if (k > n) {
rb_raise(R_ERR_ARG, "| m{Combinatorics}-> sf{n_choose_k} got arg(n){%"PRIsVALUE"} w/ value smaller than arg(k){%"PRIsVALUE"} |", param_a, param_b);
} else if (((k - 1) * 2) < n) {
k = n - k;
}
unsigned long r = 1;
unsigned int d;
for (d = 1; d <= k; d++) {
r *= n--;
r /= d;
}
return ULONG2NUM(r);
} else {
rb_raise(R_ERR_ARG, "| m{Combinatorics}-> sf{n_choose_k} did not receive type{Integer} for either arg(n){%"PRIsVALUE"} or arg(k){%"PRIsVALUE"} |", param_a, param_b);
}
)
ⓡ𝑓_self_a_b(m_combinatorics_permutations,
if (is_int(param_a) && is_int(param_b)) {
int n = RB_FIX2INT(param_a);
int k = RB_FIX2INT(param_b);
if (n < 0 || k < 0) {
rb_raise(R_ERR_ARG, "| m{Combinatorics}-> sf{permutations} received a negative Integer for either arg(n){%"PRIsVALUE"} or arg(k){%"PRIsVALUE"} |", param_a, param_b);
} if (k > n) {
rb_raise(R_ERR_ARG, "| m{Combinatorics}-> sf{permutations} received arg(n){%"PRIsVALUE"} w/ a smaller value than arg(k){%"PRIsVALUE"} |", param_a, param_b);
}
unsigned long p = 1;
for (int i = 0; i < k; i++) {
p *= (n - i);
}
return ULONG2NUM(p);
} else {
rb_raise(R_ERR_ARG, "| m{Combinatorics}-> sf{permutations} did not receive type{Integer} for either arg(n){%"PRIsVALUE"} or arg(k){%"PRIsVALUE"} |", param_a, param_b);
}
)
/* __ __ __
/\ \ /\ \__/\ \
___ __ __ ___ ___\ \ \____ __ _ __ \ \ ,_\ \ \___ __ ___ _ __ __ __
/' _ `\/\ \/\ \ /' __` __`\ \ '__`\ /'__`\/\`'__\ \ \ \/\ \ _ `\ /'__`\ / __`\/\`'__\/\ \/\ \
/\ \/\ \ \ \_\ \/\ \/\ \/\ \ \ \L\ \/\ __/\ \ \/ \ \ \_\ \ \ \ \/\ __//\ \L\ \ \ \/ \ \ \_\ \
\ \_\ \_\ \____/\ \_\ \_\ \_\ \_,__/\ \____\\ \_\ \ \__\\ \_\ \_\ \____\ \____/\ \_\ \/`____ \
\/_/\/_/\/___/ \/_/\/_/\/_/\/___/ \/____/ \/_/ \/__/ \/_/\/_/\/____/\/___/ \/_/ `/___/> \
/\___/
\/__/ */
// source solution credit: https://www.geeksforgeeks.org/eulers-totient-function/
ⓡ𝑓_self_them(m_number_theory_eulers_totient_func,
if (is_int(them)) {
unsigned long n = NUM2ULONG(them);
if (n == 0ul) {re_0}
unsigned long result = n;
for (unsigned long p = 2ul; p * p <= n; ++p) {
if (n % p == 0ul) {
while (n % p == 0ul) {
n /= p;
}
result -= result / p;
}
}
if (n > 1ul) {
result -= result / n;
}
return ULONG2NUM(result);
} else {rb_raise(R_ERR_ARG, "");}
)
// source solution credit: https://www.geeksforgeeks.org/check-whether-number-semiprime-not/
ⓡ𝑓_self_them(m_number_theory_is_semiprime,
if (is_fixnum(them)) {
int num = FIX2INT(them);
int num_primes_encountered = 0;
for (int i = 2; num_primes_encountered < 2 && i * i <= num; ++i) {
while (num % i == 0) {
num /= i;
++num_primes_encountered;
}
}
// a remaining value of > 1 will be a prime number
if (num > 1) {
re_as_bool(num_primes_encountered == 1)
} else {
re_as_bool(num_primes_encountered == 2)
}
} else {
rb_raise(R_ERR_ARG, "| m{NumberTheory}-> sf{semiprime?} did not receive type{Fixnum} for either arg(n){%"PRIsVALUE"} but type{%s} |", them, rb_obj_classname(them));
}
)
/* __ __
/\ \__ __ /\ \__
\ \ ,_\ _ __ /\_\ __ ___ ___ ___ ___ ___ __\ \ ,_\ _ __ __ __
\ \ \/ /\`'__\/\ \ /'_ `\ / __`\ /' _ `\ / __`\ /' __` __`\ /'__`\ \ \/ /\`'__\/\ \/\ \
\ \ \_\ \ \/ \ \ \/\ \L\ \/\ \L\ \/\ \/\ \/\ \L\ \/\ \/\ \/\ \/\ __/\ \ \_\ \ \/ \ \ \_\ \
\ \__\\ \_\ \ \_\ \____ \ \____/\ \_\ \_\ \____/\ \_\ \_\ \_\ \____\\ \__\\ \_\ \/`____ \
\/__/ \/_/ \/_/\/___L\ \/___/ \/_/\/_/\/___/ \/_/\/_/\/_/\/____/ \/__/ \/_/ `/___/> \
/\____/ /\___/
\_/__/ \/__/ */
/*____________________________________________________________________________________________________________________
___ ___ ___ __ ___
| |__| |__ | /\ /\ |\ | / _` | |__
| | | |___ | /~~\ /~~\ | \| \__> |___ |___
_____________________________________________________________________________________________________________________ */
static VALUE θ_m_get_size(const VALUE self){re_me_mem_size}
static void θ_set_value(const ptrθ data, const double value) {
if (!(ptrθ_flag_is_constant(data))) { //&& data->angle_value != value
data->angle_value = value;
ptrθ_flag_clr_cache_synced(data);
if (value == 0.0) {
ptrθ_flags_val_is_zero(data);
} else if (value > 0.0) {
const double max_value = vocab_value_perigon(data->angle_mode);
if (value == max_value) {
ptrθ_flags_val_is_perigon(data, FLAG_TRUE);
} else if (value < max_value) {
ptrθ_flags_val_is_below_perigon(data, FLAG_TRUE);
} else {
ptrθ_flags_val_is_beyond_perigon(data, FLAG_TRUE);
}
} else {
const double max_value = vocab_value_perigon_negative(data->angle_mode);
if (value == max_value) {
ptrθ_flags_val_is_perigon(data, FLAG_FALSE);
} else if (value > max_value) {
ptrθ_flags_val_is_below_perigon(data, FLAG_FALSE);
} else {
ptrθ_flags_val_is_beyond_perigon(data, FLAG_FALSE);
}
}
} else {
rb_raise(R_ERR_RUNTIME, "| c{ThetaAngle}-> internal m{set_value} can\'t be called on a constant ThetaAngle |");
}
}
static inline long double θ_get_val_precise_as_mode(const unsigned char angle_mode, const ptrθ them) {
if (angle_mode == them->angle_mode) {
return (long double) them->angle_value;
} else if (them->angle_mode == THETA_MODE_ID_DGR) {
if (angle_mode == THETA_MODE_ID_RAD) {
return θDGRL2LRAD((long double) them->angle_value);
} else if (angle_mode == THETA_MODE_ID_TRN) {
return θDGRL2LTRN((long double) them->angle_value);
} else {
return θDGRL2LGON((long double) them->angle_value);
}
} else if (them->angle_mode == THETA_MODE_ID_RAD) {
if (angle_mode == THETA_MODE_ID_DGR) {
return θRADL2LDGR((long double) them->angle_value);
} else if (angle_mode == THETA_MODE_ID_TRN) {
return θRADL2LTRN((long double) them->angle_value);
} else {
return θRADL2LGON((long double) them->angle_value);
}
} else if (them->angle_mode == THETA_MODE_ID_TRN) {
if (angle_mode == THETA_MODE_ID_DGR) {
return θTRNL2LDGR((long double) them->angle_value);
} else if (angle_mode == THETA_MODE_ID_RAD) {
return θTRNL2LRAD((long double) them->angle_value);
} else {
return θTRNL2LGON((long double) them->angle_value);
}
} else {
if (angle_mode == THETA_MODE_ID_DGR) {
return θGONL2LDGR((long double) them->angle_value);
} else if (angle_mode == THETA_MODE_ID_RAD) {
return θGONL2LRAD((long double) them->angle_value);
} else if (angle_mode == THETA_MODE_ID_TRN) {
return θGONL2LTRN((long double) them->angle_value);