Change copyright header of mpfr module
[gnome.seed] / modules / mpfr / seed-mpfr-trig.c
1 /* -*- mode: C; indent-tabs-mode: t; tab-width: 8; c-basic-offset: 2; -*- */
2
3 /*
4  * This file is part of Seed, the GObject Introspection<->Javascript bindings.
5  *
6  * Seed is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as
8  * published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  * Seed is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with Seed.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  * Copyright (C) Matthew Arsenault 2009-2010 <arsenm2@rpi.edu>
18  */
19
20 #include <mpfr.h>
21
22 #include "seed-mpfr.h"
23
24 SeedValue seed_mpfr_sin (SeedContext ctx,
25                          SeedObject function,
26                          SeedObject this_object,
27                          gsize argument_count,
28                          const SeedValue args[],
29                          SeedException * exception)
30 {
31     mpfr_rnd_t rnd;
32     mpfr_ptr rop, op;
33     gint ret;
34
35     CHECK_ARG_COUNT("mpfr.sin", 2);
36
37     rop = seed_object_get_private(this_object);
38     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
39
40     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
41     {
42         op = seed_object_get_private(args[0]);
43     }
44     else
45     {
46         TYPE_EXCEPTION("mpfr.sin", "mpfr_t");
47     }
48
49     ret = mpfr_sin(rop, op, rnd);
50
51     return seed_value_from_int(ctx, ret, exception);
52 }
53
54 SeedValue seed_mpfr_cos (SeedContext ctx,
55                          SeedObject function,
56                          SeedObject this_object,
57                          gsize argument_count,
58                          const SeedValue args[],
59                          SeedException * exception)
60 {
61     mpfr_rnd_t rnd;
62     mpfr_ptr rop, op;
63     gint ret;
64
65     CHECK_ARG_COUNT("mpfr.cos", 2);
66
67     rop = seed_object_get_private(this_object);
68     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
69
70     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
71     {
72         op = seed_object_get_private(args[0]);
73     }
74     else
75     {
76         TYPE_EXCEPTION("mpfr.cos", "mpfr_t");
77     }
78
79     ret = mpfr_cos(rop, op, rnd);
80
81     return seed_value_from_int(ctx, ret, exception);
82 }
83
84 SeedValue seed_mpfr_tan (SeedContext ctx,
85                          SeedObject function,
86                          SeedObject this_object,
87                          gsize argument_count,
88                          const SeedValue args[],
89                          SeedException * exception)
90 {
91     mpfr_rnd_t rnd;
92     mpfr_ptr rop, op;
93     gint ret;
94
95     CHECK_ARG_COUNT("mpfr.tan", 2);
96
97     rop = seed_object_get_private(this_object);
98     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
99
100     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
101     {
102         op = seed_object_get_private(args[0]);
103     }
104     else
105     {
106         TYPE_EXCEPTION("mpfr.tan", "mpfr_t");
107     }
108
109     ret = mpfr_tan(rop, op, rnd);
110
111     return seed_value_from_int(ctx, ret, exception);
112 }
113
114 SeedValue seed_mpfr_csc (SeedContext ctx,
115                          SeedObject function,
116                          SeedObject this_object,
117                          gsize argument_count,
118                          const SeedValue args[],
119                          SeedException * exception)
120 {
121     mpfr_rnd_t rnd;
122     mpfr_ptr rop, op;
123     gint ret;
124
125     CHECK_ARG_COUNT("mpfr.csc", 2);
126
127     rop = seed_object_get_private(this_object);
128     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
129
130     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
131     {
132         op = seed_object_get_private(args[0]);
133     }
134     else
135     {
136         TYPE_EXCEPTION("mpfr.csc", "mpfr_t");
137     }
138
139     ret = mpfr_csc(rop, op, rnd);
140
141     return seed_value_from_int(ctx, ret, exception);
142 }
143
144 SeedValue seed_mpfr_sec (SeedContext ctx,
145                          SeedObject function,
146                          SeedObject this_object,
147                          gsize argument_count,
148                          const SeedValue args[],
149                          SeedException * exception)
150 {
151     mpfr_rnd_t rnd;
152     mpfr_ptr rop, op;
153     gint ret;
154
155     CHECK_ARG_COUNT("mpfr.sec", 2);
156
157     rop = seed_object_get_private(this_object);
158     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
159
160     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
161     {
162         op = seed_object_get_private(args[0]);
163     }
164     else
165     {
166         TYPE_EXCEPTION("mpfr.sec", "mpfr_t");
167     }
168
169     ret = mpfr_sec(rop, op, rnd);
170
171     return seed_value_from_int(ctx, ret, exception);
172 }
173
174 SeedValue seed_mpfr_cot (SeedContext ctx,
175                          SeedObject function,
176                          SeedObject this_object,
177                          gsize argument_count,
178                          const SeedValue args[],
179                          SeedException * exception)
180 {
181     mpfr_rnd_t rnd;
182     mpfr_ptr rop, op;
183     gint ret;
184
185     CHECK_ARG_COUNT("mpfr.cot", 2);
186
187     rop = seed_object_get_private(this_object);
188     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
189
190     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
191     {
192         op = seed_object_get_private(args[0]);
193     }
194     else
195     {
196         TYPE_EXCEPTION("mpfr.cot", "mpfr_t");
197     }
198
199     ret = mpfr_cot(rop, op, rnd);
200
201     return seed_value_from_int(ctx, ret, exception);
202 }
203
204 SeedValue seed_mpfr_asin (SeedContext ctx,
205                           SeedObject function,
206                           SeedObject this_object,
207                           gsize argument_count,
208                           const SeedValue args[],
209                           SeedException * exception)
210 {
211     mpfr_rnd_t rnd;
212     mpfr_ptr rop, op;
213     gint ret;
214
215     CHECK_ARG_COUNT("mpfr.asin", 2);
216
217     rop = seed_object_get_private(this_object);
218     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
219
220     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
221     {
222         op = seed_object_get_private(args[0]);
223     }
224     else
225     {
226         TYPE_EXCEPTION("mpfr.asin", "mpfr_t");
227     }
228
229     ret = mpfr_asin(rop, op, rnd);
230
231     return seed_value_from_int(ctx, ret, exception);
232 }
233
234
235 SeedValue seed_mpfr_acos (SeedContext ctx,
236                           SeedObject function,
237                           SeedObject this_object,
238                           gsize argument_count,
239                           const SeedValue args[],
240                           SeedException * exception)
241 {
242     mpfr_rnd_t rnd;
243     mpfr_ptr rop, op;
244     gint ret;
245
246     CHECK_ARG_COUNT("mpfr.acos", 2);
247
248     rop = seed_object_get_private(this_object);
249     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
250
251     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
252     {
253         op = seed_object_get_private(args[0]);
254     }
255     else
256     {
257         TYPE_EXCEPTION("mpfr.acos", "mpfr_t");
258     }
259
260     ret = mpfr_acos(rop, op, rnd);
261
262     return seed_value_from_int(ctx, ret, exception);
263 }
264
265 SeedValue seed_mpfr_atan (SeedContext ctx,
266                           SeedObject function,
267                           SeedObject this_object,
268                           gsize argument_count,
269                           const SeedValue args[],
270                           SeedException * exception)
271 {
272     mpfr_rnd_t rnd;
273     mpfr_ptr rop, op;
274     gint ret;
275
276     CHECK_ARG_COUNT("mpfr.atan", 2);
277
278     rop = seed_object_get_private(this_object);
279     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
280
281     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
282     {
283         op = seed_object_get_private(args[0]);
284     }
285     else
286     {
287         TYPE_EXCEPTION("mpfr.atan", "mpfr_t");
288     }
289
290     ret = mpfr_atan(rop, op, rnd);
291
292     return seed_value_from_int(ctx, ret, exception);
293 }
294
295
296 /* log functions */
297
298 SeedValue seed_mpfr_log (SeedContext ctx,
299                          SeedObject function,
300                          SeedObject this_object,
301                          gsize argument_count,
302                          const SeedValue args[],
303                          SeedException * exception)
304 {
305     mpfr_rnd_t rnd;
306     mpfr_ptr rop, op;
307     gint ret;
308
309     CHECK_ARG_COUNT("mpfr.log", 2);
310
311     rop = seed_object_get_private(this_object);
312     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
313
314     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
315     {
316         op = seed_object_get_private(args[0]);
317     }
318     else
319     {
320         TYPE_EXCEPTION("mpfr.log", "mpfr_t");
321     }
322
323     ret = mpfr_log(rop, op, rnd);
324
325     return seed_value_from_int(ctx, ret, exception);
326 }
327
328 SeedValue seed_mpfr_log2 (SeedContext ctx,
329                           SeedObject function,
330                           SeedObject this_object,
331                           gsize argument_count,
332                           const SeedValue args[],
333                           SeedException * exception)
334 {
335     mpfr_rnd_t rnd;
336     mpfr_ptr rop, op;
337     gint ret;
338
339     CHECK_ARG_COUNT("mpfr.log2", 2);
340
341     rop = seed_object_get_private(this_object);
342     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
343
344     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
345     {
346         op = seed_object_get_private(args[0]);
347     }
348     else
349     {
350         TYPE_EXCEPTION("mpfr.log2", "mpfr_t");
351     }
352
353     ret = mpfr_log2(rop, op, rnd);
354
355     return seed_value_from_int(ctx, ret, exception);
356 }
357
358 SeedValue seed_mpfr_log10 (SeedContext ctx,
359                            SeedObject function,
360                            SeedObject this_object,
361                            gsize argument_count,
362                            const SeedValue args[],
363                            SeedException * exception)
364 {
365     mpfr_rnd_t rnd;
366     mpfr_ptr rop, op;
367     gint ret;
368
369     CHECK_ARG_COUNT("mpfr.log10", 2);
370
371     rop = seed_object_get_private(this_object);
372     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
373
374     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
375     {
376         op = seed_object_get_private(args[0]);
377     }
378     else
379     {
380         TYPE_EXCEPTION("mpfr.log10", "mpfr_t");
381     }
382
383     ret = mpfr_log10(rop, op, rnd);
384
385     return seed_value_from_int(ctx, ret, exception);
386 }
387
388 /* hyperbolic trig functions */
389
390 SeedValue seed_mpfr_sinh (SeedContext ctx,
391                           SeedObject function,
392                           SeedObject this_object,
393                           gsize argument_count,
394                           const SeedValue args[],
395                           SeedException * exception)
396 {
397     mpfr_rnd_t rnd;
398     mpfr_ptr rop, op;
399     gint ret;
400
401     CHECK_ARG_COUNT("mpfr.sinh", 2);
402
403     rop = seed_object_get_private(this_object);
404     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
405
406     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
407     {
408         op = seed_object_get_private(args[0]);
409     }
410     else
411     {
412         TYPE_EXCEPTION("mpfr.sinh", "mpfr_t");
413     }
414
415     ret = mpfr_sinh(rop, op, rnd);
416
417     return seed_value_from_int(ctx, ret, exception);
418 }
419
420 SeedValue seed_mpfr_cosh (SeedContext ctx,
421                           SeedObject function,
422                           SeedObject this_object,
423                           gsize argument_count,
424                           const SeedValue args[],
425                           SeedException * exception)
426 {
427     mpfr_rnd_t rnd;
428     mpfr_ptr rop, op;
429     gint ret;
430
431     CHECK_ARG_COUNT("mpfr.cosh", 2);
432
433     rop = seed_object_get_private(this_object);
434     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
435
436     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
437     {
438         op = seed_object_get_private(args[0]);
439     }
440     else
441     {
442         TYPE_EXCEPTION("mpfr.cosh", "mpfr_t");
443     }
444
445     ret = mpfr_cosh(rop, op, rnd);
446
447     return seed_value_from_int(ctx, ret, exception);
448 }
449
450 SeedValue seed_mpfr_tanh (SeedContext ctx,
451                           SeedObject function,
452                           SeedObject this_object,
453                           gsize argument_count,
454                           const SeedValue args[],
455                           SeedException * exception)
456 {
457     mpfr_rnd_t rnd;
458     mpfr_ptr rop, op;
459     gint ret;
460
461     CHECK_ARG_COUNT("mpfr.tanh", 2);
462
463     rop = seed_object_get_private(this_object);
464     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
465
466     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
467     {
468         op = seed_object_get_private(args[0]);
469     }
470     else
471     {
472         TYPE_EXCEPTION("mpfr.tanh", "mpfr_t");
473     }
474
475     ret = mpfr_tanh(rop, op, rnd);
476
477     return seed_value_from_int(ctx, ret, exception);
478 }
479
480
481 SeedValue seed_mpfr_sech (SeedContext ctx,
482                           SeedObject function,
483                           SeedObject this_object,
484                           gsize argument_count,
485                           const SeedValue args[],
486                           SeedException * exception)
487 {
488     mpfr_rnd_t rnd;
489     mpfr_ptr rop, op;
490     gint ret;
491
492     CHECK_ARG_COUNT("mpfr.sech", 2);
493
494     rop = seed_object_get_private(this_object);
495     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
496
497     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
498     {
499         op = seed_object_get_private(args[0]);
500     }
501     else
502     {
503         TYPE_EXCEPTION("mpfr.sech", "mpfr_t");
504     }
505
506     ret = mpfr_sech(rop, op, rnd);
507
508     return seed_value_from_int(ctx, ret, exception);
509 }
510
511 SeedValue seed_mpfr_csch (SeedContext ctx,
512                           SeedObject function,
513                           SeedObject this_object,
514                           gsize argument_count,
515                           const SeedValue args[],
516                           SeedException * exception)
517 {
518     mpfr_rnd_t rnd;
519     mpfr_ptr rop, op;
520     gint ret;
521
522     CHECK_ARG_COUNT("mpfr.csch", 2);
523
524     rop = seed_object_get_private(this_object);
525     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
526
527     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
528     {
529         op = seed_object_get_private(args[0]);
530     }
531     else
532     {
533         TYPE_EXCEPTION("mpfr.csch", "mpfr_t");
534     }
535
536     ret = mpfr_csch(rop, op, rnd);
537
538     return seed_value_from_int(ctx, ret, exception);
539 }
540
541 SeedValue seed_mpfr_coth (SeedContext ctx,
542                           SeedObject function,
543                           SeedObject this_object,
544                           gsize argument_count,
545                           const SeedValue args[],
546                           SeedException * exception)
547 {
548     mpfr_rnd_t rnd;
549     mpfr_ptr rop, op;
550     gint ret;
551
552     CHECK_ARG_COUNT("mpfr.coth", 2);
553
554     rop = seed_object_get_private(this_object);
555     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
556
557     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
558     {
559         op = seed_object_get_private(args[0]);
560     }
561     else
562     {
563         TYPE_EXCEPTION("mpfr.coth", "mpfr_t");
564     }
565
566     ret = mpfr_coth(rop, op, rnd);
567
568     return seed_value_from_int(ctx, ret, exception);
569 }
570
571 /* inverse hyperbolic trig */
572
573 SeedValue seed_mpfr_asinh (SeedContext ctx,
574                            SeedObject function,
575                            SeedObject this_object,
576                            gsize argument_count,
577                            const SeedValue args[],
578                            SeedException * exception)
579 {
580     mpfr_rnd_t rnd;
581     mpfr_ptr rop, op;
582     gint ret;
583
584     CHECK_ARG_COUNT("mpfr.asinh", 2);
585
586     rop = seed_object_get_private(this_object);
587     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
588
589     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
590     {
591         op = seed_object_get_private(args[0]);
592     }
593     else
594     {
595         TYPE_EXCEPTION("mpfr.asinh", "mpfr_t");
596     }
597
598     ret = mpfr_asinh(rop, op, rnd);
599
600     return seed_value_from_int(ctx, ret, exception);
601 }
602
603 SeedValue seed_mpfr_acosh (SeedContext ctx,
604                            SeedObject function,
605                            SeedObject this_object,
606                            gsize argument_count,
607                            const SeedValue args[],
608                            SeedException * exception)
609 {
610     mpfr_rnd_t rnd;
611     mpfr_ptr rop, op;
612     gint ret;
613
614     CHECK_ARG_COUNT("mpfr.acosh", 2);
615
616     rop = seed_object_get_private(this_object);
617     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
618
619     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
620     {
621         op = seed_object_get_private(args[0]);
622     }
623     else
624     {
625         TYPE_EXCEPTION("mpfr.acosh", "mpfr_t");
626     }
627
628     ret = mpfr_acosh(rop, op, rnd);
629
630     return seed_value_from_int(ctx, ret, exception);
631 }
632
633 SeedValue seed_mpfr_atanh (SeedContext ctx,
634                            SeedObject function,
635                            SeedObject this_object,
636                            gsize argument_count,
637                            const SeedValue args[],
638                            SeedException * exception)
639 {
640     mpfr_rnd_t rnd;
641     mpfr_ptr rop, op;
642     gint ret;
643
644     CHECK_ARG_COUNT("mpfr.atanh", 2);
645
646     rop = seed_object_get_private(this_object);
647     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
648
649     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
650     {
651         op = seed_object_get_private(args[0]);
652     }
653     else
654     {
655         TYPE_EXCEPTION("mpfr.atanh", "mpfr_t");
656     }
657
658     ret = mpfr_atanh(rop, op, rnd);
659
660     return seed_value_from_int(ctx, ret, exception);
661 }
662
663 SeedValue seed_mpfr_log1p (SeedContext ctx,
664                            SeedObject function,
665                            SeedObject this_object,
666                            gsize argument_count,
667                            const SeedValue args[],
668                            SeedException * exception)
669 {
670     mpfr_rnd_t rnd;
671     mpfr_ptr rop, op;
672     gint ret;
673
674     CHECK_ARG_COUNT("mpfr.log1p", 2);
675
676     rop = seed_object_get_private(this_object);
677     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
678
679     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
680     {
681         op = seed_object_get_private(args[0]);
682     }
683     else
684     {
685         TYPE_EXCEPTION("mpfr.log1p", "mpfr_t");
686     }
687
688     ret = mpfr_log1p(rop, op, rnd);
689
690     return seed_value_from_int(ctx, ret, exception);
691 }
692
693 SeedValue seed_mpfr_expm1 (SeedContext ctx,
694                            SeedObject function,
695                            SeedObject this_object,
696                            gsize argument_count,
697                            const SeedValue args[],
698                            SeedException * exception)
699 {
700     mpfr_rnd_t rnd;
701     mpfr_ptr rop, op;
702     gint ret;
703
704     CHECK_ARG_COUNT("mpfr.expm1", 2);
705
706     rop = seed_object_get_private(this_object);
707     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
708
709     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
710     {
711         op = seed_object_get_private(args[0]);
712     }
713     else
714     {
715         TYPE_EXCEPTION("mpfr.expm1", "mpfr_t");
716     }
717
718     ret = mpfr_expm1(rop, op, rnd);
719
720     return seed_value_from_int(ctx, ret, exception);
721 }
722
723 SeedValue seed_mpfr_li2 (SeedContext ctx,
724                          SeedObject function,
725                          SeedObject this_object,
726                          gsize argument_count,
727                          const SeedValue args[],
728                          SeedException * exception)
729 {
730     mpfr_rnd_t rnd;
731     mpfr_ptr rop, op;
732     gint ret;
733
734     CHECK_ARG_COUNT("mpfr.li2", 2);
735
736     rop = seed_object_get_private(this_object);
737     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
738
739     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
740     {
741         op = seed_object_get_private(args[0]);
742     }
743     else
744     {
745         TYPE_EXCEPTION("mpfr.li2", "mpfr_t");
746     }
747
748     ret = mpfr_li2(rop, op, rnd);
749
750     return seed_value_from_int(ctx, ret, exception);
751 }
752
753 SeedValue seed_mpfr_gamma (SeedContext ctx,
754                            SeedObject function,
755                            SeedObject this_object,
756                            gsize argument_count,
757                            const SeedValue args[],
758                            SeedException * exception)
759 {
760     mpfr_rnd_t rnd;
761     mpfr_ptr rop, op;
762     gint ret;
763
764     CHECK_ARG_COUNT("mpfr.gamma", 2);
765
766     rop = seed_object_get_private(this_object);
767     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
768
769     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
770     {
771         op = seed_object_get_private(args[0]);
772     }
773     else
774     {
775         TYPE_EXCEPTION("mpfr.gamma", "mpfr_t");
776     }
777
778     ret = mpfr_gamma(rop, op, rnd);
779
780     return seed_value_from_int(ctx, ret, exception);
781 }
782
783 SeedValue seed_mpfr_lngamma (SeedContext ctx,
784                              SeedObject function,
785                              SeedObject this_object,
786                              gsize argument_count,
787                              const SeedValue args[],
788                              SeedException * exception)
789 {
790     mpfr_rnd_t rnd;
791     mpfr_ptr rop, op;
792     gint ret;
793
794     CHECK_ARG_COUNT("mpfr.lngamma", 2);
795
796     rop = seed_object_get_private(this_object);
797     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
798
799     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
800     {
801         op = seed_object_get_private(args[0]);
802     }
803     else
804     {
805         TYPE_EXCEPTION("mpfr.lngamma", "mpfr_t");
806     }
807
808     ret = mpfr_lngamma(rop, op, rnd);
809
810     return seed_value_from_int(ctx, ret, exception);
811 }
812
813 SeedValue seed_mpfr_zeta (SeedContext ctx,
814                           SeedObject function,
815                           SeedObject this_object,
816                           gsize argument_count,
817                           const SeedValue args[],
818                           SeedException * exception)
819 {
820     mpfr_rnd_t rnd;
821     mpfr_ptr rop, op;
822     gint ret;
823     gulong uiop;
824
825     CHECK_ARG_COUNT("mpfr.zeta", 2);
826
827     rop = seed_object_get_private(this_object);
828     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
829
830     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
831     {
832         op = seed_object_get_private(args[0]);
833         ret = mpfr_zeta(rop, op, rnd);
834     }
835     else if ( seed_value_is_number(ctx, args[0]) )
836     {
837         uiop = seed_value_to_ulong(ctx, args[0], exception);
838         ret = mpfr_zeta_ui(rop, uiop, rnd);
839     }
840     else
841     {
842         TYPE_EXCEPTION("mpfr.zeta", "mpfr_t or unsigned int");
843     }
844
845     return seed_value_from_int(ctx, ret, exception);
846 }
847
848 SeedValue seed_mpfr_erf (SeedContext ctx,
849                          SeedObject function,
850                          SeedObject this_object,
851                          gsize argument_count,
852                          const SeedValue args[],
853                          SeedException * exception)
854 {
855     mpfr_rnd_t rnd;
856     mpfr_ptr rop, op;
857     gint ret;
858
859     CHECK_ARG_COUNT("mpfr.erf", 2);
860
861     rop = seed_object_get_private(this_object);
862     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
863
864     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
865     {
866         op = seed_object_get_private(args[0]);
867     }
868     else
869     {
870         TYPE_EXCEPTION("mpfr.erf", "mpfr_t");
871     }
872
873     ret = mpfr_erf(rop, op, rnd);
874
875     return seed_value_from_int(ctx, ret, exception);
876 }
877
878 SeedValue seed_mpfr_erfc (SeedContext ctx,
879                           SeedObject function,
880                           SeedObject this_object,
881                           gsize argument_count,
882                           const SeedValue args[],
883                           SeedException * exception)
884 {
885     mpfr_rnd_t rnd;
886     mpfr_ptr rop, op;
887     gint ret;
888
889     CHECK_ARG_COUNT("mpfr.erfc", 2);
890
891     rop = seed_object_get_private(this_object);
892     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
893
894     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
895     {
896         op = seed_object_get_private(args[0]);
897     }
898     else
899     {
900         TYPE_EXCEPTION("mpfr.erfc", "mpfr_t");
901     }
902
903     ret = mpfr_erfc(rop, op, rnd);
904
905     return seed_value_from_int(ctx, ret, exception);
906 }
907
908 /* bessel functions */
909 SeedValue seed_mpfr_j0 (SeedContext ctx,
910                         SeedObject function,
911                         SeedObject this_object,
912                         gsize argument_count,
913                         const SeedValue args[],
914                         SeedException * exception)
915 {
916     mpfr_rnd_t rnd;
917     mpfr_ptr rop, op;
918     gint ret;
919
920     CHECK_ARG_COUNT("mpfr.j0", 2);
921
922     rop = seed_object_get_private(this_object);
923     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
924
925     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
926     {
927         op = seed_object_get_private(args[0]);
928     }
929     else
930     {
931         TYPE_EXCEPTION("mpfr.j0", "mpfr_t");
932     }
933
934     ret = mpfr_j0(rop, op, rnd);
935
936     return seed_value_from_int(ctx, ret, exception);
937 }
938
939 SeedValue seed_mpfr_j1 (SeedContext ctx,
940                         SeedObject function,
941                         SeedObject this_object,
942                         gsize argument_count,
943                         const SeedValue args[],
944                         SeedException * exception)
945 {
946     mpfr_rnd_t rnd;
947     mpfr_ptr rop, op;
948     gint ret;
949
950     CHECK_ARG_COUNT("mpfr.j1", 2);
951
952     rop = seed_object_get_private(this_object);
953     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
954
955     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
956     {
957         op = seed_object_get_private(args[0]);
958     }
959     else
960     {
961         TYPE_EXCEPTION("mpfr.j1", "mpfr_t");
962     }
963
964     ret = mpfr_j1(rop, op, rnd);
965
966     return seed_value_from_int(ctx, ret, exception);
967 }
968
969 SeedValue seed_mpfr_jn (SeedContext ctx,
970                         SeedObject function,
971                         SeedObject this_object,
972                         gsize argument_count,
973                         const SeedValue args[],
974                         SeedException * exception)
975 {
976     mpfr_rnd_t rnd;
977     mpfr_ptr rop, op;
978     gint ret, n;
979
980     CHECK_ARG_COUNT("mpfr.jn", 3);
981
982     rop = seed_object_get_private(this_object);
983     rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
984
985     if ( seed_value_is_object_of_class(ctx, args[1], mpfr_class) )
986     {
987         op = seed_object_get_private(args[1]);
988     }
989     else
990     {
991         TYPE_EXCEPTION("mpfr.jn", "mpfr_t");
992     }
993
994     if ( seed_value_is_number(ctx, args[0]) )
995     {
996         n = seed_value_to_int(ctx, args[0], exception);
997     }
998     else
999     {
1000         TYPE_EXCEPTION("mpfr.jn", "int");
1001     }
1002
1003     ret = mpfr_jn(rop, n, op, rnd);
1004
1005     return seed_value_from_int(ctx, ret, exception);
1006 }
1007
1008 SeedValue seed_mpfr_y0 (SeedContext ctx,
1009                         SeedObject function,
1010                         SeedObject this_object,
1011                         gsize argument_count,
1012                         const SeedValue args[],
1013                         SeedException * exception)
1014 {
1015     mpfr_rnd_t rnd;
1016     mpfr_ptr rop, op;
1017     gint ret;
1018
1019     CHECK_ARG_COUNT("mpfr.y0", 2);
1020
1021     rop = seed_object_get_private(this_object);
1022     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
1023
1024     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
1025     {
1026         op = seed_object_get_private(args[0]);
1027     }
1028     else
1029     {
1030         TYPE_EXCEPTION("mpfr.y0", "mpfr_t");
1031     }
1032
1033     ret = mpfr_y0(rop, op, rnd);
1034
1035     return seed_value_from_int(ctx, ret, exception);
1036 }
1037
1038 SeedValue seed_mpfr_y1 (SeedContext ctx,
1039                         SeedObject function,
1040                         SeedObject this_object,
1041                         gsize argument_count,
1042                         const SeedValue args[],
1043                         SeedException * exception)
1044 {
1045     mpfr_rnd_t rnd;
1046     mpfr_ptr rop, op;
1047     gint ret;
1048
1049     CHECK_ARG_COUNT("mpfr.y1", 2);
1050
1051     rop = seed_object_get_private(this_object);
1052     rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
1053
1054     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
1055     {
1056         op = seed_object_get_private(args[0]);
1057     }
1058     else
1059     {
1060         TYPE_EXCEPTION("mpfr.y1", "mpfr_t");
1061     }
1062
1063     ret = mpfr_y1(rop, op, rnd);
1064
1065     return seed_value_from_int(ctx, ret, exception);
1066 }
1067
1068 SeedValue seed_mpfr_yn (SeedContext ctx,
1069                         SeedObject function,
1070                         SeedObject this_object,
1071                         gsize argument_count,
1072                         const SeedValue args[],
1073                         SeedException * exception)
1074 {
1075     mpfr_rnd_t rnd;
1076     mpfr_ptr rop, op;
1077     gint ret, n;
1078
1079     CHECK_ARG_COUNT("mpfr.yn", 3);
1080
1081     rop = seed_object_get_private(this_object);
1082     rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
1083
1084     if ( seed_value_is_object_of_class(ctx, args[1], mpfr_class) )
1085     {
1086         op = seed_object_get_private(args[1]);
1087     }
1088     else
1089     {
1090         TYPE_EXCEPTION("mpfr.yn", "mpfr_t");
1091     }
1092
1093     if ( seed_value_is_number(ctx, args[0]) )
1094     {
1095         n = seed_value_to_int(ctx, args[0], exception);
1096     }
1097     else
1098     {
1099         TYPE_EXCEPTION("mpfr.yn", "int");
1100     }
1101
1102     ret = mpfr_yn(rop, n, op, rnd);
1103
1104     return seed_value_from_int(ctx, ret, exception);
1105 }
1106
1107 SeedValue seed_mpfr_fma (SeedContext ctx,
1108                          SeedObject function,
1109                          SeedObject this_object,
1110                          gsize argument_count,
1111                          const SeedValue args[],
1112                          SeedException * exception)
1113 {
1114     mpfr_rnd_t rnd;
1115     mpfr_ptr rop, op1, op2, op3;
1116     gint ret;
1117
1118     CHECK_ARG_COUNT("mpfr.fma", 4);
1119
1120     rop = seed_object_get_private(this_object);
1121     rnd = seed_value_to_mpfr_rnd_t(ctx, args[3], exception);
1122
1123     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) &&
1124          seed_value_is_object_of_class(ctx, args[1], mpfr_class) &&
1125          seed_value_is_object_of_class(ctx, args[2], mpfr_class))
1126     {
1127         op1 = seed_object_get_private(args[0]);
1128         op2 = seed_object_get_private(args[1]);
1129         op3 = seed_object_get_private(args[2]);
1130     }
1131     else
1132     {
1133         TYPE_EXCEPTION("mpfr.fma", "mpfr_t");
1134     }
1135
1136     ret = mpfr_fma(rop, op1, op2, op3, rnd);
1137
1138     return seed_value_from_int(ctx, ret, exception);
1139 }
1140
1141 SeedValue seed_mpfr_fms (SeedContext ctx,
1142                          SeedObject function,
1143                          SeedObject this_object,
1144                          gsize argument_count,
1145                          const SeedValue args[],
1146                          SeedException * exception)
1147 {
1148     mpfr_rnd_t rnd;
1149     mpfr_ptr rop, op1, op2, op3;
1150     gint ret;
1151
1152     CHECK_ARG_COUNT("mpfr.fms", 4);
1153
1154     rop = seed_object_get_private(this_object);
1155     rnd = seed_value_to_mpfr_rnd_t(ctx, args[3], exception);
1156
1157     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) &&
1158          seed_value_is_object_of_class(ctx, args[1], mpfr_class) &&
1159          seed_value_is_object_of_class(ctx, args[2], mpfr_class))
1160     {
1161         op1 = seed_object_get_private(args[0]);
1162         op2 = seed_object_get_private(args[1]);
1163         op3 = seed_object_get_private(args[2]);
1164     }
1165     else
1166     {
1167         TYPE_EXCEPTION("mpfr.fms", "mpfr_t");
1168     }
1169
1170     ret = mpfr_fms(rop, op1, op2, op3, rnd);
1171
1172     return seed_value_from_int(ctx, ret, exception);
1173 }
1174
1175 SeedValue seed_mpfr_agm (SeedContext ctx,
1176                          SeedObject function,
1177                          SeedObject this_object,
1178                          gsize argument_count,
1179                          const SeedValue args[],
1180                          SeedException * exception)
1181 {
1182     mpfr_rnd_t rnd;
1183     mpfr_ptr rop, op1, op2;
1184     gint ret;
1185
1186     CHECK_ARG_COUNT("mpfr.agm", 3);
1187
1188     rop = seed_object_get_private(this_object);
1189     rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
1190
1191     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) &&
1192          seed_value_is_object_of_class(ctx, args[1], mpfr_class))
1193     {
1194         op1 = seed_object_get_private(args[0]);
1195         op2 = seed_object_get_private(args[1]);
1196     }
1197     else
1198     {
1199         TYPE_EXCEPTION("mpfr.agm", "mpfr_t");
1200     }
1201
1202     ret = mpfr_agm(rop, op1, op2, rnd);
1203
1204     return seed_value_from_int(ctx, ret, exception);
1205 }
1206
1207 SeedValue seed_mpfr_hypot (SeedContext ctx,
1208                            SeedObject function,
1209                            SeedObject this_object,
1210                            gsize argument_count,
1211                            const SeedValue args[],
1212                            SeedException * exception)
1213 {
1214     mpfr_rnd_t rnd;
1215     mpfr_ptr rop, op1, op2;
1216     gint ret;
1217
1218     CHECK_ARG_COUNT("mpfr.hypot", 3);
1219
1220     rop = seed_object_get_private(this_object);
1221     rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
1222
1223     if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) &&
1224          seed_value_is_object_of_class(ctx, args[1], mpfr_class))
1225     {
1226         op1 = seed_object_get_private(args[0]);
1227         op2 = seed_object_get_private(args[1]);
1228     }
1229     else
1230     {
1231         TYPE_EXCEPTION("mpfr.hypot", "mpfr_t");
1232     }
1233
1234     ret = mpfr_hypot(rop, op1, op2, rnd);
1235
1236     return seed_value_from_int(ctx, ret, exception);
1237 }
1238
1239 SeedValue seed_mpfr_free_cache (SeedContext ctx,
1240                                 SeedObject function,
1241                                 SeedObject this_object,
1242                                 gsize argument_count,
1243                                 const SeedValue args[],
1244                                 SeedException * exception)
1245 {
1246     CHECK_ARG_COUNT("mpfr.free_cache", 0);
1247     mpfr_free_cache();
1248     return seed_make_null(ctx);
1249 }
1250
1251 SeedValue seed_mpfr_clear_flags (SeedContext ctx,
1252                                  SeedObject function,
1253                                  SeedObject this_object,
1254                                  gsize argument_count,
1255                                  const SeedValue args[],
1256                                  SeedException * exception)
1257 {
1258     CHECK_ARG_COUNT("mpfr.clear_flags", 0);
1259     mpfr_clear_flags();
1260     return seed_make_null(ctx);
1261 }
1262