This source file includes following definitions.
- _bc_new_num_ex
- _bc_free_num_ex
- bc_init_numbers
- bc_copy_num
- bc_init_num
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 #include <config.h>
33 #include <stdio.h>
34 #include <assert.h>
35 #include <stdlib.h>
36 #include <ctype.h>
37 #include <stdarg.h>
38 #include "bcmath.h"
39 #include "private.h"
40
41 #if SANDER_0
42 bc_num _bc_Free_list = NULL;
43 #endif
44
45
46
47 bc_num
48 _bc_new_num_ex (length, scale, persistent)
49 int length, scale, persistent;
50 {
51 bc_num temp;
52
53
54 temp = (bc_num) safe_pemalloc (1, sizeof(bc_struct)+length, scale, persistent);
55 #if 0
56 if (_bc_Free_list != NULL) {
57 temp = _bc_Free_list;
58 _bc_Free_list = temp->n_next;
59 } else {
60 temp = (bc_num) pemalloc (sizeof(bc_struct), persistent);
61 if (temp == NULL) bc_out_of_memory ();
62 }
63 #endif
64 temp->n_sign = PLUS;
65 temp->n_len = length;
66 temp->n_scale = scale;
67 temp->n_refs = 1;
68
69 temp->n_ptr = (char *) safe_pemalloc (1, length, scale, persistent);
70 if (temp->n_ptr == NULL) bc_out_of_memory();
71 temp->n_value = temp->n_ptr;
72 memset (temp->n_ptr, 0, length+scale);
73 return temp;
74 }
75
76
77
78
79
80 void
81 _bc_free_num_ex (num, persistent)
82 bc_num *num;
83 int persistent;
84 {
85 if (*num == NULL) return;
86 (*num)->n_refs--;
87 if ((*num)->n_refs == 0) {
88 if ((*num)->n_ptr)
89
90 pefree ((*num)->n_ptr, persistent);
91 pefree(*num, persistent);
92 #if 0
93 (*num)->n_next = _bc_Free_list;
94 _bc_Free_list = *num;
95 #endif
96 }
97 *num = NULL;
98 }
99
100
101
102
103 void
104 bc_init_numbers (void)
105 {
106 BCG(_zero_) = _bc_new_num_ex (1,0,1);
107 BCG(_one_) = _bc_new_num_ex (1,0,1);
108 BCG(_one_)->n_value[0] = 1;
109 BCG(_two_) = _bc_new_num_ex (1,0,1);
110 BCG(_two_)->n_value[0] = 2;
111 }
112
113
114
115
116 bc_num
117 bc_copy_num (bc_num num)
118 {
119 num->n_refs++;
120 return num;
121 }
122
123
124
125
126 void
127 bc_init_num (bc_num *num)
128 {
129 *num = bc_copy_num (BCG(_zero_));
130 }
131