-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpfr.v
3814 lines (2966 loc) · 78.4 KB
/
mpfr.v
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
// MIT License
// Copyright (c) 2021 Vincent Laisney
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
module mpfr
import gmp
import math.mathutil
#flag -lgmp -lmpfr
#flag @VMODROOT/mpfr_v_utils.o
#flag -I @VMODROOT
#include "mpfr.h"
#include "mpfr_v_utils.h"
/* Flags macros (in the public API) */
const (
flags_underflow = 1
flags_overflow = 2
flags_nan = 4
flags_inexact = 8
flags_erange = 16
flags_divby0 = 32
flags_all = (flags_underflow | flags_overflow | flags_nan | flags_inexact | flags_erange | flags_divby0)
)
pub enum Round {
rndn=0 /* round to nearest, with ties to even */
rndz /* round toward zero */
rndu /* round toward +Inf */
rndd /* round toward -Inf */
rnda /* round away from zero */
rndf /* faithful rounding */
rndna=-1 /* round to nearest, with ties away from zero (mpfr_round) */
}
const (
mpfr_prec_min = 1
mpfr_prec_max = i64(((u64 (-1) >> 1) - 256))
/* Definition of the standard exponent limits */
mpfr_emax_default = i64((u64(1) << 30) - 1)
mpfr_emin_default = (-(mpfr_emax_default))
)
/* Definition of the main structure */
struct C.__mpfr_struct {
_mpfr_prec i64
_mpfr_sign int
_mpfr_exp i64
_mpfr_d &u64
}
pub type Bigfloat = C.__mpfr_struct
pub type Mpfr_prec = i64
pub type Mpfr_exp = i64
// typedef __mpfr_struct mpfr_t[1]
// typedef __mpfr_struct *&Bigfloat
// typedef __mpfr_struct *&Bigfloat
/* Stack interface */
// typedef enum {
// MPFR_NAN_KIND = 0,
// MPFR_INF_KIND = 1,
// MPFR_ZERO_KIND = 2,
// MPFR_REGULAR_KIND = 3
// } mpfr_kind_t
fn init() {
gmp.mp_set_memory_functions(gmp.my_malloc, gmp.my_realloc, gmp.my_free)
}
// statics functions from mpfr_v_utils.h
fn C.get_retval () int
fn C.set_retval (int)
pub fn set_retval(r int) {
C.set_retval(r)
}
pub fn get_retval() int {
return C.get_retval()
}
struct MathContext {
prec Mpfr_prec
flags u64
rnd Round
}
[inline]
pub fn get_def_math_ctx() MathContext {
return MathContext {
prec: get_default_prec()
flags: 0
rnd: .rndn
}
}
fn C.mpfr_get_version () &char
pub fn get_version () &char {
return C.mpfr_get_version ()
}
fn C.mpfr_get_patches () &char
pub fn get_patches () &char {
return C.mpfr_get_patches ()
}
fn C.mpfr_buildopt_tls_p () int
pub fn buildopt_tls_p () int {
return C.mpfr_buildopt_tls_p ()
}
fn C.mpfr_buildopt_float128_p () int
pub fn buildopt_float128_p () int {
return C.mpfr_buildopt_float128_p ()
}
fn C.mpfr_buildopt_decimal_p () int
pub fn buildopt_decimal_p () int {
return C.mpfr_buildopt_decimal_p ()
}
fn C.mpfr_buildopt_gmpinternals_p () int
pub fn buildopt_gmpinternals_p () int {
return C.mpfr_buildopt_gmpinternals_p ()
}
fn C.mpfr_buildopt_sharedcache_p () int
pub fn buildopt_sharedcache_p () int {
return C.mpfr_buildopt_sharedcache_p ()
}
fn C.mpfr_buildopt_tune_case () &char
pub fn buildopt_tune_case () &char {
return C.mpfr_buildopt_tune_case ()
}
fn C.mpfr_get_emin () i64
pub fn get_emin () i64 {
return C.mpfr_get_emin ()
}
fn C.mpfr_set_emin (i64) int
pub fn set_emin (e i64) int {
return C.mpfr_set_emin (e)
}
fn C.mpfr_get_emin_min () i64
pub fn get_emin_min () i64 {
return C.mpfr_get_emin_min ()
}
fn C.mpfr_get_emin_max () i64
pub fn get_emin_max () i64 {
return C.mpfr_get_emin_max ()
}
fn C.mpfr_get_emax () i64
pub fn get_emax () i64 {
return C.mpfr_get_emax ()
}
fn C.mpfr_set_emax (i64) int
pub fn set_emax (e i64) int {
return C.mpfr_set_emax (e)
}
fn C.mpfr_get_emax_min () i64
pub fn get_emax_min () i64 {
return C.mpfr_get_emax_min ()
}
fn C.mpfr_get_emax_max () i64
pub fn get_emax_max () i64 {
return C.mpfr_get_emax_max ()
}
fn C.mpfr_set_default_rounding_mode (Round)
pub fn set_default_rounding_mode (rnd Round) {
C.mpfr_set_default_rounding_mode (rnd)
}
fn C.mpfr_get_default_rounding_mode () Round
pub fn get_default_rounding_mode () Round {
return C.mpfr_get_default_rounding_mode ()
}
fn C.mpfr_print_rnd_mode (Round) &char
pub fn print_rnd_mode (rnd Round) &char {
return C.mpfr_print_rnd_mode (rnd)
}
fn C.mpfr_clear_flags ()
pub fn clear_flags () {
C.mpfr_clear_flags ()
}
fn C.mpfr_clear_underflow ()
pub fn clear_underflow () {
C.mpfr_clear_underflow ()
}
fn C.mpfr_clear_overflow ()
pub fn clear_overflow () {
C.mpfr_clear_overflow ()
}
fn C.mpfr_clear_divby0 ()
pub fn clear_divby0 () {
C.mpfr_clear_divby0 ()
}
fn C.mpfr_clear_nanflag ()
pub fn clear_nanflag () {
C.mpfr_clear_nanflag ()
}
fn C.mpfr_clear_inexflag ()
pub fn clear_inexflag () {
C.mpfr_clear_inexflag ()
}
fn C.mpfr_clear_erangeflag ()
pub fn clear_erangeflag () {
C.mpfr_clear_erangeflag ()
}
fn C.mpfr_set_underflow ()
pub fn set_underflow () {
C.mpfr_set_underflow ()
}
fn C.mpfr_set_overflow ()
pub fn set_overflow () {
C.mpfr_set_overflow ()
}
fn C.mpfr_set_divby0 ()
pub fn set_divby0 () {
C.mpfr_set_divby0 ()
}
fn C.mpfr_set_nanflag ()
pub fn set_nanflag () {
C.mpfr_set_nanflag ()
}
fn C.mpfr_set_inexflag ()
pub fn set_inexflag () {
C.mpfr_set_inexflag ()
}
fn C.mpfr_set_erangeflag ()
pub fn set_erangeflag () {
C.mpfr_set_erangeflag ()
}
fn C.mpfr_underflow_p () int
pub fn underflow_p () bool {
return C.mpfr_underflow_p () != 0
}
fn C.mpfr_overflow_p () int
pub fn overflow_p () bool {
return C.mpfr_overflow_p () != 0
}
fn C.mpfr_divby0_p () int
pub fn divby0_p () bool {
return C.mpfr_divby0_p () != 0
}
fn C.mpfr_nanflag_p () int
pub fn nanflag_p () bool {
return C.mpfr_nanflag_p () != 0
}
fn C.mpfr_inexflag_p () int
pub fn inexflag_p () bool {
return C.mpfr_inexflag_p () != 0
}
fn C.mpfr_erangeflag_p () int
pub fn erangeflag_p () bool {
return C.mpfr_erangeflag_p () != 0
}
fn C.mpfr_flags_clear (u32)
pub fn flags_clear (f u32) {
C.mpfr_flags_clear (f)
}
fn C.mpfr_flags_set (u32)
pub fn flags_set (f u32) {
C.mpfr_flags_set (f)
}
fn C.mpfr_flags_test (u32) u32
pub fn flags_test (f u32) u32 {
return C.mpfr_flags_test (f)
}
fn C.mpfr_flags_save () u32
pub fn flags_save () u32 {
return C.mpfr_flags_save ()
}
fn C.mpfr_flags_restore (u32,u32)
pub fn flags_restore (f u32, g u32) {
C.mpfr_flags_restore (f, g)
}
fn C.mpfr_check_range (&Bigfloat, int, Round) int
pub fn check_range (mut a Bigfloat, b int, r Round) int {
return C.mpfr_check_range (&a, b, r)
}
fn C.mpfr_init2 (&Bigfloat, Mpfr_prec)
pub fn init2 (mut a Bigfloat, p Mpfr_prec) {
C.mpfr_init2 (&a, p)
}
fn C.mpfr_init (&Bigfloat)
pub fn mpfr_init (mut a Bigfloat) {
C.mpfr_init (&a)
}
pub fn new() Bigfloat {
a := Bigfloat{ _mpfr_d: 0 }
ctx := get_def_math_ctx()
C.mpfr_init2 (&a, ctx.prec)
return a
}
fn C.mpfr_clear (&Bigfloat)
pub fn clear (mut a Bigfloat) {
C.mpfr_clear (&a)
}
// C.mpfr_inits2 (Mpfr_prec, &Bigfloat, ...) __MPFR_SENTINEL_ATTR
// C.mpfr_inits (&Bigfloat, ...) __MPFR_SENTINEL_ATTR
// C.mpfr_clears (&Bigfloat, ...) __MPFR_SENTINEL_ATTR
fn C.mpfr_prec_round (&Bigfloat, Mpfr_prec, Round) int
pub fn prec_round (p Mpfr_prec) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_prec_round (&a, p, ctx.rnd)
set_retval(retval)
return a
}
pub fn prec_round_ctx (p Mpfr_prec, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_prec_round (&a, p, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_can_round (&Bigfloat, i64, Round, Round, Mpfr_prec) int
pub fn can_round (a Bigfloat, err i64, r1 Round, r2 Round, p Mpfr_prec) int {
return C.mpfr_can_round (&a, err, r1, r2, p)
}
fn C.mpfr_min_prec (&Bigfloat) Mpfr_prec
pub fn min_prec (a Bigfloat) Mpfr_prec {
return C.mpfr_min_prec (&a)
}
fn C.mpfr_get_exp (&Bigfloat) Mpfr_exp
pub fn get_exp (a Bigfloat) Mpfr_exp {
return C.mpfr_get_exp (&a)
}
fn C.mpfr_set_exp (&Bigfloat, i64) int
pub fn set_exp (mut a Bigfloat, e i64) int {
return C.mpfr_set_exp (&a, e)
}
fn C.mpfr_get_prec (&Bigfloat) i64
pub fn get_prec (a Bigfloat) i64 {
return C.mpfr_get_prec (&a)
}
fn C.mpfr_set_prec (&Bigfloat, Mpfr_prec)
pub fn set_prec (mut a Bigfloat, p Mpfr_prec) {
C.mpfr_set_prec (&a, p)
}
fn C.mpfr_set_prec_raw (&Bigfloat, Mpfr_prec)
pub fn set_prec_raw (mut a Bigfloat, p Mpfr_prec) {
C.mpfr_set_prec_raw (&a, p)
}
fn C.mpfr_set_default_prec (Mpfr_prec)
pub fn set_default_prec (p Mpfr_prec) {
C.mpfr_set_default_prec (p)
}
fn C.mpfr_get_default_prec () i64
pub fn get_default_prec () i64 {
return C.mpfr_get_default_prec ()
}
fn C.mpfr_set_d (&Bigfloat, f64, Round) int
pub fn from_f64 (d f64) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_set_d (&a, d, ctx.rnd)
set_retval(retval)
return a
}
pub fn from_f64_ctx (d f64, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_set_d (&a, d, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_set_flt (&Bigfloat, f32, Round) int
pub fn from_f32 (f f32) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_set_flt (&a, f, ctx.rnd)
set_retval(retval)
return a
}
pub fn from_f32_ctx (f f32, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_set_flt (&a, f, ctx.rnd)
set_retval(retval)
return a
}
// #ifdef MPFR_WANT_DECIMAL_FLOATS
// // /* _Decimal64 is not defined in C++,
// // cf https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51364 */
// fn C.mpfr_set_decimal64 (&Bigfloat, _Decimal64, Round) int
// pub fn set_decimal64 (&Bigfloat, _Decimal64, Round) int {
// return C.mpfr_set_decimal64 (&Bigfloat, _Decimal64, Round)
// }
// fn C.mpfr_set_decimal128 (&Bigfloat, _Decimal128, Round) int
// pub fn set_decimal128 (&Bigfloat, _Decimal128, Round) int {
// return C.mpfr_set_decimal128 (&Bigfloat, _Decimal128, Round)
// }
// #endif
// fn C.mpfr_set_ld (&Bigfloat, f80, Round) int
// pub fn set_ld (mut a Bigfloat, f80, Round) int {
// return C.mpfr_set_ld (&Bigfloat, f80, Round)
// }
// #ifdef MPFR_WANT_FLOAT128
// fn C.mpfr_set_float128 (&Bigfloat, f128, Round) int
// f128 C.mpfr_get_float128 (&Bigfloat, Round)
// #endif
fn C.mpfr_set_z (&Bigfloat, &gmp.Bigint, Round) int
pub fn set_z (b gmp.Bigint) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_set_z (&a, &b, ctx.rnd)
set_retval(retval)
return a
}
pub fn set_z_ctx (b gmp.Bigint, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_set_z (&a, &b, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_set_z_2exp (&Bigfloat, &gmp.Bigint, i64, Round) int
pub fn set_z_2exp (b gmp.Bigint, e i64) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_set_z_2exp (&a, &b, e, ctx.rnd)
set_retval(retval)
return a
}
pub fn set_z_2exp_ctx (b gmp.Bigint, e i64, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_set_z_2exp (&a, &b, e, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_set_nan (&Bigfloat)
pub fn set_nan (mut a Bigfloat) {
C.mpfr_set_nan (&a)
}
fn C.mpfr_set_inf (&Bigfloat, int)
pub fn set_inf (mut a Bigfloat, neg bool) {
C.mpfr_set_inf (&a, int(neg))
}
fn C.mpfr_set_zero (&Bigfloat, int)
pub fn set_zero (mut a &Bigfloat, neg bool) {
C.mpfr_set_zero (&a, int(neg))
}
// #ifndef MPFR_USE_MINI_GMP
/* mini-gmp does not provide mpf_t, we disable the following functions */
fn C.mpfr_set_f (&Bigfloat, &gmp.Bigfloat, Round) int
pub fn set_f (b gmp.Bigfloat) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_set_f (&a, &b, ctx.rnd)
set_retval(retval)
return a
}
pub fn set_f_ctx (b gmp.Bigfloat, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_set_f (&a, &b, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_cmp_f (&Bigfloat, &gmp.Bigfloat) int
pub fn cmp_f (a Bigfloat, b gmp.Bigfloat) int {
return C.mpfr_cmp_f (&a, &b)
}
fn C.mpfr_get_f (&gmp.Bigfloat, &Bigfloat, Round) int
pub fn get_f (mut a gmp.Bigfloat, b Bigfloat, r Round) int {
return C.mpfr_get_f (&a, &b, r)
}
pub fn get_f_ctx (mut a gmp.Bigfloat, b Bigfloat, r Round, ctx MathContext) int {
return C.mpfr_get_f (&a, &b, r)
}
// #endif
fn C.mpfr_set_si (&Bigfloat, i64, Round) int
pub fn from_i64 (i i64) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_set_si (&a, i, ctx.rnd)
set_retval(retval)
return a
}
pub fn from_i64_ctx (i i64, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_set_si (&a, i, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_set_ui (&Bigfloat, u64, Round) int
pub fn from_u64 (u u64) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_set_ui (&a, u, ctx.rnd)
set_retval(retval)
return a
}
pub fn from_u64_ctx (u u64, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_set_ui (&a, u, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_set_si_2exp (&Bigfloat, i64, i64, Round) int
pub fn set_i64_2exp (i i64, e i64) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_set_si_2exp (&a, i, e, ctx.rnd)
set_retval(retval)
return a
}
pub fn set_i64_2exp_ctx (i i64, e i64, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_set_si_2exp (&a, i, e, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_set_ui_2exp (&Bigfloat, u64, i64, Round) int
pub fn set_u64_2exp (u u64, e i64) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_set_ui_2exp (&a, u, e, ctx.rnd)
set_retval(retval)
return a
}
pub fn set_u64_2exp_ctx (u u64, e i64, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_set_ui_2exp (&a, u, e, ctx.rnd)
set_retval(retval)
return a
}
// #ifndef MPFR_USE_MINI_GMP
/* mini-gmp does not provide mpq_t, we disable the following functions */
fn C.mpfr_set_q (&Bigfloat, &gmp.Bigrational, Round) int
pub fn set_q (b gmp.Bigrational) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_set_q (&a, &b, ctx.rnd)
set_retval(retval)
return a
}
pub fn set_q_ctx (b gmp.Bigrational, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_set_q (&a, &b, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_mul_q (&Bigfloat, &Bigfloat, &gmp.Bigrational, Round) int
pub fn mul_q (b Bigfloat, c gmp.Bigrational) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_mul_q (&a, &b, &c, ctx.rnd)
set_retval(retval)
return a
}
pub fn mul_q_ctx (b Bigfloat, c gmp.Bigrational, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_mul_q (&a, &b, &c, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_div_q (&Bigfloat, &Bigfloat, &gmp.Bigrational, Round) int
pub fn div_q (b Bigfloat, c gmp.Bigrational) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_div_q (&a, &b, &c, ctx.rnd)
set_retval(retval)
return a
}
pub fn div_q_ctx (b Bigfloat, c gmp.Bigrational, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_div_q (&a, &b, &c, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_add_q (&Bigfloat, &Bigfloat, &gmp.Bigrational, Round) int
pub fn add_q (b Bigfloat, c gmp.Bigrational) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_add_q (&a, &b, &c, ctx.rnd)
set_retval(retval)
return a
}
pub fn add_q_ctx (b Bigfloat, c gmp.Bigrational, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_add_q (&a, &b, &c, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_sub_q (&Bigfloat, &Bigfloat, &gmp.Bigrational, Round) int
pub fn sub_q (b Bigfloat, c gmp.Bigrational) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_sub_q (&a, &b, &c, ctx.rnd)
set_retval(retval)
return a
}
pub fn sub_q_ctx (b Bigfloat, c gmp.Bigrational, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_sub_q (&a, &b, &c, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_cmp_q (&Bigfloat, &gmp.Bigrational) int
pub fn cmp_q (a Bigfloat, b gmp.Bigrational) int {
return C.mpfr_cmp_q (&a, &b)
}
fn C.mpfr_get_q (&gmp.Bigrational, &Bigfloat)
pub fn get_q (a gmp.Bigrational, b Bigfloat) {
C.mpfr_get_q (&a, &b)
}
// #endif
fn C.mpfr_set_str (&Bigfloat, &char, int, Round) int
pub fn set_str (s &char, b int) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_set_str (&a, s, b, ctx.rnd)
set_retval(retval)
return a
}
pub fn set_str_ctx (s &char, b int, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_set_str (&a, s, b, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_init_set_str (&Bigfloat, &char, int, Round) int
pub fn from_str (s string) ?Bigfloat {
a := Bigfloat{ _mpfr_d: 0 }
ctx := get_def_print_ctx()
retval := C.mpfr_init_set_str (&a, s.str, ctx.base, ctx.rnd)
set_retval(retval)
if retval != 0 {
return error('Invalid string')
}
return a
}
fn C.mpfr_set4 (&Bigfloat, &Bigfloat, Round, int) int
pub fn set4 (b Bigfloat, f int) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_set4 (&a, &b, ctx.rnd, f)
set_retval(retval)
return a
}
pub fn set4_ctx (b Bigfloat, f int, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_set4 (&a, &b, ctx.rnd, f)
set_retval(retval)
return a
}
fn C.mpfr_abs (&Bigfloat, &Bigfloat, Round) int
pub fn abs (b Bigfloat) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_abs (&a, &b, ctx.rnd)
set_retval(retval)
return a
}
pub fn abs_ctx (b Bigfloat, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_abs (&a, &b, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_set (&Bigfloat, &Bigfloat, Round) int
pub fn set (b Bigfloat) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_set (&a, &b, ctx.rnd)
set_retval(retval)
return a
}
pub fn set_ctx (b Bigfloat, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_set (&a, &b, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_neg (&Bigfloat, &Bigfloat, Round) int
pub fn neg (b Bigfloat) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_neg (&a, &b, ctx.rnd)
set_retval(retval)
return a
}
pub fn neg_ctx (b Bigfloat, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_neg (&a, &b, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_signbit (&Bigfloat) int
pub fn signbit (a Bigfloat) int {
return C.mpfr_signbit (&a)
}
fn C.mpfr_setsign (&Bigfloat, &Bigfloat, int, Round) int
pub fn setsign (b Bigfloat, i int) Bigfloat {
a := new()
ctx := get_def_math_ctx()
retval := C.mpfr_setsign (&a, &b, i, ctx.rnd)
set_retval(retval)
return a
}
pub fn setsign_ctx (b Bigfloat, i int, ctx MathContext) Bigfloat {
a := new()
retval := C.mpfr_setsign (&a, &b, i, ctx.rnd)
set_retval(retval)
return a
}
fn C.mpfr_copysign (&Bigfloat, &Bigfloat, &Bigfloat, Round) int
pub fn copysign (mut a Bigfloat, b Bigfloat, c Bigfloat, r Round) int {
return C.mpfr_copysign (&a, &b, &c, r)
}
fn C.mpfr_get_z_2exp (&gmp.Bigint, &Bigfloat) i64
pub fn get_z_2exp (a gmp.Bigint, s Bigfloat) i64 {
return C.mpfr_get_z_2exp (&a, &s)
}
fn C.mpfr_get_flt (&Bigfloat, Round) f32
pub fn (a Bigfloat) f32 () f32 {
ctx := get_def_math_ctx()
return C.mpfr_get_flt (&a, ctx.rnd)
}
pub fn (a Bigfloat) f32_ctx (ctx MathContext) f32 {
return C.mpfr_get_flt (&a, ctx.rnd)
}
fn C.mpfr_get_d (&Bigfloat, Round) f64
pub fn (a Bigfloat) f64 () f64 {
ctx := get_def_math_ctx()
return C.mpfr_get_d (&a, ctx.rnd)
}
pub fn (a Bigfloat) f64_ctx (ctx MathContext) f64 {
return C.mpfr_get_d (&a, ctx.rnd)
}
// #ifdef MPFR_WANT_DECIMAL_FLOATS
// _Decimal64 C.mpfr_get_decimal64 (&Bigfloat, Round)
// _Decimal128 C.mpfr_get_decimal128 (&Bigfloat, Round)
// #endif
// fn C.mpfr_get_ld (&Bigfloat, Round) f80
// pub fn get_ld (a Bigfloat, r Round) f80 {
// return C.mpfr_get_ld (&a, r)
// }
fn C.mpfr_get_d1 (&Bigfloat) f64
pub fn get_d1 (a Bigfloat) f64 {
return C.mpfr_get_d1 (&a)
}
pub fn get_d1_ctx (a Bigfloat, ctx MathContext) f64 {
return C.mpfr_get_d1 (&a)
}
fn C.mpfr_get_d_2exp (&i64, &Bigfloat, Round) f64
pub fn get_f64_2exp (e &i64, s Bigfloat, r Round) f64 {
return C.mpfr_get_d_2exp (e, &s, r)
}
pub fn get_f64_2exp_ctx (e &i64, s Bigfloat, r Round, ctx MathContext) f64 {
return C.mpfr_get_d_2exp (e, &s, r)