~ubuntu-branches/ubuntu/utopic/bc/utopic-proposed

« back to all changes in this revision

Viewing changes to dc/numeric.c

  • Committer: Bazaar Package Importer
  • Author(s): John G. Hasler
  • Date: 2009-10-15 12:17:23 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20091015121723-yw88a2por3cjq4un
Tags: 1.06.95-2
Fixed errors in debian/rules that prevented info files from
being correctly generated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 * make use of bc's numeric routines.
26
26
 */
27
27
 
 
28
/* make all the header files see that these are really the same thing;
 
29
 * this is acceptable because everywhere else dc_number is just referenced
 
30
 * as a pointer-to-incomplete-structure type
 
31
 */
 
32
#define dc_number bc_struct
 
33
 
28
34
#include "config.h"
29
35
 
30
36
#include <stdio.h>
64
70
int std_only = FALSE;
65
71
 
66
72
/* convert an opaque dc_num into a real bc_num */
67
 
#define CastNum(x)      ((bc_num)(x))
 
73
/* by a freak accident, these are now no-op mappings,
 
74
 * but leave the notation here in case that changes later
 
75
 * */
 
76
#define CastNum(x)              (x)
 
77
#define CastNumPtr(x)   (x)
68
78
 
69
79
/* add two dc_nums, place into *result;
70
80
 * return DC_SUCCESS on success, DC_DOMAIN_ERROR on domain error
76
86
        int kscale ATTRIB((unused)) DC_DECLSEP
77
87
        dc_num *result DC_DECLEND
78
88
{
79
 
        bc_init_num((bc_num *)result);
80
 
        bc_add(CastNum(a), CastNum(b), (bc_num *)result, 0);
 
89
        bc_init_num(CastNumPtr(result));
 
90
        bc_add(CastNum(a), CastNum(b), CastNumPtr(result), 0);
81
91
        return DC_SUCCESS;
82
92
}
83
93
 
91
101
        int kscale ATTRIB((unused)) DC_DECLSEP
92
102
        dc_num *result DC_DECLEND
93
103
{
94
 
        bc_init_num((bc_num *)result);
95
 
        bc_sub(CastNum(a), CastNum(b), (bc_num *)result, 0);
 
104
        bc_init_num(CastNumPtr(result));
 
105
        bc_sub(CastNum(a), CastNum(b), CastNumPtr(result), 0);
96
106
        return DC_SUCCESS;
97
107
}
98
108
 
106
116
        int kscale DC_DECLSEP
107
117
        dc_num *result DC_DECLEND
108
118
{
109
 
        bc_init_num((bc_num *)result);
110
 
        bc_multiply(CastNum(a), CastNum(b), (bc_num *)result, kscale);
 
119
        bc_init_num(CastNumPtr(result));
 
120
        bc_multiply(CastNum(a), CastNum(b), CastNumPtr(result), kscale);
111
121
        return DC_SUCCESS;
112
122
}
113
123
 
121
131
        int kscale DC_DECLSEP
122
132
        dc_num *result DC_DECLEND
123
133
{
124
 
        bc_init_num((bc_num *)result);
125
 
        if (bc_divide(CastNum(a), CastNum(b), (bc_num *)result, kscale)){
 
134
        bc_init_num(CastNumPtr(result));
 
135
        if (bc_divide(CastNum(a), CastNum(b), CastNumPtr(result), kscale)){
126
136
                fprintf(stderr, "%s: divide by zero\n", progname);
127
 
                checkferror_output(stderr);
128
137
                return DC_DOMAIN_ERROR;
129
138
        }
130
139
        return DC_SUCCESS;
142
151
        dc_num *quotient DC_DECLSEP
143
152
        dc_num *remainder DC_DECLEND
144
153
{
145
 
        bc_init_num((bc_num *)quotient);
146
 
        bc_init_num((bc_num *)remainder);
 
154
        bc_init_num(CastNumPtr(quotient));
 
155
        bc_init_num(CastNumPtr(remainder));
147
156
        if (bc_divmod(CastNum(a), CastNum(b),
148
 
                                                (bc_num *)quotient, (bc_num *)remainder, kscale)){
 
157
                                                CastNumPtr(quotient), CastNumPtr(remainder), kscale)){
149
158
                fprintf(stderr, "%s: divide by zero\n", progname);
150
 
                checkferror_output(stderr);
151
159
                return DC_DOMAIN_ERROR;
152
160
        }
153
161
        return DC_SUCCESS;
163
171
        int kscale DC_DECLSEP
164
172
        dc_num *result DC_DECLEND
165
173
{
166
 
        bc_init_num((bc_num *)result);
167
 
        if (bc_modulo(CastNum(a), CastNum(b), (bc_num *)result, kscale)){
 
174
        bc_init_num(CastNumPtr(result));
 
175
        if (bc_modulo(CastNum(a), CastNum(b), CastNumPtr(result), kscale)){
168
176
                fprintf(stderr, "%s: remainder by zero\n", progname);
169
 
                checkferror_output(stderr);
170
177
                return DC_DOMAIN_ERROR;
171
178
        }
172
179
        return DC_SUCCESS;
180
187
        int kscale DC_DECLSEP
181
188
        dc_num *result DC_DECLEND
182
189
{
183
 
        bc_init_num((bc_num *)result);
 
190
        bc_init_num(CastNumPtr(result));
184
191
        if (bc_raisemod(CastNum(base), CastNum(expo), CastNum(mod),
185
 
                                        (bc_num *)result, kscale)){
186
 
                if (bc_is_zero(CastNum(mod))) {
 
192
                                        CastNumPtr(result), kscale)){
 
193
                if (bc_is_zero(CastNum(mod)))
187
194
                        fprintf(stderr, "%s: remainder by zero\n", progname);
188
 
                        checkferror_output(stderr);
189
 
                }
190
195
                return DC_DOMAIN_ERROR;
191
196
        }
192
197
        return DC_SUCCESS;
202
207
        int kscale DC_DECLSEP
203
208
        dc_num *result DC_DECLEND
204
209
{
205
 
        bc_init_num((bc_num *)result);
206
 
        bc_raise(CastNum(a), CastNum(b), (bc_num *)result, kscale);
 
210
        bc_init_num(CastNumPtr(result));
 
211
        bc_raise(CastNum(a), CastNum(b), CastNumPtr(result), kscale);
207
212
        return DC_SUCCESS;
208
213
}
209
214
 
221
226
        tmp = bc_copy_num(CastNum(value));
222
227
        if (!bc_sqrt(&tmp, kscale)){
223
228
                fprintf(stderr, "%s: square root of negative number\n", progname);
224
 
                checkferror_output(stderr);
225
229
                bc_free_num(&tmp);
226
230
                return DC_DOMAIN_ERROR;
227
231
        }
228
 
        *((bc_num *)result) = tmp;
 
232
        *(CastNumPtr(result)) = tmp;
229
233
        return DC_SUCCESS;
230
234
}
231
235
 
273
277
{
274
278
        dc_data result;
275
279
 
276
 
        bc_init_num((bc_num *)&result.v.number);
277
 
        bc_int2num((bc_num *)&result.v.number, value);
 
280
        bc_init_num(CastNumPtr(&result.v.number));
 
281
        bc_int2num(CastNumPtr(&result.v.number), value);
278
282
        result.dc_type = DC_NUMBER;
279
283
        return result;
280
284
}
365
369
        bc_free_num(&base);
366
370
        if (readahead)
367
371
                *readahead = c;
368
 
        full_result.v.number = (dc_num)result;
 
372
        *CastNumPtr(&full_result.v.number) = result;
369
373
        full_result.dc_type = DC_NUMBER;
370
374
        return full_result;
371
375
}
425
429
{
426
430
        out_char('\0'); /* clear the column counter */
427
431
        bc_out_num(CastNum(value), obase, out_char, 0);
428
 
        if (newline_p == DC_WITHNL) {
 
432
        if (newline_p == DC_WITHNL)
429
433
                putchar ('\n');
430
 
                checkferror_output(stdout);
431
 
        }
432
434
        if (discard_p == DC_TOSS)
433
435
                dc_free_num(&value);
434
436
}
473
475
 
474
476
        for (cur=top_of_stack; cur; cur=next) {
475
477
                putchar(cur->digit);
476
 
                checkferror_output(stdout);
477
478
                next = cur->link;
478
479
                free(cur);
479
480
        }
488
489
dc_free_num DC_DECLARG((value))
489
490
        dc_num *value DC_DECLEND
490
491
{
491
 
        bc_free_num((bc_num *)value);
 
492
        bc_free_num(CastNumPtr(value));
492
493
}
493
494
 
494
495
/* return a duplicate of the number in the passed value */
591
592
                        out_col = 1;
592
593
                }
593
594
                putchar(ch);
594
 
                checkferror_output(stderr);
595
595
        }
596
596
}
597
597
 
631
631
        vfprintf (stderr, mesg, args);
632
632
        va_end (args);
633
633
        fprintf (stderr, "\n");
634
 
        checkferror_output(stderr);
635
634
}
636
635
 
637
636
 
665
664
        vfprintf (stderr, mesg, args);
666
665
        va_end (args);
667
666
        fprintf (stderr, "\n");
668
 
        checkferror_output(stderr);
669
667
}
670
668
 
671
669