1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /*                                                                           */
3 /*   File....: numb.c                                                        */
4 /*   Name....: Number Functions                                              */
5 /*   Author..: Thorsten Koch                                                 */
6 /*   Copyright by Author, All rights reserved                                */
7 /*                                                                           */
8 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
9 /*
10  * Copyright (C) 2001-2018 by Thorsten Koch <koch@zib.de>
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public License
14  * as published by the Free Software Foundation; either version 3
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
25  */
26 #ifndef _NUMB_H_
27 #define _NUMB_H_
28 
29 typedef struct number            Numb;
30 
31  /* numbgmp.c
32  */
33 extern void         numb_init(bool with_management);
34 extern void         numb_exit(void);
35 /*lint -sem(        numb_new, @P >= malloc(1)) */
36 extern Numb*        numb_new(void);
37 /*lint -sem(        numb_new_ascii, nulterm(1), 1P >= 1, @P >= malloc(1)) */
38 extern Numb*        numb_new_ascii(const char* val);
39 /*lint -sem(        numb_new_integer, @P >= malloc(1)) */
40 extern Numb*        numb_new_integer(int val);
41 
42 /*lint -sem(        numb_free, custodial(1), inout(1), cleanup, 1P >= 1) */
43 extern void         numb_free(Numb* numb);
44 /*lint -sem(        numb_is_valid, pure, 1P >= 1) */
45 extern bool         numb_is_valid(const Numb* numb);
46 
47 /*lint -sem(        numb_copy, 1p == 1, @P >= malloc(1)) */
48 extern Numb*        numb_copy(const Numb* source);
49 /*lint -sem(        numb_equal, pure, 1P >= 1, 2P >= 1) */
50 extern bool         numb_equal(const Numb* numb_a, const Numb* numb_b);
51 /*lint -sem(        numb_cmp, pure, 1P >= 1, 2P >= 1) */
52 extern int          numb_cmp(const Numb* numb_a, const Numb* numb_b);
53 /*lint -sem(        numb_set, inout(1), 1P >= 1, 2P >= 1) */
54 extern void         numb_set(Numb* numb_a, const Numb* numb_b);
55 /*lint -sem(        numb_add, inout(1), 1P >= 1, 2P >= 1) */
56 extern void         numb_add(Numb* numb_a, const Numb* numb_b);
57 /*lint -sem(        numb_new_add, 1P >= 1, 2p, @P >= malloc(1)) */
58 extern Numb*        numb_new_add(const Numb* numb_a, const Numb* numb_b);
59 /*lint -sem(        numb_sub, inout(1), 1P >= 1, 2P >= 1) */
60 extern void         numb_sub(Numb* numb_a, const Numb* numb_b);
61 /*lint -sem(        numb_new_sub, 1P >= 1, 2p, @P >= malloc(1)) */
62 extern Numb*        numb_new_sub(const Numb* numb_a, const Numb* numb_b);
63 /*lint -sem(        numb_mul, inout(1), 1P >= 1, 2P >= 1) */
64 extern void         numb_mul(Numb* numb_a, const Numb* numb_b);
65 /*lint -sem(        numb_new_mul, 1P >= 1, 2p, @P >= malloc(1)) */
66 extern Numb*        numb_new_mul(const Numb* numb_a, const Numb* numb_b);
67 /*lint -sem(        numb_div, inout(1), 1P >= 1, 2P >= 1) */
68 extern void         numb_div(Numb* numb_a, const Numb* numb_b);
69 /*lint -sem(        numb_new_div, 1P >= 1, 2p, @P >= malloc(1)) */
70 extern Numb*        numb_new_div(const Numb* numb_a, const Numb* numb_b);
71 /*lint -sem(        numb_intdiv, inout(1), 1P >= 1, 2P >= 1) */
72 extern void         numb_intdiv(Numb* numb_a, const Numb* numb_b);
73 /*lint -sem(        numb_new_intdiv, 1P >= 1, 2p, @P >= malloc(1)) */
74 extern Numb*        numb_new_intdiv(const Numb* numb_a, const Numb* numb_b);
75 /*lint -sem(        numb_new_pow, 1P >= 1, chneg(2), @P >= malloc(1)) */
76 extern Numb*        numb_new_pow(const Numb* base, int expo);
77 /*lint -sem(        numb_new_fac, chneg(1), @P >= malloc(1)) */
78 extern Numb*        numb_new_fac(int n);
79 /*lint -sem(        numb_mod, inout(1), 1P >= 1, 2P >= 1) */
80 extern void         numb_mod(Numb* numb_a, const Numb* numb_b);
81 /*lint -sem(        numb_new_mod, 1P >= 1, 2p, @P >= malloc(1)) */
82 extern Numb*        numb_new_mod(const Numb* numb_a, const Numb* numb_b);
83 /*lint -sem(        numb_neg, inout(1), 1P >= 1) */
84 extern void         numb_neg(Numb* numb);
85 /*lint -sem(        numb_abs, inout(1), 1P >= 1) */
86 extern void         numb_abs(Numb* numb);
87 /*lint -sem(        numb_sgn, inout(1), 1P >= 1) */
88 extern void         numb_sgn(Numb* numb);
89 /*lint -sem(        numb_get_sgn, 1P >= 1, @n >= -1 && @n <= 1) */
90 extern int          numb_get_sgn(const Numb* numb);
91 /*lint -sem(        numb_round, inout(1), 1P >= 1) */
92 extern void         numb_round(Numb* numb);
93 /*lint -sem(        numb_ceil, inout(1), 1P >= 1) */
94 extern void         numb_ceil(Numb* numb);
95 /*lint -sem(        numb_floor, inout(1), 1P >= 1) */
96 extern void         numb_floor(Numb* numb);
97 /*lint -sem(        numb_new_log, 1P >= 1, @P >= malloc(1) || @P == 0) */
98 extern Numb*        numb_new_log(const Numb* numb);
99 /*lint -sem(        numb_new_sqrt, 1P >= 1, @P >= malloc(1) || @P == 0) */
100 extern Numb*        numb_new_sqrt(const Numb* numb);
101 /*lint -sem(        numb_new_exp, 1P >= 1, @P >= malloc(1)) */
102 extern Numb*        numb_new_exp(const Numb* numb);
103 /*lint -sem(        numb_new_ln, 1P >= 1, @P >= malloc(1) || @P == 0) */
104 extern Numb*        numb_new_ln(const Numb* numb);
105 /*lint -sem(        numb_new_rand, 1P >= 1, 2p, @P >= malloc(1)) */
106 extern Numb*        numb_new_rand(const Numb* mini, const Numb* maxi);
107 /*lint -sem(        numb_todbl, pure, 1P >= 1) */
108 extern double       numb_todbl(const Numb* numb);
109 /*lint -sem(        numb_print, 1P >= 1, 2P >= 1) */
110 extern void         numb_print(FILE* fp, const Numb* numb);
111 /*lint -sem(        numb_hash, pure, 1P >= 1) */
112 extern unsigned int numb_hash(const Numb* numb);
113 /*lint -sem(        numb_tostr, 1P >= 1, @p) */
114 extern char*        numb_tostr(const Numb* numb);
115 /*lint -sem(        numb_zero, @P >= 1) */
116 extern const Numb*  numb_zero(void);
117 /*lint -sem(        numb_one, @P >= 1) */
118 extern const Numb*  numb_one(void);
119 /*lint -sem(        numb_minusone, @P >= 1) */
120 extern const Numb*  numb_minusone(void);
121 /*lint -sem(        numb_unknown, @P >= 1) */
122 extern const Numb*  numb_unknown(void);
123 /*lint -sem(        numb_is_int, pure, 1P >= 1) */
124 extern bool         numb_is_int(const Numb* numb);
125 /*lint -sem(        numb_toint, pure, 1P >= 1) */
126 extern int          numb_toint(const Numb* numb);
127 /*lint -sem(        numb_is_number, 1P >= 1) */
128 extern bool         numb_is_number(const char *s);
129 
130 #ifdef __GMP_H__
131 /*lint -sem(        numb_new_mpq, @P >= malloc(1)) */
132 extern Numb*        numb_new_mpq(const mpq_t val);
133 /*lint -sem(        numb_new_mpq, 1P >= 1) */
134 extern void         numb_get_mpq(const Numb* numb, mpq_t value);
135 #endif /* __GMP_H__ */
136 
137 #endif /* _NUMB_H_ */
138