Lines Matching full:r
35 \f[I]#include <bcl.h>\f[R]
37 Link with \f[I]\-lbcl\f[R], and on POSIX systems, \f[I]\-lpthread\f[R]
42 \f[B]BclError bcl_start(\f[R]\f[I]void\f[R]\f[B]);\f[R]
44 \f[B]void bcl_end(\f[R]\f[I]void\f[R]\f[B]);\f[R]
46 \f[B]BclError bcl_init(\f[R]\f[I]void\f[R]\f[B]);\f[R]
48 \f[B]void bcl_free(\f[R]\f[I]void\f[R]\f[B]);\f[R]
50 \f[B]bool bcl_abortOnFatalError(\f[R]\f[I]void\f[R]\f[B]);\f[R]
52 \f[B]void bcl_setAbortOnFatalError(bool\f[R] \f[I]abrt\f[R]\f[B]);\f[R]
54 \f[B]bool bcl_leadingZeroes(\f[R]\f[I]void\f[R]\f[B]);\f[R]
56 \f[B]void bcl_setLeadingZeroes(bool\f[R]
57 \f[I]leadingZeroes\f[R]\f[B]);\f[R]
59 \f[B]void bcl_gc(\f[R]\f[I]void\f[R]\f[B]);\f[R]
61 \f[B]bool bcl_digitClamp(\f[R]\f[I]void\f[R]\f[B]);\f[R]
63 \f[B]void bcl_setDigitClamp(bool\f[R] \f[I]digitClamp\f[R]\f[B]);\f[R]
69 \f[B]struct BclCtxt;\f[R]
71 \f[B]typedef struct BclCtxt* BclContext;\f[R]
73 \f[B]BclContext bcl_ctxt_create(\f[R]\f[I]void\f[R]\f[B]);\f[R]
75 \f[B]void bcl_ctxt_free(BclContext\f[R] \f[I]ctxt\f[R]\f[B]);\f[R]
77 \f[B]BclError bcl_pushContext(BclContext\f[R] \f[I]ctxt\f[R]\f[B]);\f[R]
79 \f[B]void bcl_popContext(\f[R]\f[I]void\f[R]\f[B]);\f[R]
81 \f[B]BclContext bcl_context(\f[R]\f[I]void\f[R]\f[B]);\f[R]
83 \f[B]void bcl_ctxt_freeNums(BclContext\f[R] \f[I]ctxt\f[R]\f[B]);\f[R]
85 \f[B]size_t bcl_ctxt_scale(BclContext\f[R] \f[I]ctxt\f[R]\f[B]);\f[R]
87 \f[B]void bcl_ctxt_setScale(BclContext\f[R] \f[I]ctxt\f[R]\f[B],
88 size_t\f[R] \f[I]scale\f[R]\f[B]);\f[R]
90 \f[B]size_t bcl_ctxt_ibase(BclContext\f[R] \f[I]ctxt\f[R]\f[B]);\f[R]
92 \f[B]void bcl_ctxt_setIbase(BclContext\f[R] \f[I]ctxt\f[R]\f[B],
93 size_t\f[R] \f[I]ibase\f[R]\f[B]);\f[R]
95 \f[B]size_t bcl_ctxt_obase(BclContext\f[R] \f[I]ctxt\f[R]\f[B]);\f[R]
97 \f[B]void bcl_ctxt_setObase(BclContext\f[R] \f[I]ctxt\f[R]\f[B],
98 size_t\f[R] \f[I]obase\f[R]\f[B]);\f[R]
102 \f[B]typedef enum BclError BclError;\f[R]
104 \f[B]BclError bcl_err(BclNumber\f[R] \f[I]n\f[R]\f[B]);\f[R]
109 \f[B]typedef struct { size_t i; } BclNumber;\f[R]
111 \f[B]BclNumber bcl_num_create(\f[R]\f[I]void\f[R]\f[B]);\f[R]
113 \f[B]void bcl_num_free(BclNumber\f[R] \f[I]n\f[R]\f[B]);\f[R]
115 \f[B]bool bcl_num_neg(BclNumber\f[R] \f[I]n\f[R]\f[B]);\f[R]
117 \f[B]void bcl_num_setNeg(BclNumber\f[R] \f[I]n\f[R]\f[B], bool\f[R]
118 \f[I]neg\f[R]\f[B]);\f[R]
120 \f[B]size_t bcl_num_scale(BclNumber\f[R] \f[I]n\f[R]\f[B]);\f[R]
122 \f[B]BclError bcl_num_setScale(BclNumber\f[R] \f[I]n\f[R]\f[B],
123 size_t\f[R] \f[I]scale\f[R]\f[B]);\f[R]
125 \f[B]size_t bcl_num_len(BclNumber\f[R] \f[I]n\f[R]\f[B]);\f[R]
130 \f[B]BclNumber bcl_parse(const char *restrict\f[R]
131 \f[I]val\f[R]\f[B]);\f[R]
133 \f[B]char* bcl_string(BclNumber\f[R] \f[I]n\f[R]\f[B]);\f[R]
135 \f[B]char* bcl_string_keep(BclNumber\f[R] \f[I]n\f[R]\f[B]);\f[R]
137 \f[B]BclError bcl_bigdig(BclNumber\f[R] \f[I]n\f[R]\f[B], BclBigDig
138 *\f[R]\f[I]result\f[R]\f[B]);\f[R]
140 \f[B]BclError bcl_bigdig_keep(BclNumber\f[R] \f[I]n\f[R]\f[B], BclBigDig
141 *\f[R]\f[I]result\f[R]\f[B]);\f[R]
143 \f[B]BclNumber bcl_bigdig2num(BclBigDig\f[R] \f[I]val\f[R]\f[B]);\f[R]
147 \f[B]BclNumber bcl_add(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R]
148 \f[I]b\f[R]\f[B]);\f[R]
150 \f[B]BclNumber bcl_add_keep(BclNumber\f[R] \f[I]a\f[R]\f[B],
151 BclNumber\f[R] \f[I]b\f[R]\f[B]);\f[R]
153 \f[B]BclNumber bcl_sub(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R]
154 \f[I]b\f[R]\f[B]);\f[R]
156 \f[B]BclNumber bcl_sub_keep(BclNumber\f[R] \f[I]a\f[R]\f[B],
157 BclNumber\f[R] \f[I]b\f[R]\f[B]);\f[R]
159 \f[B]BclNumber bcl_mul(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R]
160 \f[I]b\f[R]\f[B]);\f[R]
162 \f[B]BclNumber bcl_mul_keep(BclNumber\f[R] \f[I]a\f[R]\f[B],
163 BclNumber\f[R] \f[I]b\f[R]\f[B]);\f[R]
165 \f[B]BclNumber bcl_div(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R]
166 \f[I]b\f[R]\f[B]);\f[R]
168 \f[B]BclNumber bcl_div_keep(BclNumber\f[R] \f[I]a\f[R]\f[B],
169 BclNumber\f[R] \f[I]b\f[R]\f[B]);\f[R]
171 \f[B]BclNumber bcl_mod(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R]
172 \f[I]b\f[R]\f[B]);\f[R]
174 \f[B]BclNumber bcl_mod_keep(BclNumber\f[R] \f[I]a\f[R]\f[B],
175 BclNumber\f[R] \f[I]b\f[R]\f[B]);\f[R]
177 \f[B]BclNumber bcl_pow(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R]
178 \f[I]b\f[R]\f[B]);\f[R]
180 \f[B]BclNumber bcl_pow_keep(BclNumber\f[R] \f[I]a\f[R]\f[B],
181 BclNumber\f[R] \f[I]b\f[R]\f[B]);\f[R]
183 \f[B]BclNumber bcl_lshift(BclNumber\f[R] \f[I]a\f[R]\f[B],
184 BclNumber\f[R] \f[I]b\f[R]\f[B]);\f[R]
186 \f[B]BclNumber bcl_lshift_keep(BclNumber\f[R] \f[I]a\f[R]\f[B],
187 BclNumber\f[R] \f[I]b\f[R]\f[B]);\f[R]
189 \f[B]BclNumber bcl_rshift(BclNumber\f[R] \f[I]a\f[R]\f[B],
190 BclNumber\f[R] \f[I]b\f[R]\f[B]);\f[R]
192 \f[B]BclNumber bcl_rshift_keep(BclNumber\f[R] \f[I]a\f[R]\f[B],
193 BclNumber\f[R] \f[I]b\f[R]\f[B]);\f[R]
195 \f[B]BclNumber bcl_sqrt(BclNumber\f[R] \f[I]a\f[R]\f[B]);\f[R]
197 \f[B]BclNumber bcl_sqrt_keep(BclNumber\f[R] \f[I]a\f[R]\f[B]);\f[R]
199 \f[B]BclError bcl_divmod(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R]
200 \f[I]b\f[R]\f[B], BclNumber *\f[R]\f[I]c\f[R]\f[B], BclNumber
201 *\f[R]\f[I]d\f[R]\f[B]);\f[R]
203 \f[B]BclError bcl_divmod_keep(BclNumber\f[R] \f[I]a\f[R]\f[B],
204 BclNumber\f[R] \f[I]b\f[R]\f[B], BclNumber *\f[R]\f[I]c\f[R]\f[B],
205 BclNumber *\f[R]\f[I]d\f[R]\f[B]);\f[R]
207 \f[B]BclNumber bcl_modexp(BclNumber\f[R] \f[I]a\f[R]\f[B],
208 BclNumber\f[R] \f[I]b\f[R]\f[B], BclNumber\f[R] \f[I]c\f[R]\f[B]);\f[R]
210 \f[B]BclNumber bcl_modexp_keep(BclNumber\f[R] \f[I]a\f[R]\f[B],
211 BclNumber\f[R] \f[I]b\f[R]\f[B], BclNumber\f[R] \f[I]c\f[R]\f[B]);\f[R]
215 \f[B]void bcl_zero(BclNumber\f[R] \f[I]n\f[R]\f[B]);\f[R]
217 \f[B]void bcl_one(BclNumber\f[R] \f[I]n\f[R]\f[B]);\f[R]
219 \f[B]ssize_t bcl_cmp(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R]
220 \f[I]b\f[R]\f[B]);\f[R]
222 \f[B]BclError bcl_copy(BclNumber\f[R] \f[I]d\f[R]\f[B], BclNumber\f[R]
223 \f[I]s\f[R]\f[B]);\f[R]
225 \f[B]BclNumber bcl_dup(BclNumber\f[R] \f[I]s\f[R]\f[B]);\f[R]
230 \f[B]#define BCL_SEED_ULONGS\f[R]
232 \f[B]#define BCL_SEED_SIZE\f[R]
234 \f[B]typedef unsigned long BclBigDig;\f[R]
236 \f[B]typedef unsigned long BclRandInt;\f[R]
238 \f[B]BclNumber bcl_irand(BclNumber\f[R] \f[I]a\f[R]\f[B]);\f[R]
240 \f[B]BclNumber bcl_irand_keep(BclNumber\f[R] \f[I]a\f[R]\f[B]);\f[R]
242 \f[B]BclNumber bcl_frand(size_t\f[R] \f[I]places\f[R]\f[B]);\f[R]
244 \f[B]BclNumber bcl_ifrand(BclNumber\f[R] \f[I]a\f[R]\f[B], size_t\f[R]
245 \f[I]places\f[R]\f[B]);\f[R]
247 \f[B]BclNumber bcl_ifrand_keep(BclNumber\f[R] \f[I]a\f[R]\f[B],
248 size_t\f[R] \f[I]places\f[R]\f[B]);\f[R]
250 \f[B]BclError bcl_rand_seedWithNum(BclNumber\f[R]
251 \f[I]n\f[R]\f[B]);\f[R]
253 \f[B]BclError bcl_rand_seedWithNum_keep(BclNumber\f[R]
254 \f[I]n\f[R]\f[B]);\f[R]
256 \f[B]BclError bcl_rand_seed(unsigned char\f[R]
257 \f[I]seed\f[R]\f[B][\f[R]\f[I]BCL_SEED_SIZE\f[R]\f[B]]);\f[R]
259 \f[B]void bcl_rand_reseed(\f[R]\f[I]void\f[R]\f[B]);\f[R]
261 \f[B]BclNumber bcl_rand_seed2num(\f[R]\f[I]void\f[R]\f[B]);\f[R]
263 \f[B]BclRandInt bcl_rand_int(\f[R]\f[I]void\f[R]\f[B]);\f[R]
265 \f[B]BclRandInt bcl_rand_bounded(BclRandInt\f[R]
266 \f[I]bound\f[R]\f[B]);\f[R]
273 bcl(3) assumes that it is allowed to use the \f[B]bcl\f[R],
274 \f[B]Bcl\f[R], \f[B]bc\f[R], and \f[B]Bc\f[R] prefixes for symbol names
282 \f[B]BclError bcl_start(\f[R]\f[I]void\f[R]\f[B])\f[R]
284 This function can be called multiple times, but \f[B]bcl_end()\f[R] must
285 only be called \f[I]once\f[R].
291 call \f[B]bcl_end()\f[R], and client applications should call both.
293 If there was no error, \f[B]BCL_ERROR_NONE\f[R] is returned.
296 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
303 \f[B]void bcl_end(\f[R]\f[I]void\f[R]\f[B])\f[R]
305 This function must only be called \f[I]once\f[R].
315 \f[B]BclError bcl_init(\f[R]\f[I]void\f[R]\f[B])\f[R]
318 matched by a call to \f[B]bcl_free(\f[R]\f[I]void\f[R]\f[B])\f[R].
323 This function \f[I]must\f[R] be called from the thread that it is
326 If there was no error, \f[B]BCL_ERROR_NONE\f[R] is returned.
329 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
332 Calling any other function without calling \f[B]bcl_start()\f[R] and
336 \f[B]bcl_start()\f[R] if another thread has previously called
337 \f[B]bcl_start()\f[R].
342 \f[B]void bcl_free(\f[R]\f[I]void\f[R]\f[B])\f[R]
344 with it if the reference count is \f[B]0\f[R].
347 This function \f[I]must\f[R] be called from the thread that it is
352 \f[B]bcl_end()\f[R] is undefined behavior.
355 \f[B]bool bcl_abortOnFatalError(\f[R]\f[I]void\f[R]\f[B])\f[R]
356 Queries and returns the current state of calling \f[B]abort()\f[R] on
358 If \f[B]true\f[R] is returned, bcl(3) will cause a \f[B]SIGABRT\f[R] if
364 This value is \f[I]thread\-local\f[R]; it applies to just the thread it
367 The default is \f[B]false\f[R].
370 \f[B]void bcl_setAbortOnFatalError(bool\f[R] \f[I]abrt\f[R]\f[B])\f[R]
371 Sets the state of calling \f[B]abort()\f[R] on fatal errors.
372 If \f[I]abrt\f[R] is \f[B]false\f[R], bcl(3) will not cause a
373 \f[B]SIGABRT\f[R] on fatal errors after the call.
374 If \f[I]abrt\f[R] is \f[B]true\f[R], bcl(3) will cause a
375 \f[B]SIGABRT\f[R] on fatal errors after the call.
378 This value is \f[I]thread\-local\f[R]; it applies to just the thread it
384 \f[B]bool bcl_leadingZeroes(\f[R]\f[I]void\f[R]\f[B])\f[R]
386 strings returned by \f[B]bcl_string()\f[R] when numbers are greater than
387 \f[B]\-1\f[R], less than \f[B]1\f[R], and not equal to \f[B]0\f[R].
388 If \f[B]true\f[R] is returned, then leading zeroes will be added.
391 This value is \f[I]thread\-local\f[R]; it applies to just the thread it
394 The default is \f[B]false\f[R].
397 \f[B]void bcl_setLeadingZeroes(bool\f[R] \f[I]leadingZeroes\f[R]\f[B])\f[R]
399 by \f[B]bcl_string()\f[R] when numbers are greater than \f[B]\-1\f[R],
400 less than \f[B]1\f[R], and not equal to \f[B]0\f[R].
401 If \f[I]leadingZeroes\f[R] is \f[B]true\f[R], leading zeroes will be
402 added to strings returned by \f[B]bcl_string()\f[R].
405 This value is \f[I]thread\-local\f[R]; it applies to just the thread it
409 \f[B]bool bcl_digitClamp(\f[R]\f[I]void\f[R]\f[B])\f[R]
411 are greater than or equal to the current \f[B]ibase\f[R] are clamped or
415 If \f[B]true\f[R] is returned, then digits are treated as though they
416 are equal to the value of \f[B]ibase\f[R] minus \f[B]1\f[R].
417 If this is \f[I]not\f[R] true, then digits are treated as though they
418 are equal to the value they would have if \f[B]ibase\f[R] was large
420 They are then multiplied by the appropriate power of \f[B]ibase\f[R].
422 For example, with clamping off and an \f[B]ibase\f[R] of \f[B]3\f[R],
423 the string \[lq]AB\[rq] would equal \f[B]3\[ha]1*A+3\[ha]0*B\f[R], which
424 is \f[B]3\f[R] times \f[B]10\f[R] plus \f[B]11\f[R], or \f[B]41\f[R],
425 while with clamping on and an \f[B]ibase\f[R] of \f[B]3\f[R], the string
426 \[lq]AB\[rq] would be equal to \f[B]3\[ha]1*2+3\[ha]0*2\f[R], which is
427 \f[B]3\f[R] times \f[B]2\f[R] plus \f[B]2\f[R], or \f[B]8\f[R].
429 This value is \f[I]thread\-local\f[R]; it applies to just the thread it
432 The default is \f[B]true\f[R].
435 \f[B]void bcl_setDigitClamp(bool\f[R] \f[I]digitClamp\f[R]\f[B])\f[R]
437 or equal to the current \f[B]ibase\f[R] are clamped or not.
439 \f[B]bcl_digitClamp(\f[R]\f[I]void\f[R]\f[B])\f[R] function.
442 This value is \f[I]thread\-local\f[R]; it applies to just the thread it
446 \f[B]void bcl_gc(\f[R]\f[I]void\f[R]\f[B])\f[R]
448 This only frees the memory of numbers that are \f[I]not\f[R] in use, so
451 All procedures that take a \f[B]BclContext\f[R] parameter a require a
454 \f[B]struct BclCtxt\f[R]
455 A forward declaration for a hidden \f[B]struct\f[R] type.
456 Clients cannot access the internals of the \f[B]struct\f[R] type
459 See \f[B]BclContext\f[R] below.
461 \f[B]BclContext\f[R]
462 A typedef to a pointer of \f[B]struct BclCtxt\f[R].
463 This is the only handle clients can get to \f[B]struct BclCtxt\f[R].
466 A \f[B]BclContext\f[R] contains the values \f[B]scale\f[R],
467 \f[B]ibase\f[R], and \f[B]obase\f[R], as well as a list of numbers.
469 \f[B]scale\f[R] is a value used to control how many decimal places
471 A value of \f[B]0\f[R] means that calculations are done on integers
474 The default is \f[B]0\f[R].
476 \f[B]ibase\f[R] is a value used to control the input base.
477 The minimum \f[B]ibase\f[R] is \f[B]2\f[R], and the maximum is
478 \f[B]36\f[R].
479 If \f[B]ibase\f[R] is \f[B]2\f[R], numbers are parsed as though they are
480 in binary, and any digits larger than \f[B]1\f[R] are clamped.
481 Likewise, a value of \f[B]10\f[R] means that numbers are parsed as
483 The default is \f[B]10\f[R].
485 \f[B]obase\f[R] is a value used to control the output base.
486 The minimum \f[B]obase\f[R] is \f[B]0\f[R] and the maximum is
487 \f[B]BC_BASE_MAX\f[R] (see the \f[B]LIMITS\f[R] section).
496 To pass values between contexts and threads, use \f[B]bcl_string()\f[R]
497 to produce a string to pass around, and use \f[B]bcl_parse()\f[R] to
499 It is suggested that the \f[B]obase\f[R] used to create the string be
500 passed around with the string and used as the \f[B]ibase\f[R] for
501 \f[B]bcl_parse()\f[R] to ensure that the number will be the same.
504 \f[B]BclContext bcl_ctxt_create(\f[R]\f[I]void\f[R]\f[B])\f[R]
506 Returns \f[B]NULL\f[R] if there was an error.
508 \f[B]void bcl_ctxt_free(BclContext\f[R] \f[I]ctxt\f[R]\f[B])\f[R]
509 Frees \f[I]ctxt\f[R], after which it is no longer valid.
512 \f[B]BclError bcl_pushContext(BclContext\f[R] \f[I]ctxt\f[R]\f[B])\f[R]
513 Pushes \f[I]ctxt\f[R] onto bcl(3)\[cq]s stack of contexts.
514 \f[I]ctxt\f[R] must have been created with
515 \f[B]bcl_ctxt_create(\f[R]\f[I]void\f[R]\f[B])\f[R].
518 If there was no error, \f[B]BCL_ERROR_NONE\f[R] is returned.
521 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
523 There \f[I]must\f[R] be a valid context to do any arithmetic.
526 \f[B]void bcl_popContext(\f[R]\f[I]void\f[R]\f[B])\f[R]
529 \f[B]BclContext bcl_context(\f[R]\f[I]void\f[R]\f[B])\f[R]
530 Returns the current context, or \f[B]NULL\f[R] if no context exists.
532 \f[B]void bcl_ctxt_freeNums(BclContext\f[R] \f[I]ctxt\f[R]\f[B])\f[R]
533 Frees all numbers in use that are associated with \f[I]ctxt\f[R].
535 \f[I]ctxt\f[R] after calling this procedure unless such numbers have
536 been created with \f[B]bcl_num_create(\f[R]\f[I]void\f[R]\f[B])\f[R]
539 \f[B]size_t bcl_ctxt_scale(BclContext\f[R] \f[I]ctxt\f[R]\f[B])\f[R]
540 Returns the \f[B]scale\f[R] for given context.
542 \f[B]void bcl_ctxt_setScale(BclContext\f[R] \f[I]ctxt\f[R]\f[B], size_t\f[R] \f[I]scale\f[R]\f[B])\…
543 Sets the \f[B]scale\f[R] for the given context to the argument
544 \f[I]scale\f[R].
546 \f[B]size_t bcl_ctxt_ibase(BclContext\f[R] \f[I]ctxt\f[R]\f[B])\f[R]
547 Returns the \f[B]ibase\f[R] for the given context.
549 \f[B]void bcl_ctxt_setIbase(BclContext\f[R] \f[I]ctxt\f[R]\f[B], size_t\f[R] \f[I]ibase\f[R]\f[B])\…
550 Sets the \f[B]ibase\f[R] for the given context to the argument
551 \f[I]ibase\f[R].
552 If the argument \f[I]ibase\f[R] is invalid, it clamped, so an
553 \f[I]ibase\f[R] of \f[B]0\f[R] or \f[B]1\f[R] is clamped to \f[B]2\f[R],
554 and any values above \f[B]36\f[R] are clamped to \f[B]36\f[R].
556 \f[B]size_t bcl_ctxt_obase(BclContext\f[R] \f[I]ctxt\f[R]\f[B])\f[R]
557 Returns the \f[B]obase\f[R] for the given context.
559 \f[B]void bcl_ctxt_setObase(BclContext\f[R] \f[I]ctxt\f[R]\f[B], size_t\f[R] \f[I]obase\f[R]\f[B])\…
560 Sets the \f[B]obase\f[R] for the given context to the argument
561 \f[I]obase\f[R].
564 \f[B]BclError\f[R]
565 An \f[B]enum\f[R] of possible error codes.
566 See the \f[B]ERRORS\f[R] section for a complete listing the codes.
568 \f[B]BclError bcl_err(BclNumber\f[R] \f[I]n\f[R]\f[B])\f[R]
569 Checks for errors in a \f[B]BclNumber\f[R].
570 All functions that can return a \f[B]BclNumber\f[R] can encode an error
572 If there was no error, it will return \f[B]BCL_ERROR_NONE\f[R].
580 \f[B]BclNumber\f[R]
582 The actual number type is not exposed; the \f[B]BclNumber\f[R] handle is
586 \f[B]BclNumber bcl_num_create(\f[R]\f[I]void\f[R]\f[B])\f[R]
587 Creates and returns a \f[B]BclNumber\f[R].
591 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
594 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
596 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
599 \f[B]void bcl_num_free(BclNumber\f[R] \f[I]n\f[R]\f[B])\f[R]
600 Frees \f[I]n\f[R].
601 It is undefined behavior to use \f[I]n\f[R] after calling this function.
603 \f[B]bool bcl_num_neg(BclNumber\f[R] \f[I]n\f[R]\f[B])\f[R]
604 Returns \f[B]true\f[R] if \f[I]n\f[R] is negative, \f[B]false\f[R]
607 \f[B]void bcl_num_setNeg(BclNumber\f[R] \f[I]n\f[R]\f[B], bool\f[R] \f[I]neg\f[R]\f[B])\f[R]
608 Sets \f[I]n\f[R]\[cq]s sign to \f[I]neg\f[R], where \f[B]true\f[R] is
609 negative, and \f[B]false\f[R] is positive.
611 \f[B]size_t bcl_num_scale(BclNumber\f[R] \f[I]n\f[R]\f[B])\f[R]
612 Returns the \f[I]scale\f[R] of \f[I]n\f[R].
615 The \f[I]scale\f[R] of a number is the number of decimal places it has
619 \f[B]BclError bcl_num_setScale(BclNumber\f[R] \f[I]n\f[R]\f[B], size_t\f[R] \f[I]scale\f[R]\f[B])\f…
620 Sets the \f[I]scale\f[R] of \f[I]n\f[R] to the argument \f[I]scale\f[R].
621 If the argument \f[I]scale\f[R] is greater than the \f[I]scale\f[R] of
622 \f[I]n\f[R], \f[I]n\f[R] is extended.
623 If the argument \f[I]scale\f[R] is less than the \f[I]scale\f[R] of
624 \f[I]n\f[R], \f[I]n\f[R] is truncated.
627 If there was no error, \f[B]BCL_ERROR_NONE\f[R] is returned.
630 \f[B]BCL_ERROR_INVALID_NUM\f[R]
632 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
634 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
637 \f[B]size_t bcl_num_len(BclNumber\f[R] \f[I]n\f[R]\f[B])\f[R]
638 Returns the number of \f[I]significant decimal digits\f[R] in
639 \f[I]n\f[R].
643 All procedures in this section without the \f[B]_keep\f[R] suffix in
644 their name consume the given \f[B]BclNumber\f[R] arguments that are not
646 See the \f[B]Consumption and Propagation\f[R] subsection below.
648 \f[B]BclNumber bcl_parse(const char *restrict\f[R] \f[I]val\f[R]\f[B])\f[R]
650 \f[B]ibase\f[R] and returns the resulting number.
653 \f[I]val\f[R] must be non\-\f[B]NULL\f[R] and a valid string.
654 See \f[B]BCL_ERROR_PARSE_INVALID_STR\f[R] in the \f[B]ERRORS\f[R]
658 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
661 \f[B]BCL_ERROR_INVALID_NUM\f[R]
663 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
665 \f[B]BCL_ERROR_PARSE_INVALID_STR\f[R]
667 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
670 \f[B]char* bcl_string(BclNumber\f[R] \f[I]n\f[R]\f[B])\f[R]
671 Returns a string representation of \f[I]n\f[R] according the the current
672 context\[cq]s \f[B]ibase\f[R].
676 \f[I]n\f[R] is consumed; it cannot be used after the call.
677 See the \f[B]Consumption and Propagation\f[R] subsection below.
680 \f[B]char* bcl_string_keep(BclNumber\f[R] \f[I]n\f[R]\f[B])\f[R]
681 Returns a string representation of \f[I]n\f[R] according the the current
682 context\[cq]s \f[B]ibase\f[R].
685 \f[B]BclError bcl_bigdig(BclNumber\f[R] \f[I]n\f[R]\f[B], BclBigDig *\f[R]\f[I]result\f[R]\f[B])\f[…
686 Converts \f[I]n\f[R] into a \f[B]BclBigDig\f[R] and returns the result
687 in the space pointed to by \f[I]result\f[R].
690 \f[I]a\f[R] must be smaller than \f[B]BC_OVERFLOW_MAX\f[R].
691 See the \f[B]LIMITS\f[R] section.
693 If there was no error, \f[B]BCL_ERROR_NONE\f[R] is returned.
696 \f[B]BCL_ERROR_INVALID_NUM\f[R]
698 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
700 \f[B]BCL_ERROR_MATH_OVERFLOW\f[R]
702 \f[I]n\f[R] is consumed; it cannot be used after the call.
703 See the \f[B]Consumption and Propagation\f[R] subsection below.
706 \f[B]BclError bcl_bigdig_keep(BclNumber\f[R] \f[I]n\f[R]\f[B], BclBigDig *\f[R]\f[I]result\f[R]\f[B…
707 Converts \f[I]n\f[R] into a \f[B]BclBigDig\f[R] and returns the result
708 in the space pointed to by \f[I]result\f[R].
711 \f[I]a\f[R] must be smaller than \f[B]BC_OVERFLOW_MAX\f[R].
712 See the \f[B]LIMITS\f[R] section.
714 If there was no error, \f[B]BCL_ERROR_NONE\f[R] is returned.
717 \f[B]BCL_ERROR_INVALID_NUM\f[R]
719 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
721 \f[B]BCL_ERROR_MATH_OVERFLOW\f[R]
724 \f[B]BclNumber bcl_bigdig2num(BclBigDig\f[R] \f[I]val\f[R]\f[B])\f[R]
725 Creates a \f[B]BclNumber\f[R] from \f[I]val\f[R].
729 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
732 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
734 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
739 All procedures in this section without the \f[B]_keep\f[R] suffix in
740 their name consume the given \f[B]BclNumber\f[R] arguments that are not
742 See the \f[B]Consumption and Propagation\f[R] subsection below.
746 \f[B]BCL_ERROR_INVALID_NUM\f[R]
748 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
750 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
752 \f[B]BclNumber bcl_add(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[R]
753 Adds \f[I]a\f[R] and \f[I]b\f[R] and returns the result.
754 The \f[I]scale\f[R] of the result is the max of the \f[I]scale\f[R]s of
755 \f[I]a\f[R] and \f[I]b\f[R].
758 \f[I]a\f[R] and \f[I]b\f[R] are consumed; they cannot be used after the
760 See the \f[B]Consumption and Propagation\f[R] subsection below.
762 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
765 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
768 \f[B]BCL_ERROR_INVALID_NUM\f[R]
770 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
772 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
775 \f[B]BclNumber bcl_add_keep(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[R]
776 Adds \f[I]a\f[R] and \f[I]b\f[R] and returns the result.
777 The \f[I]scale\f[R] of the result is the max of the \f[I]scale\f[R]s of
778 \f[I]a\f[R] and \f[I]b\f[R].
781 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
784 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
787 \f[B]BCL_ERROR_INVALID_NUM\f[R]
789 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
791 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
794 \f[B]BclNumber bcl_sub(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[R]
795 Subtracts \f[I]b\f[R] from \f[I]a\f[R] and returns the result.
796 The \f[I]scale\f[R] of the result is the max of the \f[I]scale\f[R]s of
797 \f[I]a\f[R] and \f[I]b\f[R].
800 \f[I]a\f[R] and \f[I]b\f[R] are consumed; they cannot be used after the
802 See the \f[B]Consumption and Propagation\f[R] subsection below.
804 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
807 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
810 \f[B]BCL_ERROR_INVALID_NUM\f[R]
812 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
814 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
817 \f[B]BclNumber bcl_sub_keep(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[R]
818 Subtracts \f[I]b\f[R] from \f[I]a\f[R] and returns the result.
819 The \f[I]scale\f[R] of the result is the max of the \f[I]scale\f[R]s of
820 \f[I]a\f[R] and \f[I]b\f[R].
823 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
826 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
829 \f[B]BCL_ERROR_INVALID_NUM\f[R]
831 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
833 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
836 \f[B]BclNumber bcl_mul(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[R]
837 Multiplies \f[I]a\f[R] and \f[I]b\f[R] and returns the result.
838 If \f[I]ascale\f[R] is the \f[I]scale\f[R] of \f[I]a\f[R] and
839 \f[I]bscale\f[R] is the \f[I]scale\f[R] of \f[I]b\f[R], the
840 \f[I]scale\f[R] of the result is equal to
841 \f[B]min(ascale+bscale,max(scale,ascale,bscale))\f[R], where
842 \f[B]min()\f[R] and \f[B]max()\f[R] return the obvious values.
845 \f[I]a\f[R] and \f[I]b\f[R] are consumed; they cannot be used after the
847 See the \f[B]Consumption and Propagation\f[R] subsection below.
849 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
852 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
855 \f[B]BCL_ERROR_INVALID_NUM\f[R]
857 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
859 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
862 \f[B]BclNumber bcl_mul_keep(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[R]
863 Multiplies \f[I]a\f[R] and \f[I]b\f[R] and returns the result.
864 If \f[I]ascale\f[R] is the \f[I]scale\f[R] of \f[I]a\f[R] and
865 \f[I]bscale\f[R] is the \f[I]scale\f[R] of \f[I]b\f[R], the
866 \f[I]scale\f[R] of the result is equal to
867 \f[B]min(ascale+bscale,max(scale,ascale,bscale))\f[R], where
868 \f[B]min()\f[R] and \f[B]max()\f[R] return the obvious values.
871 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
874 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
877 \f[B]BCL_ERROR_INVALID_NUM\f[R]
879 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
881 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
884 \f[B]BclNumber bcl_div(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[R]
885 Divides \f[I]a\f[R] by \f[I]b\f[R] and returns the result.
886 The \f[I]scale\f[R] of the result is the \f[I]scale\f[R] of the current
890 \f[I]b\f[R] cannot be \f[B]0\f[R].
892 \f[I]a\f[R] and \f[I]b\f[R] are consumed; they cannot be used after the
894 See the \f[B]Consumption and Propagation\f[R] subsection below.
896 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
899 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
902 \f[B]BCL_ERROR_INVALID_NUM\f[R]
904 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
906 \f[B]BCL_ERROR_MATH_DIVIDE_BY_ZERO\f[R]
908 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
911 \f[B]BclNumber bcl_div_keep(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[R]
912 Divides \f[I]a\f[R] by \f[I]b\f[R] and returns the result.
913 The \f[I]scale\f[R] of the result is the \f[I]scale\f[R] of the current
917 \f[I]b\f[R] cannot be \f[B]0\f[R].
919 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
922 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
925 \f[B]BCL_ERROR_INVALID_NUM\f[R]
927 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
929 \f[B]BCL_ERROR_MATH_DIVIDE_BY_ZERO\f[R]
931 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
934 \f[B]BclNumber bcl_mod(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[R]
935 Divides \f[I]a\f[R] by \f[I]b\f[R] to the \f[I]scale\f[R] of the current
936 context, computes the modulus \f[B]a\-(a/b)*b\f[R], and returns the
940 \f[I]b\f[R] cannot be \f[B]0\f[R].
942 \f[I]a\f[R] and \f[I]b\f[R] are consumed; they cannot be used after the
944 See the \f[B]Consumption and Propagation\f[R] subsection below.
946 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
949 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
952 \f[B]BCL_ERROR_INVALID_NUM\f[R]
954 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
956 \f[B]BCL_ERROR_MATH_DIVIDE_BY_ZERO\f[R]
958 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
961 \f[B]BclNumber bcl_mod_keep(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[R]
962 Divides \f[I]a\f[R] by \f[I]b\f[R] to the \f[I]scale\f[R] of the current
963 context, computes the modulus \f[B]a\-(a/b)*b\f[R], and returns the
967 \f[I]b\f[R] cannot be \f[B]0\f[R].
969 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
972 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
975 \f[B]BCL_ERROR_INVALID_NUM\f[R]
977 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
979 \f[B]BCL_ERROR_MATH_DIVIDE_BY_ZERO\f[R]
981 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
984 \f[B]BclNumber bcl_pow(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[R]
985 Calculates \f[I]a\f[R] to the power of \f[I]b\f[R] to the
986 \f[I]scale\f[R] of the current context.
987 \f[I]b\f[R] must be an integer, but can be negative.
988 If it is negative, \f[I]a\f[R] must be non\-zero.
991 \f[I]b\f[R] must be an integer.
992 If \f[I]b\f[R] is negative, \f[I]a\f[R] must not be \f[B]0\f[R].
994 \f[I]a\f[R] must be smaller than \f[B]BC_OVERFLOW_MAX\f[R].
995 See the \f[B]LIMITS\f[R] section.
997 \f[I]a\f[R] and \f[I]b\f[R] are consumed; they cannot be used after the
999 See the \f[B]Consumption and Propagation\f[R] subsection below.
1001 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
1004 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1007 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1009 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1011 \f[B]BCL_ERROR_MATH_NON_INTEGER\f[R]
1013 \f[B]BCL_ERROR_MATH_OVERFLOW\f[R]
1015 \f[B]BCL_ERROR_MATH_DIVIDE_BY_ZERO\f[R]
1017 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1020 \f[B]BclNumber bcl_pow_keep(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[R]
1021 Calculates \f[I]a\f[R] to the power of \f[I]b\f[R] to the
1022 \f[I]scale\f[R] of the current context.
1023 \f[I]b\f[R] must be an integer, but can be negative.
1024 If it is negative, \f[I]a\f[R] must be non\-zero.
1027 \f[I]b\f[R] must be an integer.
1028 If \f[I]b\f[R] is negative, \f[I]a\f[R] must not be \f[B]0\f[R].
1030 \f[I]a\f[R] must be smaller than \f[B]BC_OVERFLOW_MAX\f[R].
1031 See the \f[B]LIMITS\f[R] section.
1033 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
1036 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1039 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1041 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1043 \f[B]BCL_ERROR_MATH_NON_INTEGER\f[R]
1045 \f[B]BCL_ERROR_MATH_OVERFLOW\f[R]
1047 \f[B]BCL_ERROR_MATH_DIVIDE_BY_ZERO\f[R]
1049 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1052 \f[B]BclNumber bcl_lshift(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[R]
1053 Shifts \f[I]a\f[R] left (moves the radix right) by \f[I]b\f[R] places
1056 \f[I]b\f[R] must be an integer.
1059 \f[I]b\f[R] must be an integer.
1061 \f[I]a\f[R] and \f[I]b\f[R] are consumed; they cannot be used after the
1063 See the \f[B]Consumption and Propagation\f[R] subsection below.
1065 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
1068 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1071 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1073 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1075 \f[B]BCL_ERROR_MATH_NON_INTEGER\f[R]
1077 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1080 \f[B]BclNumber bcl_lshift_keep(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[…
1081 Shifts \f[I]a\f[R] left (moves the radix right) by \f[I]b\f[R] places
1084 \f[I]b\f[R] must be an integer.
1087 \f[I]b\f[R] must be an integer.
1089 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
1092 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1095 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1097 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1099 \f[B]BCL_ERROR_MATH_NON_INTEGER\f[R]
1101 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1104 \f[B]BclNumber bcl_rshift(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[R]
1105 Shifts \f[I]a\f[R] right (moves the radix left) by \f[I]b\f[R] places
1108 \f[I]b\f[R] must be an integer.
1111 \f[I]b\f[R] must be an integer.
1113 \f[I]a\f[R] and \f[I]b\f[R] are consumed; they cannot be used after the
1115 See the \f[B]Consumption and Propagation\f[R] subsection below.
1117 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
1120 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1123 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1125 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1127 \f[B]BCL_ERROR_MATH_NON_INTEGER\f[R]
1129 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1132 \f[B]BclNumber bcl_rshift_keep(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[…
1133 Shifts \f[I]a\f[R] right (moves the radix left) by \f[I]b\f[R] places
1136 \f[I]b\f[R] must be an integer.
1139 \f[I]b\f[R] must be an integer.
1141 \f[I]a\f[R] and \f[I]b\f[R] can be the same number.
1144 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1147 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1149 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1151 \f[B]BCL_ERROR_MATH_NON_INTEGER\f[R]
1153 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1156 \f[B]BclNumber bcl_sqrt(BclNumber\f[R] \f[I]a\f[R]\f[B])\f[R]
1157 Calculates the square root of \f[I]a\f[R] and returns the result.
1158 The \f[I]scale\f[R] of the result is equal to the \f[B]scale\f[R] of the
1162 \f[I]a\f[R] cannot be negative.
1164 \f[I]a\f[R] is consumed; it cannot be used after the call.
1165 See the \f[B]Consumption and Propagation\f[R] subsection below.
1168 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1171 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1173 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1175 \f[B]BCL_ERROR_MATH_NEGATIVE\f[R]
1177 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1180 \f[B]BclNumber bcl_sqrt_keep(BclNumber\f[R] \f[I]a\f[R]\f[B])\f[R]
1181 Calculates the square root of \f[I]a\f[R] and returns the result.
1182 The \f[I]scale\f[R] of the result is equal to the \f[B]scale\f[R] of the
1186 \f[I]a\f[R] cannot be negative.
1189 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1192 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1194 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1196 \f[B]BCL_ERROR_MATH_NEGATIVE\f[R]
1198 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1201 …d(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B], BclNumber *\f[R]\f[I]c\f[R]\f[…
1202 Divides \f[I]a\f[R] by \f[I]b\f[R] and returns the quotient in a new
1203 number which is put into the space pointed to by \f[I]c\f[R], and puts
1205 \f[I]d\f[R].
1208 \f[I]b\f[R] cannot be \f[B]0\f[R].
1210 \f[I]a\f[R] and \f[I]b\f[R] are consumed; they cannot be used after the
1212 See the \f[B]Consumption and Propagation\f[R] subsection below.
1214 \f[I]c\f[R] and \f[I]d\f[R] cannot point to the same place, nor can they
1215 point to the space occupied by \f[I]a\f[R] or \f[I]b\f[R].
1217 If there was no error, \f[B]BCL_ERROR_NONE\f[R] is returned.
1220 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1222 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1224 \f[B]BCL_ERROR_MATH_DIVIDE_BY_ZERO\f[R]
1226 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1229 …p(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B], BclNumber *\f[R]\f[I]c\f[R]\f[…
1230 Divides \f[I]a\f[R] by \f[I]b\f[R] and returns the quotient in a new
1231 number which is put into the space pointed to by \f[I]c\f[R], and puts
1233 \f[I]d\f[R].
1236 \f[I]b\f[R] cannot be \f[B]0\f[R].
1238 \f[I]c\f[R] and \f[I]d\f[R] cannot point to the same place, nor can they
1239 point to the space occupied by \f[I]a\f[R] or \f[I]b\f[R].
1241 If there was no error, \f[B]BCL_ERROR_NONE\f[R] is returned.
1244 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1246 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1248 \f[B]BCL_ERROR_MATH_DIVIDE_BY_ZERO\f[R]
1250 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1253 …lNumber bcl_modexp(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B], BclNumber\f[R…
1254 Computes a modular exponentiation where \f[I]a\f[R] is the base,
1255 \f[I]b\f[R] is the exponent, and \f[I]c\f[R] is the modulus, and returns
1257 The \f[I]scale\f[R] of the result is equal to the \f[B]scale\f[R] of the
1261 \f[I]a\f[R], \f[I]b\f[R], and \f[I]c\f[R] must be integers.
1262 \f[I]c\f[R] must not be \f[B]0\f[R].
1263 \f[I]b\f[R] must not be negative.
1265 \f[I]a\f[R], \f[I]b\f[R], and \f[I]c\f[R] are consumed; they cannot be
1267 See the \f[B]Consumption and Propagation\f[R] subsection below.
1270 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1273 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1275 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1277 \f[B]BCL_ERROR_MATH_NEGATIVE\f[R]
1279 \f[B]BCL_ERROR_MATH_NON_INTEGER\f[R]
1281 \f[B]BCL_ERROR_MATH_DIVIDE_BY_ZERO\f[R]
1283 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1286 …er bcl_modexp_keep(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B], BclNumber\f[R…
1287 Computes a modular exponentiation where \f[I]a\f[R] is the base,
1288 \f[I]b\f[R] is the exponent, and \f[I]c\f[R] is the modulus, and returns
1290 The \f[I]scale\f[R] of the result is equal to the \f[B]scale\f[R] of the
1294 \f[I]a\f[R], \f[I]b\f[R], and \f[I]c\f[R] must be integers.
1295 \f[I]c\f[R] must not be \f[B]0\f[R].
1296 \f[I]b\f[R] must not be negative.
1299 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1302 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1304 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1306 \f[B]BCL_ERROR_MATH_NEGATIVE\f[R]
1308 \f[B]BCL_ERROR_MATH_NON_INTEGER\f[R]
1310 \f[B]BCL_ERROR_MATH_DIVIDE_BY_ZERO\f[R]
1312 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1316 \f[B]void bcl_zero(BclNumber\f[R] \f[I]n\f[R]\f[B])\f[R]
1317 Sets \f[I]n\f[R] to \f[B]0\f[R].
1319 \f[B]void bcl_one(BclNumber\f[R] \f[I]n\f[R]\f[B])\f[R]
1320 Sets \f[I]n\f[R] to \f[B]1\f[R].
1322 \f[B]ssize_t bcl_cmp(BclNumber\f[R] \f[I]a\f[R]\f[B], BclNumber\f[R] \f[I]b\f[R]\f[B])\f[R]
1323 Compares \f[I]a\f[R] and \f[I]b\f[R] and returns \f[B]0\f[R] if
1324 \f[I]a\f[R] and \f[I]b\f[R] are equal, \f[B]<0\f[R] if \f[I]a\f[R] is
1325 less than \f[I]b\f[R], and \f[B]>0\f[R] if \f[I]a\f[R] is greater than
1326 \f[I]b\f[R].
1328 \f[B]BclError bcl_copy(BclNumber\f[R] \f[I]d\f[R]\f[B], BclNumber\f[R] \f[I]s\f[R]\f[B])\f[R]
1329 Copies \f[I]s\f[R] into \f[I]d\f[R].
1332 If there was no error, \f[B]BCL_ERROR_NONE\f[R] is returned.
1335 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1337 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1339 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1342 \f[B]BclNumber bcl_dup(BclNumber\f[R] \f[I]s\f[R]\f[B])\f[R]
1343 Creates and returns a new \f[B]BclNumber\f[R] that is a copy of
1344 \f[I]s\f[R].
1348 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1351 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1353 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1355 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1358 The pseudo\-random number generator in bcl(3) is a \f[I]seeded\f[R]
1364 \f[B]/dev/urandom\f[R].
1365 If that fails, it seeds itself with by calling \f[B]libc\f[R]\[cq]s
1366 \f[B]srand(time(NULL))\f[R] and then calling \f[B]rand()\f[R] for each
1367 byte, since \f[B]rand()\f[R] is only guaranteed to return \f[B]15\f[R]
1376 \f[B]bcl_rand_seedWithNum(BclNumber)\f[R]
1379 char[\f[R]\f[I]BCL_SEED_SIZE\f[R]\f[B]])\f[R]
1381 \f[B]bcl_rand_reseed(\f[R]\f[I]void\f[R]\f[B])\f[R]
1383 All procedures in this section without the \f[B]_keep\f[R] suffix in
1384 their name consume the given \f[B]BclNumber\f[R] arguments that are not
1386 See the \f[B]Consumption and Propagation\f[R] subsection below.
1392 \f[B]BCL_SEED_ULONGS\f[R]
1393 The number of \f[B]unsigned long\f[R]\[cq]s in a seed for bcl(3)\[cq]s
1396 \f[B]BCL_SEED_SIZE\f[R]
1397 The size, in \f[B]char\f[R]\[cq]s, of a seed for bcl(3)\[cq]s random
1400 \f[B]BclBigDig\f[R]
1401 bcl(3)\[cq]s overflow type (see the \f[B]PERFORMANCE\f[R] section).
1403 \f[B]BclRandInt\f[R]
1407 \f[B]BclNumber bcl_irand(BclNumber\f[R] \f[I]a\f[R]\f[B])\f[R]
1408 Returns a random number that is not larger than \f[I]a\f[R] in a new
1410 If \f[I]a\f[R] is \f[B]0\f[R] or \f[B]1\f[R], the new number is equal to
1411 \f[B]0\f[R].
1413 \f[B]BclRandInt\f[R].
1418 \f[I]a\f[R] must be an integer and non\-negative.
1420 \f[I]a\f[R] is consumed; it cannot be used after the call.
1421 See the \f[B]Consumption and Propagation\f[R] subsection below.
1426 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1429 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1431 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1433 \f[B]BCL_ERROR_MATH_NEGATIVE\f[R]
1435 \f[B]BCL_ERROR_MATH_NON_INTEGER\f[R]
1437 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1440 \f[B]BclNumber bcl_irand_keep(BclNumber\f[R] \f[I]a\f[R]\f[B])\f[R]
1441 Returns a random number that is not larger than \f[I]a\f[R] in a new
1443 If \f[I]a\f[R] is \f[B]0\f[R] or \f[B]1\f[R], the new number is equal to
1444 \f[B]0\f[R].
1446 \f[B]BclRandInt\f[R].
1451 \f[I]a\f[R] must be an integer and non\-negative.
1456 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1459 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1461 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1463 \f[B]BCL_ERROR_MATH_NEGATIVE\f[R]
1465 \f[B]BCL_ERROR_MATH_NON_INTEGER\f[R]
1467 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1470 \f[B]BclNumber bcl_frand(size_t\f[R] \f[I]places\f[R]\f[B])\f[R]
1471 Returns a random number between \f[B]0\f[R] (inclusive) and \f[B]1\f[R]
1472 (exclusive) that has \f[I]places\f[R] decimal digits after the radix
1474 There are no limits on \f[I]places\f[R].
1480 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1483 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1485 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1488 \f[B]BclNumber bcl_ifrand(BclNumber\f[R] \f[I]a\f[R]\f[B], size_t\f[R] \f[I]places\f[R]\f[B])\f[R]
1489 Returns a random number less than \f[I]a\f[R] with \f[I]places\f[R]
1491 There are no limits on \f[I]a\f[R] or \f[I]places\f[R].
1494 \f[I]a\f[R] must be an integer and non\-negative.
1496 \f[I]a\f[R] is consumed; it cannot be used after the call.
1497 See the \f[B]Consumption and Propagation\f[R] subsection below.
1502 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1505 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1507 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1509 \f[B]BCL_ERROR_MATH_NEGATIVE\f[R]
1511 \f[B]BCL_ERROR_MATH_NON_INTEGER\f[R]
1513 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1516 \f[B]BclNumber bcl_ifrand_keep(BclNumber\f[R] \f[I]a\f[R]\f[B], size_t\f[R] \f[I]places\f[R]\f[B])\…
1517 Returns a random number less than \f[I]a\f[R] with \f[I]places\f[R]
1519 There are no limits on \f[I]a\f[R] or \f[I]places\f[R].
1522 \f[I]a\f[R] must be an integer and non\-negative.
1527 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1530 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1532 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1534 \f[B]BCL_ERROR_MATH_NEGATIVE\f[R]
1536 \f[B]BCL_ERROR_MATH_NON_INTEGER\f[R]
1538 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1541 \f[B]BclError bcl_rand_seedWithNum(BclNumber\f[R] \f[I]n\f[R]\f[B])\f[R]
1542 Seeds the PRNG with \f[I]n\f[R].
1545 \f[I]n\f[R] is consumed.
1549 If there was no error, \f[B]BCL_ERROR_NONE\f[R] is returned.
1552 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1554 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1556 Note that if \f[B]bcl_rand_seed2num(\f[R]\f[I]void\f[R]\f[B])\f[R] or
1557 \f[B]bcl_rand_seed2num_err(BclNumber)\f[R] are called right after this
1559 \f[I]n\f[R].
1562 \f[B]BclError bcl_rand_seedWithNum_keep(BclNumber\f[R] \f[I]n\f[R]\f[B])\f[R]
1563 Seeds the PRNG with \f[I]n\f[R].
1568 If there was no error, \f[B]BCL_ERROR_NONE\f[R] is returned.
1571 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1573 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1575 Note that if \f[B]bcl_rand_seed2num(\f[R]\f[I]void\f[R]\f[B])\f[R] or
1576 \f[B]bcl_rand_seed2num_err(BclNumber)\f[R] are called right after this
1578 \f[I]n\f[R].
1581 \f[B]BclError bcl_rand_seed(unsigned char\f[R] \f[I]seed\f[R]\f[B][\f[R]\f[I]BCL_SEED_SIZE\f[R]\f[B…
1582 Seeds the PRNG with the bytes in \f[I]seed\f[R].
1585 If there was no error, \f[B]BCL_ERROR_NONE\f[R] is returned.
1588 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1591 \f[B]void bcl_rand_reseed(\f[R]\f[I]void\f[R]\f[B])\f[R]
1593 First, it attempts to read data from \f[B]/dev/urandom\f[R] and falls
1594 back to \f[B]libc\f[R]\[cq]s \f[B]rand()\f[R].
1600 \f[B]BclNumber bcl_rand_seed2num(\f[R]\f[I]void\f[R]\f[B])\f[R]
1601 Returns the current seed of the PRNG as a \f[B]BclNumber\f[R].
1607 The error can be queried with \f[B]bcl_err(BclNumber)\f[R].
1610 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1612 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1615 \f[B]BclRandInt bcl_rand_int(\f[R]\f[I]void\f[R]\f[B])\f[R]
1616 Returns a random integer between \f[B]0\f[R] and \f[B]BC_RAND_MAX\f[R]
1623 \f[B]BclRandInt bcl_rand_bounded(BclRandInt\f[R] \f[I]bound\f[R]\f[B])\f[R]
1624 Returns a random integer between \f[B]0\f[R] and \f[I]bound\f[R]
1643 leaked until reclaimed with \f[B]bcl_ctxt_freeNums(BclContext)\f[R].
1646 The result should always be checked with \f[B]bcl_err(BclNumber)\f[R],
1657 error codes defined in \f[B]BclError\f[R].
1660 \f[B]BCL_ERROR_NONE\f[R]
1663 \f[B]BCL_ERROR_INVALID_NUM\f[R]
1664 An invalid \f[B]BclNumber\f[R] was given as a parameter.
1666 \f[B]BCL_ERROR_INVALID_CONTEXT\f[R]
1667 An invalid \f[B]BclContext\f[R] is being used.
1669 \f[B]BCL_ERROR_MATH_NEGATIVE\f[R]
1673 \f[B]BCL_ERROR_MATH_NON_INTEGER\f[R]
1676 \f[B]bcl_num_pow()\f[R].
1678 \f[B]BCL_ERROR_MATH_OVERFLOW\f[R]
1680 as for converting a \f[B]BclNumber\f[R] to a \f[B]BclBigDig\f[R].
1682 \f[B]BCL_ERROR_MATH_DIVIDE_BY_ZERO\f[R]
1685 \f[B]BCL_ERROR_PARSE_INVALID_STR\f[R]
1695 There is one exception to the above: one lowercase \f[B]e\f[R] is
1697 If the letter \f[B]e\f[R] exists, the number is considered to be in
1698 scientific notation, where the part before the \f[B]e\f[R] is the
1700 There can be a dash right after the \f[B]e\f[R] to indicate a negative
1703 \f[B]WARNING\f[R]: Both the number and the exponent in scientific
1704 notation are interpreted according to the current \f[B]ibase\f[R], but
1705 the number is still multiplied by \f[B]10\[ha]exponent\f[R] regardless
1706 of the current \f[B]ibase\f[R].
1707 For example, if \f[B]ibase\f[R] is \f[B]16\f[R] and bcl(3) is given the
1708 number string \f[B]FFeA\f[R], the resulting decimal number will be
1709 \f[B]2550000000000\f[R], and if bcl(3) is given the number string
1710 \f[B]10e\-4\f[R], the resulting decimal number will be \f[B]0.0016\f[R].
1713 \f[B]BCL_ERROR_FATAL_ALLOC_ERR\f[R]
1717 If clients call \f[B]bcl_setAbortOnFatalError()\f[R] with an
1718 \f[B]true\f[R] argument, this error will cause bcl(3) to throw a
1719 \f[B]SIGABRT\f[R].
1721 with a \f[B]false\f[R] argument.
1724 It is highly recommended that client libraries do \f[I]not\f[R] activate
1728 \f[B]BCL_ERROR_FATAL_UNKNOWN_ERR\f[R]
1732 If clients call \f[B]bcl_setAbortOnFatalError()\f[R] with an
1733 \f[B]true\f[R] argument, this error will cause bcl(3) to throw a
1734 \f[B]SIGABRT\f[R].
1736 with a \f[B]false\f[R] argument.
1739 It is highly recommended that client libraries do \f[I]not\f[R] activate
1743 bcl(3) is \f[I]MT\-Safe\f[R]: it is safe to call any functions from more
1745 However, is is \f[I]not\f[R] safe to pass any data between threads
1746 except for strings returned by \f[B]bcl_string()\f[R].
1748 bcl(3) is not \f[I]async\-signal\-safe\f[R].
1754 Most bc(1) implementations use \f[B]char\f[R] types to calculate the
1755 value of \f[B]1\f[R] decimal digit at a time, but that can be slow.
1758 It uses large integers to calculate more than \f[B]1\f[R] decimal digit
1760 If built in a environment where \f[B]BC_LONG_BIT\f[R] (see the
1761 \f[B]LIMITS\f[R] section) is \f[B]64\f[R], then each integer has
1762 \f[B]9\f[R] decimal digits.
1763 If built in an environment where \f[B]BC_LONG_BIT\f[R] is \f[B]32\f[R]
1764 then each integer has \f[B]4\f[R] decimal digits.
1766 \f[B]BC_BASE_DIGS\f[R].
1770 This integer type depends on the value of \f[B]BC_LONG_BIT\f[R], but is
1775 \f[B]BC_LONG_BIT\f[R]
1776 The number of bits in the \f[B]long\f[R] type in the environment where
1779 integer (see the \f[B]PERFORMANCE\f[R] section).
1781 \f[B]BC_BASE_DIGS\f[R]
1783 \f[B]PERFORMANCE\f[R] section).
1784 Depends on \f[B]BC_LONG_BIT\f[R].
1786 \f[B]BC_BASE_POW\f[R]
1788 \f[B]BC_BASE_DIGS\f[R]) plus \f[B]1\f[R].
1789 Depends on \f[B]BC_BASE_DIGS\f[R].
1791 \f[B]BC_OVERFLOW_MAX\f[R]
1792 The max number that the overflow type (see the \f[B]PERFORMANCE\f[R]
1794 Depends on \f[B]BC_LONG_BIT\f[R].
1796 \f[B]BC_BASE_MAX\f[R]
1798 Set at \f[B]BC_BASE_POW\f[R].
1800 \f[B]BC_SCALE_MAX\f[R]
1801 The maximum \f[B]scale\f[R].
1802 Set at \f[B]BC_OVERFLOW_MAX\-1\f[R].
1804 \f[B]BC_NUM_MAX\f[R]
1807 Set at \f[B]BC_OVERFLOW_MAX\-1\f[R].
1809 \f[B]BC_RAND_MAX\f[R]
1810 The maximum integer (inclusive) returned by the \f[B]bcl_rand_int()\f[R]
1812 Set at \f[B]2\[ha]BC_LONG_BIT\-1\f[R].
1816 Set at \f[B]BC_OVERFLOW_MAX\f[R].
1831 numbers that use a period (\f[B].\f[R]) as a radix point, regardless of
1832 the value of \f[B]LC_NUMERIC\f[R].