1*5a6e8488SAndroid Build Coastguard Worker<!--- 2*5a6e8488SAndroid Build Coastguard Worker 3*5a6e8488SAndroid Build Coastguard WorkerSPDX-License-Identifier: BSD-2-Clause 4*5a6e8488SAndroid Build Coastguard Worker 5*5a6e8488SAndroid Build Coastguard WorkerCopyright (c) 2018-2024 Gavin D. Howard and contributors. 6*5a6e8488SAndroid Build Coastguard Worker 7*5a6e8488SAndroid Build Coastguard WorkerRedistribution and use in source and binary forms, with or without 8*5a6e8488SAndroid Build Coastguard Workermodification, are permitted provided that the following conditions are met: 9*5a6e8488SAndroid Build Coastguard Worker 10*5a6e8488SAndroid Build Coastguard Worker* Redistributions of source code must retain the above copyright notice, this 11*5a6e8488SAndroid Build Coastguard Worker list of conditions and the following disclaimer. 12*5a6e8488SAndroid Build Coastguard Worker 13*5a6e8488SAndroid Build Coastguard Worker* Redistributions in binary form must reproduce the above copyright notice, 14*5a6e8488SAndroid Build Coastguard Worker this list of conditions and the following disclaimer in the documentation 15*5a6e8488SAndroid Build Coastguard Worker and/or other materials provided with the distribution. 16*5a6e8488SAndroid Build Coastguard Worker 17*5a6e8488SAndroid Build Coastguard WorkerTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18*5a6e8488SAndroid Build Coastguard WorkerAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19*5a6e8488SAndroid Build Coastguard WorkerIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20*5a6e8488SAndroid Build Coastguard WorkerARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21*5a6e8488SAndroid Build Coastguard WorkerLIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22*5a6e8488SAndroid Build Coastguard WorkerCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23*5a6e8488SAndroid Build Coastguard WorkerSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24*5a6e8488SAndroid Build Coastguard WorkerINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25*5a6e8488SAndroid Build Coastguard WorkerCONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26*5a6e8488SAndroid Build Coastguard WorkerARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27*5a6e8488SAndroid Build Coastguard WorkerPOSSIBILITY OF SUCH DAMAGE. 28*5a6e8488SAndroid Build Coastguard Worker 29*5a6e8488SAndroid Build Coastguard Worker--> 30*5a6e8488SAndroid Build Coastguard Worker 31*5a6e8488SAndroid Build Coastguard Worker# NAME 32*5a6e8488SAndroid Build Coastguard Worker 33*5a6e8488SAndroid Build Coastguard Workerbcl - library of arbitrary precision decimal arithmetic 34*5a6e8488SAndroid Build Coastguard Worker 35*5a6e8488SAndroid Build Coastguard Worker# SYNOPSIS 36*5a6e8488SAndroid Build Coastguard Worker 37*5a6e8488SAndroid Build Coastguard Worker## Use 38*5a6e8488SAndroid Build Coastguard Worker 39*5a6e8488SAndroid Build Coastguard Worker*#include <bcl.h>* 40*5a6e8488SAndroid Build Coastguard Worker 41*5a6e8488SAndroid Build Coastguard WorkerLink with *-lbcl*, and on POSIX systems, *-lpthread* is also required. 42*5a6e8488SAndroid Build Coastguard Worker 43*5a6e8488SAndroid Build Coastguard Worker## Setup 44*5a6e8488SAndroid Build Coastguard Worker 45*5a6e8488SAndroid Build Coastguard WorkerThese items allow clients to set up bcl(3). 46*5a6e8488SAndroid Build Coastguard Worker 47*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_start(**_void_**);** 48*5a6e8488SAndroid Build Coastguard Worker 49*5a6e8488SAndroid Build Coastguard Worker**void bcl_end(**_void_**);** 50*5a6e8488SAndroid Build Coastguard Worker 51*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_init(**_void_**);** 52*5a6e8488SAndroid Build Coastguard Worker 53*5a6e8488SAndroid Build Coastguard Worker**void bcl_free(**_void_**);** 54*5a6e8488SAndroid Build Coastguard Worker 55*5a6e8488SAndroid Build Coastguard Worker**bool bcl_abortOnFatalError(**_void_**);** 56*5a6e8488SAndroid Build Coastguard Worker 57*5a6e8488SAndroid Build Coastguard Worker**void bcl_setAbortOnFatalError(bool** _abrt_**);** 58*5a6e8488SAndroid Build Coastguard Worker 59*5a6e8488SAndroid Build Coastguard Worker**bool bcl_leadingZeroes(**_void_**);** 60*5a6e8488SAndroid Build Coastguard Worker 61*5a6e8488SAndroid Build Coastguard Worker**void bcl_setLeadingZeroes(bool** _leadingZeroes_**);** 62*5a6e8488SAndroid Build Coastguard Worker 63*5a6e8488SAndroid Build Coastguard Worker**void bcl_gc(**_void_**);** 64*5a6e8488SAndroid Build Coastguard Worker 65*5a6e8488SAndroid Build Coastguard Worker**bool bcl_digitClamp(**_void_**);** 66*5a6e8488SAndroid Build Coastguard Worker 67*5a6e8488SAndroid Build Coastguard Worker**void bcl_setDigitClamp(bool** _digitClamp_**);** 68*5a6e8488SAndroid Build Coastguard Worker 69*5a6e8488SAndroid Build Coastguard Worker## Contexts 70*5a6e8488SAndroid Build Coastguard Worker 71*5a6e8488SAndroid Build Coastguard WorkerThese items will allow clients to handle contexts, which are isolated from each 72*5a6e8488SAndroid Build Coastguard Workerother. This allows more than one client to use bcl(3) in the same program. 73*5a6e8488SAndroid Build Coastguard Worker 74*5a6e8488SAndroid Build Coastguard Worker**struct BclCtxt;** 75*5a6e8488SAndroid Build Coastguard Worker 76*5a6e8488SAndroid Build Coastguard Worker**typedef struct BclCtxt\* BclContext;** 77*5a6e8488SAndroid Build Coastguard Worker 78*5a6e8488SAndroid Build Coastguard Worker**BclContext bcl_ctxt_create(**_void_**);** 79*5a6e8488SAndroid Build Coastguard Worker 80*5a6e8488SAndroid Build Coastguard Worker**void bcl_ctxt_free(BclContext** _ctxt_**);** 81*5a6e8488SAndroid Build Coastguard Worker 82*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_pushContext(BclContext** _ctxt_**);** 83*5a6e8488SAndroid Build Coastguard Worker 84*5a6e8488SAndroid Build Coastguard Worker**void bcl_popContext(**_void_**);** 85*5a6e8488SAndroid Build Coastguard Worker 86*5a6e8488SAndroid Build Coastguard Worker**BclContext bcl_context(**_void_**);** 87*5a6e8488SAndroid Build Coastguard Worker 88*5a6e8488SAndroid Build Coastguard Worker**void bcl_ctxt_freeNums(BclContext** _ctxt_**);** 89*5a6e8488SAndroid Build Coastguard Worker 90*5a6e8488SAndroid Build Coastguard Worker**size_t bcl_ctxt_scale(BclContext** _ctxt_**);** 91*5a6e8488SAndroid Build Coastguard Worker 92*5a6e8488SAndroid Build Coastguard Worker**void bcl_ctxt_setScale(BclContext** _ctxt_**, size_t** _scale_**);** 93*5a6e8488SAndroid Build Coastguard Worker 94*5a6e8488SAndroid Build Coastguard Worker**size_t bcl_ctxt_ibase(BclContext** _ctxt_**);** 95*5a6e8488SAndroid Build Coastguard Worker 96*5a6e8488SAndroid Build Coastguard Worker**void bcl_ctxt_setIbase(BclContext** _ctxt_**, size_t** _ibase_**);** 97*5a6e8488SAndroid Build Coastguard Worker 98*5a6e8488SAndroid Build Coastguard Worker**size_t bcl_ctxt_obase(BclContext** _ctxt_**);** 99*5a6e8488SAndroid Build Coastguard Worker 100*5a6e8488SAndroid Build Coastguard Worker**void bcl_ctxt_setObase(BclContext** _ctxt_**, size_t** _obase_**);** 101*5a6e8488SAndroid Build Coastguard Worker 102*5a6e8488SAndroid Build Coastguard Worker## Errors 103*5a6e8488SAndroid Build Coastguard Worker 104*5a6e8488SAndroid Build Coastguard WorkerThese items allow clients to handle errors. 105*5a6e8488SAndroid Build Coastguard Worker 106*5a6e8488SAndroid Build Coastguard Worker**typedef enum BclError BclError;** 107*5a6e8488SAndroid Build Coastguard Worker 108*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_err(BclNumber** _n_**);** 109*5a6e8488SAndroid Build Coastguard Worker 110*5a6e8488SAndroid Build Coastguard Worker## Numbers 111*5a6e8488SAndroid Build Coastguard Worker 112*5a6e8488SAndroid Build Coastguard WorkerThese items allow clients to manipulate and query the arbitrary-precision 113*5a6e8488SAndroid Build Coastguard Workernumbers managed by bcl(3). 114*5a6e8488SAndroid Build Coastguard Worker 115*5a6e8488SAndroid Build Coastguard Worker**typedef struct { size_t i; } BclNumber;** 116*5a6e8488SAndroid Build Coastguard Worker 117*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_num_create(**_void_**);** 118*5a6e8488SAndroid Build Coastguard Worker 119*5a6e8488SAndroid Build Coastguard Worker**void bcl_num_free(BclNumber** _n_**);** 120*5a6e8488SAndroid Build Coastguard Worker 121*5a6e8488SAndroid Build Coastguard Worker**bool bcl_num_neg(BclNumber** _n_**);** 122*5a6e8488SAndroid Build Coastguard Worker 123*5a6e8488SAndroid Build Coastguard Worker**void bcl_num_setNeg(BclNumber** _n_**, bool** _neg_**);** 124*5a6e8488SAndroid Build Coastguard Worker 125*5a6e8488SAndroid Build Coastguard Worker**size_t bcl_num_scale(BclNumber** _n_**);** 126*5a6e8488SAndroid Build Coastguard Worker 127*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_num_setScale(BclNumber** _n_**, size_t** _scale_**);** 128*5a6e8488SAndroid Build Coastguard Worker 129*5a6e8488SAndroid Build Coastguard Worker**size_t bcl_num_len(BclNumber** _n_**);** 130*5a6e8488SAndroid Build Coastguard Worker 131*5a6e8488SAndroid Build Coastguard Worker## Conversion 132*5a6e8488SAndroid Build Coastguard Worker 133*5a6e8488SAndroid Build Coastguard WorkerThese items allow clients to convert numbers into and from strings and integers. 134*5a6e8488SAndroid Build Coastguard Worker 135*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_parse(const char \*restrict** _val_**);** 136*5a6e8488SAndroid Build Coastguard Worker 137*5a6e8488SAndroid Build Coastguard Worker**char\* bcl_string(BclNumber** _n_**);** 138*5a6e8488SAndroid Build Coastguard Worker 139*5a6e8488SAndroid Build Coastguard Worker**char\* bcl_string_keep(BclNumber** _n_**);** 140*5a6e8488SAndroid Build Coastguard Worker 141*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_bigdig(BclNumber** _n_**, BclBigDig \***_result_**);** 142*5a6e8488SAndroid Build Coastguard Worker 143*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_bigdig_keep(BclNumber** _n_**, BclBigDig \***_result_**);** 144*5a6e8488SAndroid Build Coastguard Worker 145*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_bigdig2num(BclBigDig** _val_**);** 146*5a6e8488SAndroid Build Coastguard Worker 147*5a6e8488SAndroid Build Coastguard Worker## Math 148*5a6e8488SAndroid Build Coastguard Worker 149*5a6e8488SAndroid Build Coastguard WorkerThese items allow clients to run math on numbers. 150*5a6e8488SAndroid Build Coastguard Worker 151*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_add(BclNumber** _a_**, BclNumber** _b_**);** 152*5a6e8488SAndroid Build Coastguard Worker 153*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_add_keep(BclNumber** _a_**, BclNumber** _b_**);** 154*5a6e8488SAndroid Build Coastguard Worker 155*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_sub(BclNumber** _a_**, BclNumber** _b_**);** 156*5a6e8488SAndroid Build Coastguard Worker 157*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_sub_keep(BclNumber** _a_**, BclNumber** _b_**);** 158*5a6e8488SAndroid Build Coastguard Worker 159*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_mul(BclNumber** _a_**, BclNumber** _b_**);** 160*5a6e8488SAndroid Build Coastguard Worker 161*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_mul_keep(BclNumber** _a_**, BclNumber** _b_**);** 162*5a6e8488SAndroid Build Coastguard Worker 163*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_div(BclNumber** _a_**, BclNumber** _b_**);** 164*5a6e8488SAndroid Build Coastguard Worker 165*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_div_keep(BclNumber** _a_**, BclNumber** _b_**);** 166*5a6e8488SAndroid Build Coastguard Worker 167*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_mod(BclNumber** _a_**, BclNumber** _b_**);** 168*5a6e8488SAndroid Build Coastguard Worker 169*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_mod_keep(BclNumber** _a_**, BclNumber** _b_**);** 170*5a6e8488SAndroid Build Coastguard Worker 171*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_pow(BclNumber** _a_**, BclNumber** _b_**);** 172*5a6e8488SAndroid Build Coastguard Worker 173*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_pow_keep(BclNumber** _a_**, BclNumber** _b_**);** 174*5a6e8488SAndroid Build Coastguard Worker 175*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_lshift(BclNumber** _a_**, BclNumber** _b_**);** 176*5a6e8488SAndroid Build Coastguard Worker 177*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_lshift_keep(BclNumber** _a_**, BclNumber** _b_**);** 178*5a6e8488SAndroid Build Coastguard Worker 179*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_rshift(BclNumber** _a_**, BclNumber** _b_**);** 180*5a6e8488SAndroid Build Coastguard Worker 181*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_rshift_keep(BclNumber** _a_**, BclNumber** _b_**);** 182*5a6e8488SAndroid Build Coastguard Worker 183*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_sqrt(BclNumber** _a_**);** 184*5a6e8488SAndroid Build Coastguard Worker 185*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_sqrt_keep(BclNumber** _a_**);** 186*5a6e8488SAndroid Build Coastguard Worker 187*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_divmod(BclNumber** _a_**, BclNumber** _b_**, BclNumber \***_c_**, BclNumber \***_d_**);** 188*5a6e8488SAndroid Build Coastguard Worker 189*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_divmod_keep(BclNumber** _a_**, BclNumber** _b_**, BclNumber \***_c_**, BclNumber \***_d_**);** 190*5a6e8488SAndroid Build Coastguard Worker 191*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_modexp(BclNumber** _a_**, BclNumber** _b_**, BclNumber** _c_**);** 192*5a6e8488SAndroid Build Coastguard Worker 193*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_modexp_keep(BclNumber** _a_**, BclNumber** _b_**, BclNumber** _c_**);** 194*5a6e8488SAndroid Build Coastguard Worker 195*5a6e8488SAndroid Build Coastguard Worker## Miscellaneous 196*5a6e8488SAndroid Build Coastguard Worker 197*5a6e8488SAndroid Build Coastguard WorkerThese items are miscellaneous. 198*5a6e8488SAndroid Build Coastguard Worker 199*5a6e8488SAndroid Build Coastguard Worker**void bcl_zero(BclNumber** _n_**);** 200*5a6e8488SAndroid Build Coastguard Worker 201*5a6e8488SAndroid Build Coastguard Worker**void bcl_one(BclNumber** _n_**);** 202*5a6e8488SAndroid Build Coastguard Worker 203*5a6e8488SAndroid Build Coastguard Worker**ssize_t bcl_cmp(BclNumber** _a_**, BclNumber** _b_**);** 204*5a6e8488SAndroid Build Coastguard Worker 205*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_copy(BclNumber** _d_**, BclNumber** _s_**);** 206*5a6e8488SAndroid Build Coastguard Worker 207*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_dup(BclNumber** _s_**);** 208*5a6e8488SAndroid Build Coastguard Worker 209*5a6e8488SAndroid Build Coastguard Worker## Pseudo-Random Number Generator 210*5a6e8488SAndroid Build Coastguard Worker 211*5a6e8488SAndroid Build Coastguard WorkerThese items allow clients to manipulate the seeded pseudo-random number 212*5a6e8488SAndroid Build Coastguard Workergenerator in bcl(3). 213*5a6e8488SAndroid Build Coastguard Worker 214*5a6e8488SAndroid Build Coastguard Worker**#define BCL_SEED_ULONGS** 215*5a6e8488SAndroid Build Coastguard Worker 216*5a6e8488SAndroid Build Coastguard Worker**#define BCL_SEED_SIZE** 217*5a6e8488SAndroid Build Coastguard Worker 218*5a6e8488SAndroid Build Coastguard Worker**typedef unsigned long BclBigDig;** 219*5a6e8488SAndroid Build Coastguard Worker 220*5a6e8488SAndroid Build Coastguard Worker**typedef unsigned long BclRandInt;** 221*5a6e8488SAndroid Build Coastguard Worker 222*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_irand(BclNumber** _a_**);** 223*5a6e8488SAndroid Build Coastguard Worker 224*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_irand_keep(BclNumber** _a_**);** 225*5a6e8488SAndroid Build Coastguard Worker 226*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_frand(size_t** _places_**);** 227*5a6e8488SAndroid Build Coastguard Worker 228*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_ifrand(BclNumber** _a_**, size_t** _places_**);** 229*5a6e8488SAndroid Build Coastguard Worker 230*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_ifrand_keep(BclNumber** _a_**, size_t** _places_**);** 231*5a6e8488SAndroid Build Coastguard Worker 232*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_rand_seedWithNum(BclNumber** _n_**);** 233*5a6e8488SAndroid Build Coastguard Worker 234*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_rand_seedWithNum_keep(BclNumber** _n_**);** 235*5a6e8488SAndroid Build Coastguard Worker 236*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_rand_seed(unsigned char** _seed_**[**_BCL_SEED_SIZE_**]);** 237*5a6e8488SAndroid Build Coastguard Worker 238*5a6e8488SAndroid Build Coastguard Worker**void bcl_rand_reseed(**_void_**);** 239*5a6e8488SAndroid Build Coastguard Worker 240*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_rand_seed2num(**_void_**);** 241*5a6e8488SAndroid Build Coastguard Worker 242*5a6e8488SAndroid Build Coastguard Worker**BclRandInt bcl_rand_int(**_void_**);** 243*5a6e8488SAndroid Build Coastguard Worker 244*5a6e8488SAndroid Build Coastguard Worker**BclRandInt bcl_rand_bounded(BclRandInt** _bound_**);** 245*5a6e8488SAndroid Build Coastguard Worker 246*5a6e8488SAndroid Build Coastguard Worker# DESCRIPTION 247*5a6e8488SAndroid Build Coastguard Worker 248*5a6e8488SAndroid Build Coastguard Workerbcl(3) is a library that implements arbitrary-precision decimal math, as 249*5a6e8488SAndroid Build Coastguard Workerstandardized by POSIX 250*5a6e8488SAndroid Build Coastguard Worker(https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html) in bc(1). 251*5a6e8488SAndroid Build Coastguard Worker 252*5a6e8488SAndroid Build Coastguard Workerbcl(3) assumes that it is allowed to use the **bcl**, **Bcl**, **bc**, and 253*5a6e8488SAndroid Build Coastguard Worker**Bc** prefixes for symbol names without collision. 254*5a6e8488SAndroid Build Coastguard Worker 255*5a6e8488SAndroid Build Coastguard WorkerAll of the items in its interface are described below. See the documentation for 256*5a6e8488SAndroid Build Coastguard Workereach function for what each function can return. 257*5a6e8488SAndroid Build Coastguard Worker 258*5a6e8488SAndroid Build Coastguard Worker## Setup 259*5a6e8488SAndroid Build Coastguard Worker 260*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_start(**_void_**)** 261*5a6e8488SAndroid Build Coastguard Worker 262*5a6e8488SAndroid Build Coastguard Worker: Initializes this library. This function can be called multiple times, but 263*5a6e8488SAndroid Build Coastguard Worker **bcl_end()** must only be called *once*. This is to make it possible for 264*5a6e8488SAndroid Build Coastguard Worker multiple libraries and applications to initialize bcl(3) without problem. 265*5a6e8488SAndroid Build Coastguard Worker 266*5a6e8488SAndroid Build Coastguard Worker It is suggested that client libraries call this function, but do not call 267*5a6e8488SAndroid Build Coastguard Worker **bcl_end()**, and client applications should call both. 268*5a6e8488SAndroid Build Coastguard Worker 269*5a6e8488SAndroid Build Coastguard Worker If there was no error, **BCL_ERROR_NONE** is returned. Otherwise, this 270*5a6e8488SAndroid Build Coastguard Worker function can return: 271*5a6e8488SAndroid Build Coastguard Worker 272*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 273*5a6e8488SAndroid Build Coastguard Worker 274*5a6e8488SAndroid Build Coastguard Worker This function must be the first one clients call. Calling any other 275*5a6e8488SAndroid Build Coastguard Worker function without calling this one first is undefined behavior. 276*5a6e8488SAndroid Build Coastguard Worker 277*5a6e8488SAndroid Build Coastguard Worker**void bcl_end(**_void_**)** 278*5a6e8488SAndroid Build Coastguard Worker 279*5a6e8488SAndroid Build Coastguard Worker: Deinitializes this library. This function must only be called *once*. 280*5a6e8488SAndroid Build Coastguard Worker 281*5a6e8488SAndroid Build Coastguard Worker All data must have been freed before calling this function. 282*5a6e8488SAndroid Build Coastguard Worker 283*5a6e8488SAndroid Build Coastguard Worker This function must be the last one clients call. Calling this function 284*5a6e8488SAndroid Build Coastguard Worker before calling any other function is undefined behavior. 285*5a6e8488SAndroid Build Coastguard Worker 286*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_init(**_void_**)** 287*5a6e8488SAndroid Build Coastguard Worker 288*5a6e8488SAndroid Build Coastguard Worker: Initializes the library for the current thread. This function can be called 289*5a6e8488SAndroid Build Coastguard Worker multiple times, but each call must be matched by a call to 290*5a6e8488SAndroid Build Coastguard Worker **bcl_free(**_void_**)**. This is to make it possible for multiple libraries 291*5a6e8488SAndroid Build Coastguard Worker and applications to initialize threads for bcl(3) without problem. 292*5a6e8488SAndroid Build Coastguard Worker 293*5a6e8488SAndroid Build Coastguard Worker This function *must* be called from the thread that it is supposed to 294*5a6e8488SAndroid Build Coastguard Worker initialize. 295*5a6e8488SAndroid Build Coastguard Worker 296*5a6e8488SAndroid Build Coastguard Worker If there was no error, **BCL_ERROR_NONE** is returned. Otherwise, this 297*5a6e8488SAndroid Build Coastguard Worker function can return: 298*5a6e8488SAndroid Build Coastguard Worker 299*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 300*5a6e8488SAndroid Build Coastguard Worker 301*5a6e8488SAndroid Build Coastguard Worker This function must be the second one clients call. Calling any other 302*5a6e8488SAndroid Build Coastguard Worker function without calling **bcl_start()** and then this one first is 303*5a6e8488SAndroid Build Coastguard Worker undefined behavior, except in the case of new threads. New threads can 304*5a6e8488SAndroid Build Coastguard Worker safely call this function without calling **bcl_start()** if another thread 305*5a6e8488SAndroid Build Coastguard Worker has previously called **bcl_start()**. But this function must still be the 306*5a6e8488SAndroid Build Coastguard Worker first function in bcl(3) called by that new thread. 307*5a6e8488SAndroid Build Coastguard Worker 308*5a6e8488SAndroid Build Coastguard Worker**void bcl_free(**_void_**)** 309*5a6e8488SAndroid Build Coastguard Worker 310*5a6e8488SAndroid Build Coastguard Worker: Decrements bcl(3)'s reference count and frees the data associated with it if 311*5a6e8488SAndroid Build Coastguard Worker the reference count is **0**. 312*5a6e8488SAndroid Build Coastguard Worker 313*5a6e8488SAndroid Build Coastguard Worker This function *must* be called from the thread that it is supposed to 314*5a6e8488SAndroid Build Coastguard Worker deinitialize. 315*5a6e8488SAndroid Build Coastguard Worker 316*5a6e8488SAndroid Build Coastguard Worker This function must be the second to last one clients call. Calling this 317*5a6e8488SAndroid Build Coastguard Worker function before calling any other function besides **bcl_end()** is 318*5a6e8488SAndroid Build Coastguard Worker undefined behavior. 319*5a6e8488SAndroid Build Coastguard Worker 320*5a6e8488SAndroid Build Coastguard Worker**bool bcl_abortOnFatalError(**_void_**)** 321*5a6e8488SAndroid Build Coastguard Worker 322*5a6e8488SAndroid Build Coastguard Worker: Queries and returns the current state of calling **abort()** on fatal 323*5a6e8488SAndroid Build Coastguard Worker errors. If **true** is returned, bcl(3) will cause a **SIGABRT** if a fatal 324*5a6e8488SAndroid Build Coastguard Worker error occurs. 325*5a6e8488SAndroid Build Coastguard Worker 326*5a6e8488SAndroid Build Coastguard Worker If activated, clients do not need to check for fatal errors. 327*5a6e8488SAndroid Build Coastguard Worker 328*5a6e8488SAndroid Build Coastguard Worker This value is *thread-local*; it applies to just the thread it is read on. 329*5a6e8488SAndroid Build Coastguard Worker 330*5a6e8488SAndroid Build Coastguard Worker The default is **false**. 331*5a6e8488SAndroid Build Coastguard Worker 332*5a6e8488SAndroid Build Coastguard Worker**void bcl_setAbortOnFatalError(bool** _abrt_**)** 333*5a6e8488SAndroid Build Coastguard Worker 334*5a6e8488SAndroid Build Coastguard Worker: Sets the state of calling **abort()** on fatal errors. If *abrt* is 335*5a6e8488SAndroid Build Coastguard Worker **false**, bcl(3) will not cause a **SIGABRT** on fatal errors after the 336*5a6e8488SAndroid Build Coastguard Worker call. If *abrt* is **true**, bcl(3) will cause a **SIGABRT** on fatal errors 337*5a6e8488SAndroid Build Coastguard Worker after the call. 338*5a6e8488SAndroid Build Coastguard Worker 339*5a6e8488SAndroid Build Coastguard Worker This value is *thread-local*; it applies to just the thread it is set on. 340*5a6e8488SAndroid Build Coastguard Worker 341*5a6e8488SAndroid Build Coastguard Worker If activated, clients do not need to check for fatal errors. 342*5a6e8488SAndroid Build Coastguard Worker 343*5a6e8488SAndroid Build Coastguard Worker**bool bcl_leadingZeroes(**_void_**)** 344*5a6e8488SAndroid Build Coastguard Worker 345*5a6e8488SAndroid Build Coastguard Worker: Queries and returns the state of whether leading zeroes are added to strings 346*5a6e8488SAndroid Build Coastguard Worker returned by **bcl_string()** when numbers are greater than **-1**, less than 347*5a6e8488SAndroid Build Coastguard Worker **1**, and not equal to **0**. If **true** is returned, then leading zeroes 348*5a6e8488SAndroid Build Coastguard Worker will be added. 349*5a6e8488SAndroid Build Coastguard Worker 350*5a6e8488SAndroid Build Coastguard Worker This value is *thread-local*; it applies to just the thread it is read on. 351*5a6e8488SAndroid Build Coastguard Worker 352*5a6e8488SAndroid Build Coastguard Worker The default is **false**. 353*5a6e8488SAndroid Build Coastguard Worker 354*5a6e8488SAndroid Build Coastguard Worker**void bcl_setLeadingZeroes(bool** _leadingZeroes_**)** 355*5a6e8488SAndroid Build Coastguard Worker 356*5a6e8488SAndroid Build Coastguard Worker: Sets the state of whether leading zeroes are added to strings returned by 357*5a6e8488SAndroid Build Coastguard Worker **bcl_string()** when numbers are greater than **-1**, less than **1**, and 358*5a6e8488SAndroid Build Coastguard Worker not equal to **0**. If *leadingZeroes* is **true**, leading zeroes will be 359*5a6e8488SAndroid Build Coastguard Worker added to strings returned by **bcl_string()**. 360*5a6e8488SAndroid Build Coastguard Worker 361*5a6e8488SAndroid Build Coastguard Worker This value is *thread-local*; it applies to just the thread it is set on. 362*5a6e8488SAndroid Build Coastguard Worker 363*5a6e8488SAndroid Build Coastguard Worker**bool bcl_digitClamp(**_void_**)** 364*5a6e8488SAndroid Build Coastguard Worker 365*5a6e8488SAndroid Build Coastguard Worker: Queries and returns the state of whether digits in number strings that are 366*5a6e8488SAndroid Build Coastguard Worker greater than or equal to the current **ibase** are clamped or not. 367*5a6e8488SAndroid Build Coastguard Worker 368*5a6e8488SAndroid Build Coastguard Worker If **true** is returned, then digits are treated as though they are equal to 369*5a6e8488SAndroid Build Coastguard Worker the value of **ibase** minus **1**. If this is *not* true, then digits are 370*5a6e8488SAndroid Build Coastguard Worker treated as though they are equal to the value they would have if **ibase** 371*5a6e8488SAndroid Build Coastguard Worker was large enough. They are then multiplied by the appropriate power of 372*5a6e8488SAndroid Build Coastguard Worker **ibase**. 373*5a6e8488SAndroid Build Coastguard Worker 374*5a6e8488SAndroid Build Coastguard Worker For example, with clamping off and an **ibase** of **3**, the string "AB" 375*5a6e8488SAndroid Build Coastguard Worker would equal **3\^1\*A+3\^0\*B**, which is **3** times **10** plus **11**, or 376*5a6e8488SAndroid Build Coastguard Worker **41**, while with clamping on and an **ibase** of **3**, the string "AB" 377*5a6e8488SAndroid Build Coastguard Worker would be equal to **3\^1\*2+3\^0\*2**, which is **3** times **2** plus 378*5a6e8488SAndroid Build Coastguard Worker **2**, or **8**. 379*5a6e8488SAndroid Build Coastguard Worker 380*5a6e8488SAndroid Build Coastguard Worker This value is *thread-local*; it applies to just the thread it is read on. 381*5a6e8488SAndroid Build Coastguard Worker 382*5a6e8488SAndroid Build Coastguard Worker The default is **true**. 383*5a6e8488SAndroid Build Coastguard Worker 384*5a6e8488SAndroid Build Coastguard Worker**void bcl_setDigitClamp(bool** _digitClamp_**)** 385*5a6e8488SAndroid Build Coastguard Worker 386*5a6e8488SAndroid Build Coastguard Worker: Sets the state of whether digits in number strings that are greater than or 387*5a6e8488SAndroid Build Coastguard Worker equal to the current **ibase** are clamped or not. For more information, see 388*5a6e8488SAndroid Build Coastguard Worker the **bcl_digitClamp(**_void_**)** function. 389*5a6e8488SAndroid Build Coastguard Worker 390*5a6e8488SAndroid Build Coastguard Worker This value is *thread-local*; it applies to just the thread it is set on. 391*5a6e8488SAndroid Build Coastguard Worker 392*5a6e8488SAndroid Build Coastguard Worker**void bcl_gc(**_void_**)** 393*5a6e8488SAndroid Build Coastguard Worker 394*5a6e8488SAndroid Build Coastguard Worker: Garbage collects cached instances of arbitrary-precision numbers. This only 395*5a6e8488SAndroid Build Coastguard Worker frees the memory of numbers that are *not* in use, so it is safe to call at 396*5a6e8488SAndroid Build Coastguard Worker any time. 397*5a6e8488SAndroid Build Coastguard Worker 398*5a6e8488SAndroid Build Coastguard Worker## Contexts 399*5a6e8488SAndroid Build Coastguard Worker 400*5a6e8488SAndroid Build Coastguard WorkerAll procedures that take a **BclContext** parameter a require a valid context as 401*5a6e8488SAndroid Build Coastguard Workeran argument. 402*5a6e8488SAndroid Build Coastguard Worker 403*5a6e8488SAndroid Build Coastguard Worker**struct BclCtxt** 404*5a6e8488SAndroid Build Coastguard Worker 405*5a6e8488SAndroid Build Coastguard Worker: A forward declaration for a hidden **struct** type. Clients cannot access 406*5a6e8488SAndroid Build Coastguard Worker the internals of the **struct** type directly. All interactions with the 407*5a6e8488SAndroid Build Coastguard Worker type are done through pointers. See **BclContext** below. 408*5a6e8488SAndroid Build Coastguard Worker 409*5a6e8488SAndroid Build Coastguard Worker**BclContext** 410*5a6e8488SAndroid Build Coastguard Worker 411*5a6e8488SAndroid Build Coastguard Worker: A typedef to a pointer of **struct BclCtxt**. This is the only handle 412*5a6e8488SAndroid Build Coastguard Worker clients can get to **struct BclCtxt**. 413*5a6e8488SAndroid Build Coastguard Worker 414*5a6e8488SAndroid Build Coastguard Worker A **BclContext** contains the values **scale**, **ibase**, and **obase**, as 415*5a6e8488SAndroid Build Coastguard Worker well as a list of numbers. 416*5a6e8488SAndroid Build Coastguard Worker 417*5a6e8488SAndroid Build Coastguard Worker **scale** is a value used to control how many decimal places calculations 418*5a6e8488SAndroid Build Coastguard Worker should use. A value of **0** means that calculations are done on integers 419*5a6e8488SAndroid Build Coastguard Worker only, where applicable, and a value of 20, for example, means that all 420*5a6e8488SAndroid Build Coastguard Worker applicable calculations return results with 20 decimal places. The default 421*5a6e8488SAndroid Build Coastguard Worker is **0**. 422*5a6e8488SAndroid Build Coastguard Worker 423*5a6e8488SAndroid Build Coastguard Worker **ibase** is a value used to control the input base. The minimum **ibase** 424*5a6e8488SAndroid Build Coastguard Worker is **2**, and the maximum is **36**. If **ibase** is **2**, numbers are 425*5a6e8488SAndroid Build Coastguard Worker parsed as though they are in binary, and any digits larger than **1** are 426*5a6e8488SAndroid Build Coastguard Worker clamped. Likewise, a value of **10** means that numbers are parsed as though 427*5a6e8488SAndroid Build Coastguard Worker they are decimal, and any larger digits are clamped. The default is **10**. 428*5a6e8488SAndroid Build Coastguard Worker 429*5a6e8488SAndroid Build Coastguard Worker **obase** is a value used to control the output base. The minimum **obase** 430*5a6e8488SAndroid Build Coastguard Worker is **0** and the maximum is **BC_BASE_MAX** (see the **LIMITS** section). 431*5a6e8488SAndroid Build Coastguard Worker 432*5a6e8488SAndroid Build Coastguard Worker Numbers created in one context are not valid in another context. It is 433*5a6e8488SAndroid Build Coastguard Worker undefined behavior to use a number created in a different context. Contexts 434*5a6e8488SAndroid Build Coastguard Worker are meant to isolate the numbers used by different clients in the same 435*5a6e8488SAndroid Build Coastguard Worker application. 436*5a6e8488SAndroid Build Coastguard Worker 437*5a6e8488SAndroid Build Coastguard Worker Different threads also have different contexts, so any numbers created in 438*5a6e8488SAndroid Build Coastguard Worker one thread are not valid in another thread. To pass values between contexts 439*5a6e8488SAndroid Build Coastguard Worker and threads, use **bcl_string()** to produce a string to pass around, and 440*5a6e8488SAndroid Build Coastguard Worker use **bcl_parse()** to parse the string. It is suggested that the **obase** 441*5a6e8488SAndroid Build Coastguard Worker used to create the string be passed around with the string and used as the 442*5a6e8488SAndroid Build Coastguard Worker **ibase** for **bcl_parse()** to ensure that the number will be the same. 443*5a6e8488SAndroid Build Coastguard Worker 444*5a6e8488SAndroid Build Coastguard Worker**BclContext bcl_ctxt_create(**_void_**)** 445*5a6e8488SAndroid Build Coastguard Worker 446*5a6e8488SAndroid Build Coastguard Worker: Creates a context and returns it. Returns **NULL** if there was an error. 447*5a6e8488SAndroid Build Coastguard Worker 448*5a6e8488SAndroid Build Coastguard Worker**void bcl_ctxt_free(BclContext** _ctxt_**)** 449*5a6e8488SAndroid Build Coastguard Worker 450*5a6e8488SAndroid Build Coastguard Worker: Frees *ctxt*, after which it is no longer valid. It is undefined behavior to 451*5a6e8488SAndroid Build Coastguard Worker attempt to use an invalid context. 452*5a6e8488SAndroid Build Coastguard Worker 453*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_pushContext(BclContext** _ctxt_**)** 454*5a6e8488SAndroid Build Coastguard Worker 455*5a6e8488SAndroid Build Coastguard Worker: Pushes *ctxt* onto bcl(3)'s stack of contexts. *ctxt* must have been created 456*5a6e8488SAndroid Build Coastguard Worker with **bcl_ctxt_create(**_void_**)**. 457*5a6e8488SAndroid Build Coastguard Worker 458*5a6e8488SAndroid Build Coastguard Worker If there was no error, **BCL_ERROR_NONE** is returned. Otherwise, this 459*5a6e8488SAndroid Build Coastguard Worker function can return: 460*5a6e8488SAndroid Build Coastguard Worker 461*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 462*5a6e8488SAndroid Build Coastguard Worker 463*5a6e8488SAndroid Build Coastguard Worker There *must* be a valid context to do any arithmetic. 464*5a6e8488SAndroid Build Coastguard Worker 465*5a6e8488SAndroid Build Coastguard Worker**void bcl_popContext(**_void_**)** 466*5a6e8488SAndroid Build Coastguard Worker 467*5a6e8488SAndroid Build Coastguard Worker: Pops the current context off of the stack, if one exists. 468*5a6e8488SAndroid Build Coastguard Worker 469*5a6e8488SAndroid Build Coastguard Worker**BclContext bcl_context(**_void_**)** 470*5a6e8488SAndroid Build Coastguard Worker 471*5a6e8488SAndroid Build Coastguard Worker: Returns the current context, or **NULL** if no context exists. 472*5a6e8488SAndroid Build Coastguard Worker 473*5a6e8488SAndroid Build Coastguard Worker**void bcl_ctxt_freeNums(BclContext** _ctxt_**)** 474*5a6e8488SAndroid Build Coastguard Worker 475*5a6e8488SAndroid Build Coastguard Worker: Frees all numbers in use that are associated with *ctxt*. It is undefined 476*5a6e8488SAndroid Build Coastguard Worker behavior to attempt to use a number associated with *ctxt* after calling 477*5a6e8488SAndroid Build Coastguard Worker this procedure unless such numbers have been created with 478*5a6e8488SAndroid Build Coastguard Worker **bcl_num_create(**_void_**)** after calling this procedure. 479*5a6e8488SAndroid Build Coastguard Worker 480*5a6e8488SAndroid Build Coastguard Worker**size_t bcl_ctxt_scale(BclContext** _ctxt_**)** 481*5a6e8488SAndroid Build Coastguard Worker 482*5a6e8488SAndroid Build Coastguard Worker: Returns the **scale** for given context. 483*5a6e8488SAndroid Build Coastguard Worker 484*5a6e8488SAndroid Build Coastguard Worker**void bcl_ctxt_setScale(BclContext** _ctxt_**, size_t** _scale_**)** 485*5a6e8488SAndroid Build Coastguard Worker 486*5a6e8488SAndroid Build Coastguard Worker: Sets the **scale** for the given context to the argument *scale*. 487*5a6e8488SAndroid Build Coastguard Worker 488*5a6e8488SAndroid Build Coastguard Worker**size_t bcl_ctxt_ibase(BclContext** _ctxt_**)** 489*5a6e8488SAndroid Build Coastguard Worker 490*5a6e8488SAndroid Build Coastguard Worker: Returns the **ibase** for the given context. 491*5a6e8488SAndroid Build Coastguard Worker 492*5a6e8488SAndroid Build Coastguard Worker**void bcl_ctxt_setIbase(BclContext** _ctxt_**, size_t** _ibase_**)** 493*5a6e8488SAndroid Build Coastguard Worker 494*5a6e8488SAndroid Build Coastguard Worker: Sets the **ibase** for the given context to the argument *ibase*. If the 495*5a6e8488SAndroid Build Coastguard Worker argument *ibase* is invalid, it clamped, so an *ibase* of **0** or **1** is 496*5a6e8488SAndroid Build Coastguard Worker clamped to **2**, and any values above **36** are clamped to **36**. 497*5a6e8488SAndroid Build Coastguard Worker 498*5a6e8488SAndroid Build Coastguard Worker**size_t bcl_ctxt_obase(BclContext** _ctxt_**)** 499*5a6e8488SAndroid Build Coastguard Worker 500*5a6e8488SAndroid Build Coastguard Worker: Returns the **obase** for the given context. 501*5a6e8488SAndroid Build Coastguard Worker 502*5a6e8488SAndroid Build Coastguard Worker**void bcl_ctxt_setObase(BclContext** _ctxt_**, size_t** _obase_**)** 503*5a6e8488SAndroid Build Coastguard Worker 504*5a6e8488SAndroid Build Coastguard Worker: Sets the **obase** for the given context to the argument *obase*. 505*5a6e8488SAndroid Build Coastguard Worker 506*5a6e8488SAndroid Build Coastguard Worker## Errors 507*5a6e8488SAndroid Build Coastguard Worker 508*5a6e8488SAndroid Build Coastguard Worker**BclError** 509*5a6e8488SAndroid Build Coastguard Worker 510*5a6e8488SAndroid Build Coastguard Worker: An **enum** of possible error codes. See the **ERRORS** section for a 511*5a6e8488SAndroid Build Coastguard Worker complete listing the codes. 512*5a6e8488SAndroid Build Coastguard Worker 513*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_err(BclNumber** _n_**)** 514*5a6e8488SAndroid Build Coastguard Worker 515*5a6e8488SAndroid Build Coastguard Worker: Checks for errors in a **BclNumber**. All functions that can return a 516*5a6e8488SAndroid Build Coastguard Worker **BclNumber** can encode an error in the number, and this function will 517*5a6e8488SAndroid Build Coastguard Worker return the error, if any. If there was no error, it will return 518*5a6e8488SAndroid Build Coastguard Worker **BCL_ERROR_NONE**. 519*5a6e8488SAndroid Build Coastguard Worker 520*5a6e8488SAndroid Build Coastguard Worker There must be a valid current context. 521*5a6e8488SAndroid Build Coastguard Worker 522*5a6e8488SAndroid Build Coastguard Worker## Numbers 523*5a6e8488SAndroid Build Coastguard Worker 524*5a6e8488SAndroid Build Coastguard WorkerAll procedures in this section require a valid current context. 525*5a6e8488SAndroid Build Coastguard Worker 526*5a6e8488SAndroid Build Coastguard Worker**BclNumber** 527*5a6e8488SAndroid Build Coastguard Worker 528*5a6e8488SAndroid Build Coastguard Worker: A handle to an arbitrary-precision number. The actual number type is not 529*5a6e8488SAndroid Build Coastguard Worker exposed; the **BclNumber** handle is the only way clients can refer to 530*5a6e8488SAndroid Build Coastguard Worker instances of arbitrary-precision numbers. 531*5a6e8488SAndroid Build Coastguard Worker 532*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_num_create(**_void_**)** 533*5a6e8488SAndroid Build Coastguard Worker 534*5a6e8488SAndroid Build Coastguard Worker: Creates and returns a **BclNumber**. 535*5a6e8488SAndroid Build Coastguard Worker 536*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 537*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 538*5a6e8488SAndroid Build Coastguard Worker 539*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 540*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 541*5a6e8488SAndroid Build Coastguard Worker 542*5a6e8488SAndroid Build Coastguard Worker**void bcl_num_free(BclNumber** _n_**)** 543*5a6e8488SAndroid Build Coastguard Worker 544*5a6e8488SAndroid Build Coastguard Worker: Frees *n*. It is undefined behavior to use *n* after calling this function. 545*5a6e8488SAndroid Build Coastguard Worker 546*5a6e8488SAndroid Build Coastguard Worker**bool bcl_num_neg(BclNumber** _n_**)** 547*5a6e8488SAndroid Build Coastguard Worker 548*5a6e8488SAndroid Build Coastguard Worker: Returns **true** if *n* is negative, **false** otherwise. 549*5a6e8488SAndroid Build Coastguard Worker 550*5a6e8488SAndroid Build Coastguard Worker**void bcl_num_setNeg(BclNumber** _n_**, bool** _neg_**)** 551*5a6e8488SAndroid Build Coastguard Worker 552*5a6e8488SAndroid Build Coastguard Worker: Sets *n*'s sign to *neg*, where **true** is negative, and **false** is 553*5a6e8488SAndroid Build Coastguard Worker positive. 554*5a6e8488SAndroid Build Coastguard Worker 555*5a6e8488SAndroid Build Coastguard Worker**size_t bcl_num_scale(BclNumber** _n_**)** 556*5a6e8488SAndroid Build Coastguard Worker 557*5a6e8488SAndroid Build Coastguard Worker: Returns the *scale* of *n*. 558*5a6e8488SAndroid Build Coastguard Worker 559*5a6e8488SAndroid Build Coastguard Worker The *scale* of a number is the number of decimal places it has after the 560*5a6e8488SAndroid Build Coastguard Worker radix (decimal point). 561*5a6e8488SAndroid Build Coastguard Worker 562*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_num_setScale(BclNumber** _n_**, size_t** _scale_**)** 563*5a6e8488SAndroid Build Coastguard Worker 564*5a6e8488SAndroid Build Coastguard Worker: Sets the *scale* of *n* to the argument *scale*. If the argument *scale* is 565*5a6e8488SAndroid Build Coastguard Worker greater than the *scale* of *n*, *n* is extended. If the argument *scale* is 566*5a6e8488SAndroid Build Coastguard Worker less than the *scale* of *n*, *n* is truncated. 567*5a6e8488SAndroid Build Coastguard Worker 568*5a6e8488SAndroid Build Coastguard Worker If there was no error, **BCL_ERROR_NONE** is returned. Otherwise, this 569*5a6e8488SAndroid Build Coastguard Worker function can return: 570*5a6e8488SAndroid Build Coastguard Worker 571*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 572*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 573*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 574*5a6e8488SAndroid Build Coastguard Worker 575*5a6e8488SAndroid Build Coastguard Worker**size_t bcl_num_len(BclNumber** _n_**)** 576*5a6e8488SAndroid Build Coastguard Worker 577*5a6e8488SAndroid Build Coastguard Worker: Returns the number of *significant decimal digits* in *n*. 578*5a6e8488SAndroid Build Coastguard Worker 579*5a6e8488SAndroid Build Coastguard Worker## Conversion 580*5a6e8488SAndroid Build Coastguard Worker 581*5a6e8488SAndroid Build Coastguard WorkerAll procedures in this section require a valid current context. 582*5a6e8488SAndroid Build Coastguard Worker 583*5a6e8488SAndroid Build Coastguard WorkerAll procedures in this section without the **_keep** suffix in their name 584*5a6e8488SAndroid Build Coastguard Workerconsume the given **BclNumber** arguments that are not given to pointer 585*5a6e8488SAndroid Build Coastguard Workerarguments. See the **Consumption and Propagation** subsection below. 586*5a6e8488SAndroid Build Coastguard Worker 587*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_parse(const char \*restrict** _val_**)** 588*5a6e8488SAndroid Build Coastguard Worker 589*5a6e8488SAndroid Build Coastguard Worker: Parses a number string according to the current context's **ibase** and 590*5a6e8488SAndroid Build Coastguard Worker returns the resulting number. 591*5a6e8488SAndroid Build Coastguard Worker 592*5a6e8488SAndroid Build Coastguard Worker *val* must be non-**NULL** and a valid string. See 593*5a6e8488SAndroid Build Coastguard Worker **BCL_ERROR_PARSE_INVALID_STR** in the **ERRORS** section for more 594*5a6e8488SAndroid Build Coastguard Worker information. 595*5a6e8488SAndroid Build Coastguard Worker 596*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 597*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 598*5a6e8488SAndroid Build Coastguard Worker 599*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 600*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 601*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_PARSE_INVALID_STR** 602*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 603*5a6e8488SAndroid Build Coastguard Worker 604*5a6e8488SAndroid Build Coastguard Worker**char\* bcl_string(BclNumber** _n_**)** 605*5a6e8488SAndroid Build Coastguard Worker 606*5a6e8488SAndroid Build Coastguard Worker: Returns a string representation of *n* according the the current context's 607*5a6e8488SAndroid Build Coastguard Worker **ibase**. The string is dynamically allocated and must be freed by the 608*5a6e8488SAndroid Build Coastguard Worker caller. 609*5a6e8488SAndroid Build Coastguard Worker 610*5a6e8488SAndroid Build Coastguard Worker *n* is consumed; it cannot be used after the call. See the 611*5a6e8488SAndroid Build Coastguard Worker **Consumption and Propagation** subsection below. 612*5a6e8488SAndroid Build Coastguard Worker 613*5a6e8488SAndroid Build Coastguard Worker**char\* bcl_string_keep(BclNumber** _n_**)** 614*5a6e8488SAndroid Build Coastguard Worker 615*5a6e8488SAndroid Build Coastguard Worker: Returns a string representation of *n* according the the current context's 616*5a6e8488SAndroid Build Coastguard Worker **ibase**. The string is dynamically allocated and must be freed by the 617*5a6e8488SAndroid Build Coastguard Worker caller. 618*5a6e8488SAndroid Build Coastguard Worker 619*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_bigdig(BclNumber** _n_**, BclBigDig \***_result_**)** 620*5a6e8488SAndroid Build Coastguard Worker 621*5a6e8488SAndroid Build Coastguard Worker: Converts *n* into a **BclBigDig** and returns the result in the space 622*5a6e8488SAndroid Build Coastguard Worker pointed to by *result*. 623*5a6e8488SAndroid Build Coastguard Worker 624*5a6e8488SAndroid Build Coastguard Worker *a* must be smaller than **BC_OVERFLOW_MAX**. See the **LIMITS** section. 625*5a6e8488SAndroid Build Coastguard Worker 626*5a6e8488SAndroid Build Coastguard Worker If there was no error, **BCL_ERROR_NONE** is returned. Otherwise, this 627*5a6e8488SAndroid Build Coastguard Worker function can return: 628*5a6e8488SAndroid Build Coastguard Worker 629*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 630*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 631*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_OVERFLOW** 632*5a6e8488SAndroid Build Coastguard Worker 633*5a6e8488SAndroid Build Coastguard Worker *n* is consumed; it cannot be used after the call. See the 634*5a6e8488SAndroid Build Coastguard Worker **Consumption and Propagation** subsection below. 635*5a6e8488SAndroid Build Coastguard Worker 636*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_bigdig_keep(BclNumber** _n_**, BclBigDig \***_result_**)** 637*5a6e8488SAndroid Build Coastguard Worker 638*5a6e8488SAndroid Build Coastguard Worker: Converts *n* into a **BclBigDig** and returns the result in the space 639*5a6e8488SAndroid Build Coastguard Worker pointed to by *result*. 640*5a6e8488SAndroid Build Coastguard Worker 641*5a6e8488SAndroid Build Coastguard Worker *a* must be smaller than **BC_OVERFLOW_MAX**. See the **LIMITS** section. 642*5a6e8488SAndroid Build Coastguard Worker 643*5a6e8488SAndroid Build Coastguard Worker If there was no error, **BCL_ERROR_NONE** is returned. Otherwise, this 644*5a6e8488SAndroid Build Coastguard Worker function can return: 645*5a6e8488SAndroid Build Coastguard Worker 646*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 647*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 648*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_OVERFLOW** 649*5a6e8488SAndroid Build Coastguard Worker 650*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_bigdig2num(BclBigDig** _val_**)** 651*5a6e8488SAndroid Build Coastguard Worker 652*5a6e8488SAndroid Build Coastguard Worker: Creates a **BclNumber** from *val*. 653*5a6e8488SAndroid Build Coastguard Worker 654*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 655*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 656*5a6e8488SAndroid Build Coastguard Worker 657*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 658*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 659*5a6e8488SAndroid Build Coastguard Worker 660*5a6e8488SAndroid Build Coastguard Worker## Math 661*5a6e8488SAndroid Build Coastguard Worker 662*5a6e8488SAndroid Build Coastguard WorkerAll procedures in this section require a valid current context. 663*5a6e8488SAndroid Build Coastguard Worker 664*5a6e8488SAndroid Build Coastguard WorkerAll procedures in this section without the **_keep** suffix in their name 665*5a6e8488SAndroid Build Coastguard Workerconsume the given **BclNumber** arguments that are not given to pointer 666*5a6e8488SAndroid Build Coastguard Workerarguments. See the **Consumption and Propagation** subsection below. 667*5a6e8488SAndroid Build Coastguard Worker 668*5a6e8488SAndroid Build Coastguard WorkerAll procedures in this section can return the following errors: 669*5a6e8488SAndroid Build Coastguard Worker 670*5a6e8488SAndroid Build Coastguard Worker* **BCL_ERROR_INVALID_NUM** 671*5a6e8488SAndroid Build Coastguard Worker* **BCL_ERROR_INVALID_CONTEXT** 672*5a6e8488SAndroid Build Coastguard Worker* **BCL_ERROR_FATAL_ALLOC_ERR** 673*5a6e8488SAndroid Build Coastguard Worker 674*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_add(BclNumber** _a_**, BclNumber** _b_**)** 675*5a6e8488SAndroid Build Coastguard Worker 676*5a6e8488SAndroid Build Coastguard Worker: Adds *a* and *b* and returns the result. The *scale* of the result is the 677*5a6e8488SAndroid Build Coastguard Worker max of the *scale*s of *a* and *b*. 678*5a6e8488SAndroid Build Coastguard Worker 679*5a6e8488SAndroid Build Coastguard Worker *a* and *b* are consumed; they cannot be used after the call. See the 680*5a6e8488SAndroid Build Coastguard Worker **Consumption and Propagation** subsection below. 681*5a6e8488SAndroid Build Coastguard Worker 682*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 683*5a6e8488SAndroid Build Coastguard Worker 684*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 685*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 686*5a6e8488SAndroid Build Coastguard Worker 687*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 688*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 689*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 690*5a6e8488SAndroid Build Coastguard Worker 691*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_add_keep(BclNumber** _a_**, BclNumber** _b_**)** 692*5a6e8488SAndroid Build Coastguard Worker 693*5a6e8488SAndroid Build Coastguard Worker: Adds *a* and *b* and returns the result. The *scale* of the result is the 694*5a6e8488SAndroid Build Coastguard Worker max of the *scale*s of *a* and *b*. 695*5a6e8488SAndroid Build Coastguard Worker 696*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 697*5a6e8488SAndroid Build Coastguard Worker 698*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 699*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 700*5a6e8488SAndroid Build Coastguard Worker 701*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 702*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 703*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 704*5a6e8488SAndroid Build Coastguard Worker 705*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_sub(BclNumber** _a_**, BclNumber** _b_**)** 706*5a6e8488SAndroid Build Coastguard Worker 707*5a6e8488SAndroid Build Coastguard Worker: Subtracts *b* from *a* and returns the result. The *scale* of the result is 708*5a6e8488SAndroid Build Coastguard Worker the max of the *scale*s of *a* and *b*. 709*5a6e8488SAndroid Build Coastguard Worker 710*5a6e8488SAndroid Build Coastguard Worker *a* and *b* are consumed; they cannot be used after the call. See the 711*5a6e8488SAndroid Build Coastguard Worker **Consumption and Propagation** subsection below. 712*5a6e8488SAndroid Build Coastguard Worker 713*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 714*5a6e8488SAndroid Build Coastguard Worker 715*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 716*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 717*5a6e8488SAndroid Build Coastguard Worker 718*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 719*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 720*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 721*5a6e8488SAndroid Build Coastguard Worker 722*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_sub_keep(BclNumber** _a_**, BclNumber** _b_**)** 723*5a6e8488SAndroid Build Coastguard Worker 724*5a6e8488SAndroid Build Coastguard Worker: Subtracts *b* from *a* and returns the result. The *scale* of the result is 725*5a6e8488SAndroid Build Coastguard Worker the max of the *scale*s of *a* and *b*. 726*5a6e8488SAndroid Build Coastguard Worker 727*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 728*5a6e8488SAndroid Build Coastguard Worker 729*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 730*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 731*5a6e8488SAndroid Build Coastguard Worker 732*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 733*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 734*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 735*5a6e8488SAndroid Build Coastguard Worker 736*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_mul(BclNumber** _a_**, BclNumber** _b_**)** 737*5a6e8488SAndroid Build Coastguard Worker 738*5a6e8488SAndroid Build Coastguard Worker: Multiplies *a* and *b* and returns the result. If *ascale* is the *scale* of 739*5a6e8488SAndroid Build Coastguard Worker *a* and *bscale* is the *scale* of *b*, the *scale* of the result is equal 740*5a6e8488SAndroid Build Coastguard Worker to **min(ascale+bscale,max(scale,ascale,bscale))**, where **min()** and 741*5a6e8488SAndroid Build Coastguard Worker **max()** return the obvious values. 742*5a6e8488SAndroid Build Coastguard Worker 743*5a6e8488SAndroid Build Coastguard Worker *a* and *b* are consumed; they cannot be used after the call. See the 744*5a6e8488SAndroid Build Coastguard Worker **Consumption and Propagation** subsection below. 745*5a6e8488SAndroid Build Coastguard Worker 746*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 747*5a6e8488SAndroid Build Coastguard Worker 748*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 749*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 750*5a6e8488SAndroid Build Coastguard Worker 751*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 752*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 753*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 754*5a6e8488SAndroid Build Coastguard Worker 755*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_mul_keep(BclNumber** _a_**, BclNumber** _b_**)** 756*5a6e8488SAndroid Build Coastguard Worker 757*5a6e8488SAndroid Build Coastguard Worker: Multiplies *a* and *b* and returns the result. If *ascale* is the *scale* of 758*5a6e8488SAndroid Build Coastguard Worker *a* and *bscale* is the *scale* of *b*, the *scale* of the result is equal 759*5a6e8488SAndroid Build Coastguard Worker to **min(ascale+bscale,max(scale,ascale,bscale))**, where **min()** and 760*5a6e8488SAndroid Build Coastguard Worker **max()** return the obvious values. 761*5a6e8488SAndroid Build Coastguard Worker 762*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 763*5a6e8488SAndroid Build Coastguard Worker 764*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 765*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 766*5a6e8488SAndroid Build Coastguard Worker 767*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 768*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 769*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 770*5a6e8488SAndroid Build Coastguard Worker 771*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_div(BclNumber** _a_**, BclNumber** _b_**)** 772*5a6e8488SAndroid Build Coastguard Worker 773*5a6e8488SAndroid Build Coastguard Worker: Divides *a* by *b* and returns the result. The *scale* of the result is the 774*5a6e8488SAndroid Build Coastguard Worker *scale* of the current context. 775*5a6e8488SAndroid Build Coastguard Worker 776*5a6e8488SAndroid Build Coastguard Worker *b* cannot be **0**. 777*5a6e8488SAndroid Build Coastguard Worker 778*5a6e8488SAndroid Build Coastguard Worker *a* and *b* are consumed; they cannot be used after the call. See the 779*5a6e8488SAndroid Build Coastguard Worker **Consumption and Propagation** subsection below. 780*5a6e8488SAndroid Build Coastguard Worker 781*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 782*5a6e8488SAndroid Build Coastguard Worker 783*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 784*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 785*5a6e8488SAndroid Build Coastguard Worker 786*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 787*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 788*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_DIVIDE_BY_ZERO** 789*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 790*5a6e8488SAndroid Build Coastguard Worker 791*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_div_keep(BclNumber** _a_**, BclNumber** _b_**)** 792*5a6e8488SAndroid Build Coastguard Worker 793*5a6e8488SAndroid Build Coastguard Worker: Divides *a* by *b* and returns the result. The *scale* of the result is the 794*5a6e8488SAndroid Build Coastguard Worker *scale* of the current context. 795*5a6e8488SAndroid Build Coastguard Worker 796*5a6e8488SAndroid Build Coastguard Worker *b* cannot be **0**. 797*5a6e8488SAndroid Build Coastguard Worker 798*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 799*5a6e8488SAndroid Build Coastguard Worker 800*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 801*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 802*5a6e8488SAndroid Build Coastguard Worker 803*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 804*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 805*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_DIVIDE_BY_ZERO** 806*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 807*5a6e8488SAndroid Build Coastguard Worker 808*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_mod(BclNumber** _a_**, BclNumber** _b_**)** 809*5a6e8488SAndroid Build Coastguard Worker 810*5a6e8488SAndroid Build Coastguard Worker: Divides *a* by *b* to the *scale* of the current context, computes the 811*5a6e8488SAndroid Build Coastguard Worker modulus **a-(a/b)\*b**, and returns the modulus. 812*5a6e8488SAndroid Build Coastguard Worker 813*5a6e8488SAndroid Build Coastguard Worker *b* cannot be **0**. 814*5a6e8488SAndroid Build Coastguard Worker 815*5a6e8488SAndroid Build Coastguard Worker *a* and *b* are consumed; they cannot be used after the call. See the 816*5a6e8488SAndroid Build Coastguard Worker **Consumption and Propagation** subsection below. 817*5a6e8488SAndroid Build Coastguard Worker 818*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 819*5a6e8488SAndroid Build Coastguard Worker 820*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 821*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 822*5a6e8488SAndroid Build Coastguard Worker 823*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 824*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 825*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_DIVIDE_BY_ZERO** 826*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 827*5a6e8488SAndroid Build Coastguard Worker 828*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_mod_keep(BclNumber** _a_**, BclNumber** _b_**)** 829*5a6e8488SAndroid Build Coastguard Worker 830*5a6e8488SAndroid Build Coastguard Worker: Divides *a* by *b* to the *scale* of the current context, computes the 831*5a6e8488SAndroid Build Coastguard Worker modulus **a-(a/b)\*b**, and returns the modulus. 832*5a6e8488SAndroid Build Coastguard Worker 833*5a6e8488SAndroid Build Coastguard Worker *b* cannot be **0**. 834*5a6e8488SAndroid Build Coastguard Worker 835*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 836*5a6e8488SAndroid Build Coastguard Worker 837*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 838*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 839*5a6e8488SAndroid Build Coastguard Worker 840*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 841*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 842*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_DIVIDE_BY_ZERO** 843*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 844*5a6e8488SAndroid Build Coastguard Worker 845*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_pow(BclNumber** _a_**, BclNumber** _b_**)** 846*5a6e8488SAndroid Build Coastguard Worker 847*5a6e8488SAndroid Build Coastguard Worker: Calculates *a* to the power of *b* to the *scale* of the current context. 848*5a6e8488SAndroid Build Coastguard Worker *b* must be an integer, but can be negative. If it is negative, *a* must 849*5a6e8488SAndroid Build Coastguard Worker be non-zero. 850*5a6e8488SAndroid Build Coastguard Worker 851*5a6e8488SAndroid Build Coastguard Worker *b* must be an integer. If *b* is negative, *a* must not be **0**. 852*5a6e8488SAndroid Build Coastguard Worker 853*5a6e8488SAndroid Build Coastguard Worker *a* must be smaller than **BC_OVERFLOW_MAX**. See the **LIMITS** section. 854*5a6e8488SAndroid Build Coastguard Worker 855*5a6e8488SAndroid Build Coastguard Worker *a* and *b* are consumed; they cannot be used after the call. See the 856*5a6e8488SAndroid Build Coastguard Worker **Consumption and Propagation** subsection below. 857*5a6e8488SAndroid Build Coastguard Worker 858*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 859*5a6e8488SAndroid Build Coastguard Worker 860*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 861*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 862*5a6e8488SAndroid Build Coastguard Worker 863*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 864*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 865*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NON_INTEGER** 866*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_OVERFLOW** 867*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_DIVIDE_BY_ZERO** 868*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 869*5a6e8488SAndroid Build Coastguard Worker 870*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_pow_keep(BclNumber** _a_**, BclNumber** _b_**)** 871*5a6e8488SAndroid Build Coastguard Worker 872*5a6e8488SAndroid Build Coastguard Worker: Calculates *a* to the power of *b* to the *scale* of the current context. 873*5a6e8488SAndroid Build Coastguard Worker *b* must be an integer, but can be negative. If it is negative, *a* must 874*5a6e8488SAndroid Build Coastguard Worker be non-zero. 875*5a6e8488SAndroid Build Coastguard Worker 876*5a6e8488SAndroid Build Coastguard Worker *b* must be an integer. If *b* is negative, *a* must not be **0**. 877*5a6e8488SAndroid Build Coastguard Worker 878*5a6e8488SAndroid Build Coastguard Worker *a* must be smaller than **BC_OVERFLOW_MAX**. See the **LIMITS** section. 879*5a6e8488SAndroid Build Coastguard Worker 880*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 881*5a6e8488SAndroid Build Coastguard Worker 882*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 883*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 884*5a6e8488SAndroid Build Coastguard Worker 885*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 886*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 887*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NON_INTEGER** 888*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_OVERFLOW** 889*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_DIVIDE_BY_ZERO** 890*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 891*5a6e8488SAndroid Build Coastguard Worker 892*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_lshift(BclNumber** _a_**, BclNumber** _b_**)** 893*5a6e8488SAndroid Build Coastguard Worker 894*5a6e8488SAndroid Build Coastguard Worker: Shifts *a* left (moves the radix right) by *b* places and returns the 895*5a6e8488SAndroid Build Coastguard Worker result. This is done in decimal. *b* must be an integer. 896*5a6e8488SAndroid Build Coastguard Worker 897*5a6e8488SAndroid Build Coastguard Worker *b* must be an integer. 898*5a6e8488SAndroid Build Coastguard Worker 899*5a6e8488SAndroid Build Coastguard Worker *a* and *b* are consumed; they cannot be used after the call. See the 900*5a6e8488SAndroid Build Coastguard Worker **Consumption and Propagation** subsection below. 901*5a6e8488SAndroid Build Coastguard Worker 902*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 903*5a6e8488SAndroid Build Coastguard Worker 904*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 905*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 906*5a6e8488SAndroid Build Coastguard Worker 907*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 908*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 909*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NON_INTEGER** 910*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 911*5a6e8488SAndroid Build Coastguard Worker 912*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_lshift_keep(BclNumber** _a_**, BclNumber** _b_**)** 913*5a6e8488SAndroid Build Coastguard Worker 914*5a6e8488SAndroid Build Coastguard Worker: Shifts *a* left (moves the radix right) by *b* places and returns the 915*5a6e8488SAndroid Build Coastguard Worker result. This is done in decimal. *b* must be an integer. 916*5a6e8488SAndroid Build Coastguard Worker 917*5a6e8488SAndroid Build Coastguard Worker *b* must be an integer. 918*5a6e8488SAndroid Build Coastguard Worker 919*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 920*5a6e8488SAndroid Build Coastguard Worker 921*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 922*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 923*5a6e8488SAndroid Build Coastguard Worker 924*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 925*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 926*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NON_INTEGER** 927*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 928*5a6e8488SAndroid Build Coastguard Worker 929*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_rshift(BclNumber** _a_**, BclNumber** _b_**)** 930*5a6e8488SAndroid Build Coastguard Worker 931*5a6e8488SAndroid Build Coastguard Worker: Shifts *a* right (moves the radix left) by *b* places and returns the 932*5a6e8488SAndroid Build Coastguard Worker result. This is done in decimal. *b* must be an integer. 933*5a6e8488SAndroid Build Coastguard Worker 934*5a6e8488SAndroid Build Coastguard Worker *b* must be an integer. 935*5a6e8488SAndroid Build Coastguard Worker 936*5a6e8488SAndroid Build Coastguard Worker *a* and *b* are consumed; they cannot be used after the call. See the 937*5a6e8488SAndroid Build Coastguard Worker **Consumption and Propagation** subsection below. 938*5a6e8488SAndroid Build Coastguard Worker 939*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 940*5a6e8488SAndroid Build Coastguard Worker 941*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 942*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 943*5a6e8488SAndroid Build Coastguard Worker 944*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 945*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 946*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NON_INTEGER** 947*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 948*5a6e8488SAndroid Build Coastguard Worker 949*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_rshift_keep(BclNumber** _a_**, BclNumber** _b_**)** 950*5a6e8488SAndroid Build Coastguard Worker 951*5a6e8488SAndroid Build Coastguard Worker: Shifts *a* right (moves the radix left) by *b* places and returns the 952*5a6e8488SAndroid Build Coastguard Worker result. This is done in decimal. *b* must be an integer. 953*5a6e8488SAndroid Build Coastguard Worker 954*5a6e8488SAndroid Build Coastguard Worker *b* must be an integer. 955*5a6e8488SAndroid Build Coastguard Worker 956*5a6e8488SAndroid Build Coastguard Worker *a* and *b* can be the same number. 957*5a6e8488SAndroid Build Coastguard Worker 958*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 959*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 960*5a6e8488SAndroid Build Coastguard Worker 961*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 962*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 963*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NON_INTEGER** 964*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 965*5a6e8488SAndroid Build Coastguard Worker 966*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_sqrt(BclNumber** _a_**)** 967*5a6e8488SAndroid Build Coastguard Worker 968*5a6e8488SAndroid Build Coastguard Worker: Calculates the square root of *a* and returns the result. The *scale* of the 969*5a6e8488SAndroid Build Coastguard Worker result is equal to the **scale** of the current context. 970*5a6e8488SAndroid Build Coastguard Worker 971*5a6e8488SAndroid Build Coastguard Worker *a* cannot be negative. 972*5a6e8488SAndroid Build Coastguard Worker 973*5a6e8488SAndroid Build Coastguard Worker *a* is consumed; it cannot be used after the call. See the 974*5a6e8488SAndroid Build Coastguard Worker **Consumption and Propagation** subsection below. 975*5a6e8488SAndroid Build Coastguard Worker 976*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 977*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 978*5a6e8488SAndroid Build Coastguard Worker 979*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 980*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 981*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NEGATIVE** 982*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 983*5a6e8488SAndroid Build Coastguard Worker 984*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_sqrt_keep(BclNumber** _a_**)** 985*5a6e8488SAndroid Build Coastguard Worker 986*5a6e8488SAndroid Build Coastguard Worker: Calculates the square root of *a* and returns the result. The *scale* of the 987*5a6e8488SAndroid Build Coastguard Worker result is equal to the **scale** of the current context. 988*5a6e8488SAndroid Build Coastguard Worker 989*5a6e8488SAndroid Build Coastguard Worker *a* cannot be negative. 990*5a6e8488SAndroid Build Coastguard Worker 991*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 992*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 993*5a6e8488SAndroid Build Coastguard Worker 994*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 995*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 996*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NEGATIVE** 997*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 998*5a6e8488SAndroid Build Coastguard Worker 999*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_divmod(BclNumber** _a_**, BclNumber** _b_**, BclNumber \***_c_**, BclNumber \***_d_**)** 1000*5a6e8488SAndroid Build Coastguard Worker 1001*5a6e8488SAndroid Build Coastguard Worker: Divides *a* by *b* and returns the quotient in a new number which is put 1002*5a6e8488SAndroid Build Coastguard Worker into the space pointed to by *c*, and puts the modulus in a new number which 1003*5a6e8488SAndroid Build Coastguard Worker is put into the space pointed to by *d*. 1004*5a6e8488SAndroid Build Coastguard Worker 1005*5a6e8488SAndroid Build Coastguard Worker *b* cannot be **0**. 1006*5a6e8488SAndroid Build Coastguard Worker 1007*5a6e8488SAndroid Build Coastguard Worker *a* and *b* are consumed; they cannot be used after the call. See the 1008*5a6e8488SAndroid Build Coastguard Worker **Consumption and Propagation** subsection below. 1009*5a6e8488SAndroid Build Coastguard Worker 1010*5a6e8488SAndroid Build Coastguard Worker *c* and *d* cannot point to the same place, nor can they point to the space 1011*5a6e8488SAndroid Build Coastguard Worker occupied by *a* or *b*. 1012*5a6e8488SAndroid Build Coastguard Worker 1013*5a6e8488SAndroid Build Coastguard Worker If there was no error, **BCL_ERROR_NONE** is returned. Otherwise, this 1014*5a6e8488SAndroid Build Coastguard Worker function can return: 1015*5a6e8488SAndroid Build Coastguard Worker 1016*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 1017*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 1018*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_DIVIDE_BY_ZERO** 1019*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 1020*5a6e8488SAndroid Build Coastguard Worker 1021*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_divmod_keep(BclNumber** _a_**, BclNumber** _b_**, BclNumber \***_c_**, BclNumber \***_d_**)** 1022*5a6e8488SAndroid Build Coastguard Worker 1023*5a6e8488SAndroid Build Coastguard Worker: Divides *a* by *b* and returns the quotient in a new number which is put 1024*5a6e8488SAndroid Build Coastguard Worker into the space pointed to by *c*, and puts the modulus in a new number which 1025*5a6e8488SAndroid Build Coastguard Worker is put into the space pointed to by *d*. 1026*5a6e8488SAndroid Build Coastguard Worker 1027*5a6e8488SAndroid Build Coastguard Worker *b* cannot be **0**. 1028*5a6e8488SAndroid Build Coastguard Worker 1029*5a6e8488SAndroid Build Coastguard Worker *c* and *d* cannot point to the same place, nor can they point to the space 1030*5a6e8488SAndroid Build Coastguard Worker occupied by *a* or *b*. 1031*5a6e8488SAndroid Build Coastguard Worker 1032*5a6e8488SAndroid Build Coastguard Worker If there was no error, **BCL_ERROR_NONE** is returned. Otherwise, this 1033*5a6e8488SAndroid Build Coastguard Worker function can return: 1034*5a6e8488SAndroid Build Coastguard Worker 1035*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 1036*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 1037*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_DIVIDE_BY_ZERO** 1038*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 1039*5a6e8488SAndroid Build Coastguard Worker 1040*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_modexp(BclNumber** _a_**, BclNumber** _b_**, BclNumber** _c_**)** 1041*5a6e8488SAndroid Build Coastguard Worker 1042*5a6e8488SAndroid Build Coastguard Worker: Computes a modular exponentiation where *a* is the base, *b* is the 1043*5a6e8488SAndroid Build Coastguard Worker exponent, and *c* is the modulus, and returns the result. The *scale* of the 1044*5a6e8488SAndroid Build Coastguard Worker result is equal to the **scale** of the current context. 1045*5a6e8488SAndroid Build Coastguard Worker 1046*5a6e8488SAndroid Build Coastguard Worker *a*, *b*, and *c* must be integers. *c* must not be **0**. *b* must not be 1047*5a6e8488SAndroid Build Coastguard Worker negative. 1048*5a6e8488SAndroid Build Coastguard Worker 1049*5a6e8488SAndroid Build Coastguard Worker *a*, *b*, and *c* are consumed; they cannot be used after the call. See the 1050*5a6e8488SAndroid Build Coastguard Worker **Consumption and Propagation** subsection below. 1051*5a6e8488SAndroid Build Coastguard Worker 1052*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 1053*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 1054*5a6e8488SAndroid Build Coastguard Worker 1055*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 1056*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 1057*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NEGATIVE** 1058*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NON_INTEGER** 1059*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_DIVIDE_BY_ZERO** 1060*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 1061*5a6e8488SAndroid Build Coastguard Worker 1062*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_modexp_keep(BclNumber** _a_**, BclNumber** _b_**, BclNumber** _c_**)** 1063*5a6e8488SAndroid Build Coastguard Worker 1064*5a6e8488SAndroid Build Coastguard Worker: Computes a modular exponentiation where *a* is the base, *b* is the 1065*5a6e8488SAndroid Build Coastguard Worker exponent, and *c* is the modulus, and returns the result. The *scale* of the 1066*5a6e8488SAndroid Build Coastguard Worker result is equal to the **scale** of the current context. 1067*5a6e8488SAndroid Build Coastguard Worker 1068*5a6e8488SAndroid Build Coastguard Worker *a*, *b*, and *c* must be integers. *c* must not be **0**. *b* must not be 1069*5a6e8488SAndroid Build Coastguard Worker negative. 1070*5a6e8488SAndroid Build Coastguard Worker 1071*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 1072*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 1073*5a6e8488SAndroid Build Coastguard Worker 1074*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 1075*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 1076*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NEGATIVE** 1077*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NON_INTEGER** 1078*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_DIVIDE_BY_ZERO** 1079*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 1080*5a6e8488SAndroid Build Coastguard Worker 1081*5a6e8488SAndroid Build Coastguard Worker## Miscellaneous 1082*5a6e8488SAndroid Build Coastguard Worker 1083*5a6e8488SAndroid Build Coastguard Worker**void bcl_zero(BclNumber** _n_**)** 1084*5a6e8488SAndroid Build Coastguard Worker 1085*5a6e8488SAndroid Build Coastguard Worker: Sets *n* to **0**. 1086*5a6e8488SAndroid Build Coastguard Worker 1087*5a6e8488SAndroid Build Coastguard Worker**void bcl_one(BclNumber** _n_**)** 1088*5a6e8488SAndroid Build Coastguard Worker 1089*5a6e8488SAndroid Build Coastguard Worker: Sets *n* to **1**. 1090*5a6e8488SAndroid Build Coastguard Worker 1091*5a6e8488SAndroid Build Coastguard Worker**ssize_t bcl_cmp(BclNumber** _a_**, BclNumber** _b_**)** 1092*5a6e8488SAndroid Build Coastguard Worker 1093*5a6e8488SAndroid Build Coastguard Worker: Compares *a* and *b* and returns **0** if *a* and *b* are equal, **<0** if 1094*5a6e8488SAndroid Build Coastguard Worker *a* is less than *b*, and **>0** if *a* is greater than *b*. 1095*5a6e8488SAndroid Build Coastguard Worker 1096*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_copy(BclNumber** _d_**, BclNumber** _s_**)** 1097*5a6e8488SAndroid Build Coastguard Worker 1098*5a6e8488SAndroid Build Coastguard Worker: Copies *s* into *d*. 1099*5a6e8488SAndroid Build Coastguard Worker 1100*5a6e8488SAndroid Build Coastguard Worker If there was no error, **BCL_ERROR_NONE** is returned. Otherwise, this 1101*5a6e8488SAndroid Build Coastguard Worker function can return: 1102*5a6e8488SAndroid Build Coastguard Worker 1103*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 1104*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 1105*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 1106*5a6e8488SAndroid Build Coastguard Worker 1107*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_dup(BclNumber** _s_**)** 1108*5a6e8488SAndroid Build Coastguard Worker 1109*5a6e8488SAndroid Build Coastguard Worker: Creates and returns a new **BclNumber** that is a copy of *s*. 1110*5a6e8488SAndroid Build Coastguard Worker 1111*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 1112*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 1113*5a6e8488SAndroid Build Coastguard Worker 1114*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 1115*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 1116*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 1117*5a6e8488SAndroid Build Coastguard Worker 1118*5a6e8488SAndroid Build Coastguard Worker## Pseudo-Random Number Generator 1119*5a6e8488SAndroid Build Coastguard Worker 1120*5a6e8488SAndroid Build Coastguard WorkerThe pseudo-random number generator in bcl(3) is a *seeded* PRNG. Given the same 1121*5a6e8488SAndroid Build Coastguard Workerseed twice, it will produce the same sequence of pseudo-random numbers twice. 1122*5a6e8488SAndroid Build Coastguard Worker 1123*5a6e8488SAndroid Build Coastguard WorkerBy default, bcl(3) attempts to seed the PRNG with data from **/dev/urandom**. If 1124*5a6e8488SAndroid Build Coastguard Workerthat fails, it seeds itself with by calling **libc**'s **srand(time(NULL))** and 1125*5a6e8488SAndroid Build Coastguard Workerthen calling **rand()** for each byte, since **rand()** is only guaranteed to 1126*5a6e8488SAndroid Build Coastguard Workerreturn **15** bits. 1127*5a6e8488SAndroid Build Coastguard Worker 1128*5a6e8488SAndroid Build Coastguard WorkerThis should provide fairly good seeding in the standard case while also 1129*5a6e8488SAndroid Build Coastguard Workerremaining fairly portable. 1130*5a6e8488SAndroid Build Coastguard Worker 1131*5a6e8488SAndroid Build Coastguard WorkerIf necessary, the PRNG can be reseeded with one of the following functions: 1132*5a6e8488SAndroid Build Coastguard Worker 1133*5a6e8488SAndroid Build Coastguard Worker* **bcl_rand_seedWithNum(BclNumber)** 1134*5a6e8488SAndroid Build Coastguard Worker* **bcl_rand_seed(unsigned char[**_BCL_SEED_SIZE_**])** 1135*5a6e8488SAndroid Build Coastguard Worker* **bcl_rand_reseed(**_void_**)** 1136*5a6e8488SAndroid Build Coastguard Worker 1137*5a6e8488SAndroid Build Coastguard WorkerAll procedures in this section without the **_keep** suffix in their name 1138*5a6e8488SAndroid Build Coastguard Workerconsume the given **BclNumber** arguments that are not given to pointer 1139*5a6e8488SAndroid Build Coastguard Workerarguments. See the **Consumption and Propagation** subsection below. 1140*5a6e8488SAndroid Build Coastguard Worker 1141*5a6e8488SAndroid Build Coastguard WorkerThe following items allow clients to use the pseudo-random number generator. All 1142*5a6e8488SAndroid Build Coastguard Workerprocedures require a valid current context. 1143*5a6e8488SAndroid Build Coastguard Worker 1144*5a6e8488SAndroid Build Coastguard Worker**BCL_SEED_ULONGS** 1145*5a6e8488SAndroid Build Coastguard Worker 1146*5a6e8488SAndroid Build Coastguard Worker: The number of **unsigned long**'s in a seed for bcl(3)'s random number 1147*5a6e8488SAndroid Build Coastguard Worker generator. 1148*5a6e8488SAndroid Build Coastguard Worker 1149*5a6e8488SAndroid Build Coastguard Worker**BCL_SEED_SIZE** 1150*5a6e8488SAndroid Build Coastguard Worker 1151*5a6e8488SAndroid Build Coastguard Worker: The size, in **char**'s, of a seed for bcl(3)'s random number generator. 1152*5a6e8488SAndroid Build Coastguard Worker 1153*5a6e8488SAndroid Build Coastguard Worker**BclBigDig** 1154*5a6e8488SAndroid Build Coastguard Worker 1155*5a6e8488SAndroid Build Coastguard Worker: bcl(3)'s overflow type (see the **PERFORMANCE** section). 1156*5a6e8488SAndroid Build Coastguard Worker 1157*5a6e8488SAndroid Build Coastguard Worker**BclRandInt** 1158*5a6e8488SAndroid Build Coastguard Worker 1159*5a6e8488SAndroid Build Coastguard Worker: An unsigned integer type returned by bcl(3)'s random number generator. 1160*5a6e8488SAndroid Build Coastguard Worker 1161*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_irand(BclNumber** _a_**)** 1162*5a6e8488SAndroid Build Coastguard Worker 1163*5a6e8488SAndroid Build Coastguard Worker: Returns a random number that is not larger than *a* in a new number. If *a* 1164*5a6e8488SAndroid Build Coastguard Worker is **0** or **1**, the new number is equal to **0**. The bound is unlimited, 1165*5a6e8488SAndroid Build Coastguard Worker so it is not bound to the size of **BclRandInt**. This is done by generating 1166*5a6e8488SAndroid Build Coastguard Worker as many random numbers as necessary, multiplying them by certain exponents, 1167*5a6e8488SAndroid Build Coastguard Worker and adding them all together. 1168*5a6e8488SAndroid Build Coastguard Worker 1169*5a6e8488SAndroid Build Coastguard Worker *a* must be an integer and non-negative. 1170*5a6e8488SAndroid Build Coastguard Worker 1171*5a6e8488SAndroid Build Coastguard Worker *a* is consumed; it cannot be used after the call. See the **Consumption and 1172*5a6e8488SAndroid Build Coastguard Worker Propagation** subsection below. 1173*5a6e8488SAndroid Build Coastguard Worker 1174*5a6e8488SAndroid Build Coastguard Worker This procedure requires a valid current context. 1175*5a6e8488SAndroid Build Coastguard Worker 1176*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 1177*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 1178*5a6e8488SAndroid Build Coastguard Worker 1179*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 1180*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 1181*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NEGATIVE** 1182*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NON_INTEGER** 1183*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 1184*5a6e8488SAndroid Build Coastguard Worker 1185*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_irand_keep(BclNumber** _a_**)** 1186*5a6e8488SAndroid Build Coastguard Worker 1187*5a6e8488SAndroid Build Coastguard Worker: Returns a random number that is not larger than *a* in a new number. If *a* 1188*5a6e8488SAndroid Build Coastguard Worker is **0** or **1**, the new number is equal to **0**. The bound is unlimited, 1189*5a6e8488SAndroid Build Coastguard Worker so it is not bound to the size of **BclRandInt**. This is done by generating 1190*5a6e8488SAndroid Build Coastguard Worker as many random numbers as necessary, multiplying them by certain exponents, 1191*5a6e8488SAndroid Build Coastguard Worker and adding them all together. 1192*5a6e8488SAndroid Build Coastguard Worker 1193*5a6e8488SAndroid Build Coastguard Worker *a* must be an integer and non-negative. 1194*5a6e8488SAndroid Build Coastguard Worker 1195*5a6e8488SAndroid Build Coastguard Worker This procedure requires a valid current context. 1196*5a6e8488SAndroid Build Coastguard Worker 1197*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 1198*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 1199*5a6e8488SAndroid Build Coastguard Worker 1200*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 1201*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 1202*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NEGATIVE** 1203*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NON_INTEGER** 1204*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 1205*5a6e8488SAndroid Build Coastguard Worker 1206*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_frand(size_t** _places_**)** 1207*5a6e8488SAndroid Build Coastguard Worker 1208*5a6e8488SAndroid Build Coastguard Worker: Returns a random number between **0** (inclusive) and **1** (exclusive) that 1209*5a6e8488SAndroid Build Coastguard Worker has *places* decimal digits after the radix (decimal point). There are no 1210*5a6e8488SAndroid Build Coastguard Worker limits on *places*. 1211*5a6e8488SAndroid Build Coastguard Worker 1212*5a6e8488SAndroid Build Coastguard Worker This procedure requires a valid current context. 1213*5a6e8488SAndroid Build Coastguard Worker 1214*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 1215*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 1216*5a6e8488SAndroid Build Coastguard Worker 1217*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 1218*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 1219*5a6e8488SAndroid Build Coastguard Worker 1220*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_ifrand(BclNumber** _a_**, size_t** _places_**)** 1221*5a6e8488SAndroid Build Coastguard Worker 1222*5a6e8488SAndroid Build Coastguard Worker: Returns a random number less than *a* with *places* decimal digits after the 1223*5a6e8488SAndroid Build Coastguard Worker radix (decimal point). There are no limits on *a* or *places*. 1224*5a6e8488SAndroid Build Coastguard Worker 1225*5a6e8488SAndroid Build Coastguard Worker *a* must be an integer and non-negative. 1226*5a6e8488SAndroid Build Coastguard Worker 1227*5a6e8488SAndroid Build Coastguard Worker *a* is consumed; it cannot be used after the call. See the **Consumption and 1228*5a6e8488SAndroid Build Coastguard Worker Propagation** subsection below. 1229*5a6e8488SAndroid Build Coastguard Worker 1230*5a6e8488SAndroid Build Coastguard Worker This procedure requires a valid current context. 1231*5a6e8488SAndroid Build Coastguard Worker 1232*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 1233*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 1234*5a6e8488SAndroid Build Coastguard Worker 1235*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 1236*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 1237*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NEGATIVE** 1238*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NON_INTEGER** 1239*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 1240*5a6e8488SAndroid Build Coastguard Worker 1241*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_ifrand_keep(BclNumber** _a_**, size_t** _places_**)** 1242*5a6e8488SAndroid Build Coastguard Worker 1243*5a6e8488SAndroid Build Coastguard Worker: Returns a random number less than *a* with *places* decimal digits after the 1244*5a6e8488SAndroid Build Coastguard Worker radix (decimal point). There are no limits on *a* or *places*. 1245*5a6e8488SAndroid Build Coastguard Worker 1246*5a6e8488SAndroid Build Coastguard Worker *a* must be an integer and non-negative. 1247*5a6e8488SAndroid Build Coastguard Worker 1248*5a6e8488SAndroid Build Coastguard Worker This procedure requires a valid current context. 1249*5a6e8488SAndroid Build Coastguard Worker 1250*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 1251*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 1252*5a6e8488SAndroid Build Coastguard Worker 1253*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 1254*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 1255*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NEGATIVE** 1256*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_MATH_NON_INTEGER** 1257*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 1258*5a6e8488SAndroid Build Coastguard Worker 1259*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_rand_seedWithNum(BclNumber** _n_**)** 1260*5a6e8488SAndroid Build Coastguard Worker 1261*5a6e8488SAndroid Build Coastguard Worker: Seeds the PRNG with *n*. 1262*5a6e8488SAndroid Build Coastguard Worker 1263*5a6e8488SAndroid Build Coastguard Worker *n* is consumed. 1264*5a6e8488SAndroid Build Coastguard Worker 1265*5a6e8488SAndroid Build Coastguard Worker This procedure requires a valid current context. 1266*5a6e8488SAndroid Build Coastguard Worker 1267*5a6e8488SAndroid Build Coastguard Worker If there was no error, **BCL_ERROR_NONE** is returned. Otherwise, this 1268*5a6e8488SAndroid Build Coastguard Worker function can return: 1269*5a6e8488SAndroid Build Coastguard Worker 1270*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 1271*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 1272*5a6e8488SAndroid Build Coastguard Worker 1273*5a6e8488SAndroid Build Coastguard Worker Note that if **bcl_rand_seed2num(**_void_**)** or 1274*5a6e8488SAndroid Build Coastguard Worker **bcl_rand_seed2num_err(BclNumber)** are called right after this function, 1275*5a6e8488SAndroid Build Coastguard Worker they are not guaranteed to return a number equal to *n*. 1276*5a6e8488SAndroid Build Coastguard Worker 1277*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_rand_seedWithNum_keep(BclNumber** _n_**)** 1278*5a6e8488SAndroid Build Coastguard Worker 1279*5a6e8488SAndroid Build Coastguard Worker: Seeds the PRNG with *n*. 1280*5a6e8488SAndroid Build Coastguard Worker 1281*5a6e8488SAndroid Build Coastguard Worker This procedure requires a valid current context. 1282*5a6e8488SAndroid Build Coastguard Worker 1283*5a6e8488SAndroid Build Coastguard Worker If there was no error, **BCL_ERROR_NONE** is returned. Otherwise, this 1284*5a6e8488SAndroid Build Coastguard Worker function can return: 1285*5a6e8488SAndroid Build Coastguard Worker 1286*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_NUM** 1287*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 1288*5a6e8488SAndroid Build Coastguard Worker 1289*5a6e8488SAndroid Build Coastguard Worker Note that if **bcl_rand_seed2num(**_void_**)** or 1290*5a6e8488SAndroid Build Coastguard Worker **bcl_rand_seed2num_err(BclNumber)** are called right after this function, 1291*5a6e8488SAndroid Build Coastguard Worker they are not guaranteed to return a number equal to *n*. 1292*5a6e8488SAndroid Build Coastguard Worker 1293*5a6e8488SAndroid Build Coastguard Worker**BclError bcl_rand_seed(unsigned char** _seed_**[**_BCL_SEED_SIZE_**])** 1294*5a6e8488SAndroid Build Coastguard Worker 1295*5a6e8488SAndroid Build Coastguard Worker: Seeds the PRNG with the bytes in *seed*. 1296*5a6e8488SAndroid Build Coastguard Worker 1297*5a6e8488SAndroid Build Coastguard Worker If there was no error, **BCL_ERROR_NONE** is returned. Otherwise, this 1298*5a6e8488SAndroid Build Coastguard Worker function can return: 1299*5a6e8488SAndroid Build Coastguard Worker 1300*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 1301*5a6e8488SAndroid Build Coastguard Worker 1302*5a6e8488SAndroid Build Coastguard Worker**void bcl_rand_reseed(**_void_**)** 1303*5a6e8488SAndroid Build Coastguard Worker 1304*5a6e8488SAndroid Build Coastguard Worker: Reseeds the PRNG with the default reseeding behavior. First, it attempts to 1305*5a6e8488SAndroid Build Coastguard Worker read data from **/dev/urandom** and falls back to **libc**'s **rand()**. 1306*5a6e8488SAndroid Build Coastguard Worker 1307*5a6e8488SAndroid Build Coastguard Worker This procedure cannot fail. 1308*5a6e8488SAndroid Build Coastguard Worker 1309*5a6e8488SAndroid Build Coastguard Worker**BclNumber bcl_rand_seed2num(**_void_**)** 1310*5a6e8488SAndroid Build Coastguard Worker 1311*5a6e8488SAndroid Build Coastguard Worker: Returns the current seed of the PRNG as a **BclNumber**. 1312*5a6e8488SAndroid Build Coastguard Worker 1313*5a6e8488SAndroid Build Coastguard Worker This procedure requires a valid current context. 1314*5a6e8488SAndroid Build Coastguard Worker 1315*5a6e8488SAndroid Build Coastguard Worker bcl(3) will encode an error in the return value, if there was one. The error 1316*5a6e8488SAndroid Build Coastguard Worker can be queried with **bcl_err(BclNumber)**. Possible errors include: 1317*5a6e8488SAndroid Build Coastguard Worker 1318*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_INVALID_CONTEXT** 1319*5a6e8488SAndroid Build Coastguard Worker * **BCL_ERROR_FATAL_ALLOC_ERR** 1320*5a6e8488SAndroid Build Coastguard Worker 1321*5a6e8488SAndroid Build Coastguard Worker**BclRandInt bcl_rand_int(**_void_**)** 1322*5a6e8488SAndroid Build Coastguard Worker 1323*5a6e8488SAndroid Build Coastguard Worker: Returns a random integer between **0** and **BC_RAND_MAX** (inclusive). 1324*5a6e8488SAndroid Build Coastguard Worker 1325*5a6e8488SAndroid Build Coastguard Worker This procedure cannot fail. 1326*5a6e8488SAndroid Build Coastguard Worker 1327*5a6e8488SAndroid Build Coastguard Worker**BclRandInt bcl_rand_bounded(BclRandInt** _bound_**)** 1328*5a6e8488SAndroid Build Coastguard Worker 1329*5a6e8488SAndroid Build Coastguard Worker: Returns a random integer between **0** and *bound* (exclusive). Bias is 1330*5a6e8488SAndroid Build Coastguard Worker removed before returning the integer. 1331*5a6e8488SAndroid Build Coastguard Worker 1332*5a6e8488SAndroid Build Coastguard Worker This procedure cannot fail. 1333*5a6e8488SAndroid Build Coastguard Worker 1334*5a6e8488SAndroid Build Coastguard Worker## Consumption and Propagation 1335*5a6e8488SAndroid Build Coastguard Worker 1336*5a6e8488SAndroid Build Coastguard WorkerSome functions are listed as consuming some or all of their arguments. This 1337*5a6e8488SAndroid Build Coastguard Workermeans that the arguments are freed, regardless of if there were errors or not. 1338*5a6e8488SAndroid Build Coastguard Worker 1339*5a6e8488SAndroid Build Coastguard WorkerThis is to enable compact code like the following: 1340*5a6e8488SAndroid Build Coastguard Worker 1341*5a6e8488SAndroid Build Coastguard Worker BclNumber n = bcl_num_add(bcl_num_mul(a, b), bcl_num_div(c, d)); 1342*5a6e8488SAndroid Build Coastguard Worker 1343*5a6e8488SAndroid Build Coastguard WorkerIf arguments to those functions were not consumed, memory would be leaked until 1344*5a6e8488SAndroid Build Coastguard Workerreclaimed with **bcl_ctxt_freeNums(BclContext)**. 1345*5a6e8488SAndroid Build Coastguard Worker 1346*5a6e8488SAndroid Build Coastguard WorkerWhen errors occur, they are propagated through. The result should always be 1347*5a6e8488SAndroid Build Coastguard Workerchecked with **bcl_err(BclNumber)**, so the example above should properly 1348*5a6e8488SAndroid Build Coastguard Workerbe: 1349*5a6e8488SAndroid Build Coastguard Worker 1350*5a6e8488SAndroid Build Coastguard Worker BclNumber n = bcl_num_add(bcl_num_mul(a, b), bcl_num_div(c, d)); 1351*5a6e8488SAndroid Build Coastguard Worker if (bcl_err(n) != BCL_ERROR_NONE) { 1352*5a6e8488SAndroid Build Coastguard Worker // Handle the error. 1353*5a6e8488SAndroid Build Coastguard Worker } 1354*5a6e8488SAndroid Build Coastguard Worker 1355*5a6e8488SAndroid Build Coastguard Worker# ERRORS 1356*5a6e8488SAndroid Build Coastguard Worker 1357*5a6e8488SAndroid Build Coastguard WorkerMost functions in bcl(3) return, directly or indirectly, any one of the error 1358*5a6e8488SAndroid Build Coastguard Workercodes defined in **BclError**. The complete list of codes is the following: 1359*5a6e8488SAndroid Build Coastguard Worker 1360*5a6e8488SAndroid Build Coastguard Worker**BCL_ERROR_NONE** 1361*5a6e8488SAndroid Build Coastguard Worker 1362*5a6e8488SAndroid Build Coastguard Worker: Success; no error occurred. 1363*5a6e8488SAndroid Build Coastguard Worker 1364*5a6e8488SAndroid Build Coastguard Worker**BCL_ERROR_INVALID_NUM** 1365*5a6e8488SAndroid Build Coastguard Worker 1366*5a6e8488SAndroid Build Coastguard Worker: An invalid **BclNumber** was given as a parameter. 1367*5a6e8488SAndroid Build Coastguard Worker 1368*5a6e8488SAndroid Build Coastguard Worker**BCL_ERROR_INVALID_CONTEXT** 1369*5a6e8488SAndroid Build Coastguard Worker 1370*5a6e8488SAndroid Build Coastguard Worker: An invalid **BclContext** is being used. 1371*5a6e8488SAndroid Build Coastguard Worker 1372*5a6e8488SAndroid Build Coastguard Worker**BCL_ERROR_MATH_NEGATIVE** 1373*5a6e8488SAndroid Build Coastguard Worker 1374*5a6e8488SAndroid Build Coastguard Worker: A negative number was given as an argument to a parameter that cannot accept 1375*5a6e8488SAndroid Build Coastguard Worker negative numbers, such as for square roots. 1376*5a6e8488SAndroid Build Coastguard Worker 1377*5a6e8488SAndroid Build Coastguard Worker**BCL_ERROR_MATH_NON_INTEGER** 1378*5a6e8488SAndroid Build Coastguard Worker 1379*5a6e8488SAndroid Build Coastguard Worker: A non-integer was given as an argument to a parameter that cannot accept 1380*5a6e8488SAndroid Build Coastguard Worker non-integer numbers, such as for the second parameter of **bcl_num_pow()**. 1381*5a6e8488SAndroid Build Coastguard Worker 1382*5a6e8488SAndroid Build Coastguard Worker**BCL_ERROR_MATH_OVERFLOW** 1383*5a6e8488SAndroid Build Coastguard Worker 1384*5a6e8488SAndroid Build Coastguard Worker: A number that would overflow its result was given as an argument, such as 1385*5a6e8488SAndroid Build Coastguard Worker for converting a **BclNumber** to a **BclBigDig**. 1386*5a6e8488SAndroid Build Coastguard Worker 1387*5a6e8488SAndroid Build Coastguard Worker**BCL_ERROR_MATH_DIVIDE_BY_ZERO** 1388*5a6e8488SAndroid Build Coastguard Worker 1389*5a6e8488SAndroid Build Coastguard Worker: A divide by zero occurred. 1390*5a6e8488SAndroid Build Coastguard Worker 1391*5a6e8488SAndroid Build Coastguard Worker**BCL_ERROR_PARSE_INVALID_STR** 1392*5a6e8488SAndroid Build Coastguard Worker 1393*5a6e8488SAndroid Build Coastguard Worker: An invalid number string was passed to a parsing function. 1394*5a6e8488SAndroid Build Coastguard Worker 1395*5a6e8488SAndroid Build Coastguard Worker A valid number string can only be one radix (period). In addition, any 1396*5a6e8488SAndroid Build Coastguard Worker lowercase ASCII letters, symbols, or non-ASCII characters are invalid. It is 1397*5a6e8488SAndroid Build Coastguard Worker allowed for the first character to be a dash. In that case, the number is 1398*5a6e8488SAndroid Build Coastguard Worker considered to be negative. 1399*5a6e8488SAndroid Build Coastguard Worker 1400*5a6e8488SAndroid Build Coastguard Worker There is one exception to the above: one lowercase **e** is allowed in the 1401*5a6e8488SAndroid Build Coastguard Worker number, after the radix, if it exists. If the letter **e** exists, the 1402*5a6e8488SAndroid Build Coastguard Worker number is considered to be in scientific notation, where the part before the 1403*5a6e8488SAndroid Build Coastguard Worker **e** is the number, and the part after, which must be an integer, is the 1404*5a6e8488SAndroid Build Coastguard Worker exponent. There can be a dash right after the **e** to indicate a negative 1405*5a6e8488SAndroid Build Coastguard Worker exponent. 1406*5a6e8488SAndroid Build Coastguard Worker 1407*5a6e8488SAndroid Build Coastguard Worker **WARNING**: Both the number and the exponent in scientific notation are 1408*5a6e8488SAndroid Build Coastguard Worker interpreted according to the current **ibase**, but the number is still 1409*5a6e8488SAndroid Build Coastguard Worker multiplied by **10\^exponent** regardless of the current **ibase**. For 1410*5a6e8488SAndroid Build Coastguard Worker example, if **ibase** is **16** and bcl(3) is given the number string 1411*5a6e8488SAndroid Build Coastguard Worker **FFeA**, the resulting decimal number will be **2550000000000**, and if 1412*5a6e8488SAndroid Build Coastguard Worker bcl(3) is given the number string **10e-4**, the resulting decimal number 1413*5a6e8488SAndroid Build Coastguard Worker will be **0.0016**. 1414*5a6e8488SAndroid Build Coastguard Worker 1415*5a6e8488SAndroid Build Coastguard Worker**BCL_ERROR_FATAL_ALLOC_ERR** 1416*5a6e8488SAndroid Build Coastguard Worker 1417*5a6e8488SAndroid Build Coastguard Worker: bcl(3) failed to allocate memory. 1418*5a6e8488SAndroid Build Coastguard Worker 1419*5a6e8488SAndroid Build Coastguard Worker If clients call **bcl_setAbortOnFatalError()** with an **true** argument, 1420*5a6e8488SAndroid Build Coastguard Worker this error will cause bcl(3) to throw a **SIGABRT**. This behavior can also 1421*5a6e8488SAndroid Build Coastguard Worker be turned off later by calling that same function with a **false** argument. 1422*5a6e8488SAndroid Build Coastguard Worker By default, this behavior is off. 1423*5a6e8488SAndroid Build Coastguard Worker 1424*5a6e8488SAndroid Build Coastguard Worker It is highly recommended that client libraries do *not* activate this 1425*5a6e8488SAndroid Build Coastguard Worker behavior. 1426*5a6e8488SAndroid Build Coastguard Worker 1427*5a6e8488SAndroid Build Coastguard Worker**BCL_ERROR_FATAL_UNKNOWN_ERR** 1428*5a6e8488SAndroid Build Coastguard Worker 1429*5a6e8488SAndroid Build Coastguard Worker: An unknown error occurred. 1430*5a6e8488SAndroid Build Coastguard Worker 1431*5a6e8488SAndroid Build Coastguard Worker If clients call **bcl_setAbortOnFatalError()** with an **true** argument, 1432*5a6e8488SAndroid Build Coastguard Worker this error will cause bcl(3) to throw a **SIGABRT**. This behavior can also 1433*5a6e8488SAndroid Build Coastguard Worker be turned off later by calling that same function with a **false** argument. 1434*5a6e8488SAndroid Build Coastguard Worker By default, this behavior is off. 1435*5a6e8488SAndroid Build Coastguard Worker 1436*5a6e8488SAndroid Build Coastguard Worker It is highly recommended that client libraries do *not* activate this 1437*5a6e8488SAndroid Build Coastguard Worker behavior. 1438*5a6e8488SAndroid Build Coastguard Worker 1439*5a6e8488SAndroid Build Coastguard Worker# ATTRIBUTES 1440*5a6e8488SAndroid Build Coastguard Worker 1441*5a6e8488SAndroid Build Coastguard Workerbcl(3) is *MT-Safe*: it is safe to call any functions from more than one thread. 1442*5a6e8488SAndroid Build Coastguard WorkerHowever, is is *not* safe to pass any data between threads except for strings 1443*5a6e8488SAndroid Build Coastguard Workerreturned by **bcl_string()**. 1444*5a6e8488SAndroid Build Coastguard Worker 1445*5a6e8488SAndroid Build Coastguard Workerbcl(3) is not *async-signal-safe*. It was not possible to make bcl(3) safe with 1446*5a6e8488SAndroid Build Coastguard Workersignals and also make it safe with multiple threads. If it is necessary to be 1447*5a6e8488SAndroid Build Coastguard Workerable to interrupt bcl(3), spawn a separate thread to run the calculation. 1448*5a6e8488SAndroid Build Coastguard Worker 1449*5a6e8488SAndroid Build Coastguard Worker# PERFORMANCE 1450*5a6e8488SAndroid Build Coastguard Worker 1451*5a6e8488SAndroid Build Coastguard WorkerMost bc(1) implementations use **char** types to calculate the value of **1** 1452*5a6e8488SAndroid Build Coastguard Workerdecimal digit at a time, but that can be slow. bcl(3) does something 1453*5a6e8488SAndroid Build Coastguard Workerdifferent. 1454*5a6e8488SAndroid Build Coastguard Worker 1455*5a6e8488SAndroid Build Coastguard WorkerIt uses large integers to calculate more than **1** decimal digit at a time. If 1456*5a6e8488SAndroid Build Coastguard Workerbuilt in a environment where **BC_LONG_BIT** (see the **LIMITS** section) is 1457*5a6e8488SAndroid Build Coastguard Worker**64**, then each integer has **9** decimal digits. If built in an environment 1458*5a6e8488SAndroid Build Coastguard Workerwhere **BC_LONG_BIT** is **32** then each integer has **4** decimal digits. This 1459*5a6e8488SAndroid Build Coastguard Workervalue (the number of decimal digits per large integer) is called 1460*5a6e8488SAndroid Build Coastguard Worker**BC_BASE_DIGS**. 1461*5a6e8488SAndroid Build Coastguard Worker 1462*5a6e8488SAndroid Build Coastguard WorkerIn addition, this bcl(3) uses an even larger integer for overflow checking. This 1463*5a6e8488SAndroid Build Coastguard Workerinteger type depends on the value of **BC_LONG_BIT**, but is always at least 1464*5a6e8488SAndroid Build Coastguard Workertwice as large as the integer type used to store digits. 1465*5a6e8488SAndroid Build Coastguard Worker 1466*5a6e8488SAndroid Build Coastguard Worker# LIMITS 1467*5a6e8488SAndroid Build Coastguard Worker 1468*5a6e8488SAndroid Build Coastguard WorkerThe following are the limits on bcl(3): 1469*5a6e8488SAndroid Build Coastguard Worker 1470*5a6e8488SAndroid Build Coastguard Worker**BC_LONG_BIT** 1471*5a6e8488SAndroid Build Coastguard Worker 1472*5a6e8488SAndroid Build Coastguard Worker: The number of bits in the **long** type in the environment where bcl(3) was 1473*5a6e8488SAndroid Build Coastguard Worker built. This determines how many decimal digits can be stored in a single 1474*5a6e8488SAndroid Build Coastguard Worker large integer (see the **PERFORMANCE** section). 1475*5a6e8488SAndroid Build Coastguard Worker 1476*5a6e8488SAndroid Build Coastguard Worker**BC_BASE_DIGS** 1477*5a6e8488SAndroid Build Coastguard Worker 1478*5a6e8488SAndroid Build Coastguard Worker: The number of decimal digits per large integer (see the **PERFORMANCE** 1479*5a6e8488SAndroid Build Coastguard Worker section). Depends on **BC_LONG_BIT**. 1480*5a6e8488SAndroid Build Coastguard Worker 1481*5a6e8488SAndroid Build Coastguard Worker**BC_BASE_POW** 1482*5a6e8488SAndroid Build Coastguard Worker 1483*5a6e8488SAndroid Build Coastguard Worker: The max decimal number that each large integer can store (see 1484*5a6e8488SAndroid Build Coastguard Worker **BC_BASE_DIGS**) plus **1**. Depends on **BC_BASE_DIGS**. 1485*5a6e8488SAndroid Build Coastguard Worker 1486*5a6e8488SAndroid Build Coastguard Worker**BC_OVERFLOW_MAX** 1487*5a6e8488SAndroid Build Coastguard Worker 1488*5a6e8488SAndroid Build Coastguard Worker: The max number that the overflow type (see the **PERFORMANCE** section) can 1489*5a6e8488SAndroid Build Coastguard Worker hold. Depends on **BC_LONG_BIT**. 1490*5a6e8488SAndroid Build Coastguard Worker 1491*5a6e8488SAndroid Build Coastguard Worker**BC_BASE_MAX** 1492*5a6e8488SAndroid Build Coastguard Worker 1493*5a6e8488SAndroid Build Coastguard Worker: The maximum output base. Set at **BC_BASE_POW**. 1494*5a6e8488SAndroid Build Coastguard Worker 1495*5a6e8488SAndroid Build Coastguard Worker**BC_SCALE_MAX** 1496*5a6e8488SAndroid Build Coastguard Worker 1497*5a6e8488SAndroid Build Coastguard Worker: The maximum **scale**. Set at **BC_OVERFLOW_MAX-1**. 1498*5a6e8488SAndroid Build Coastguard Worker 1499*5a6e8488SAndroid Build Coastguard Worker**BC_NUM_MAX** 1500*5a6e8488SAndroid Build Coastguard Worker 1501*5a6e8488SAndroid Build Coastguard Worker: The maximum length of a number (in decimal digits), which includes digits 1502*5a6e8488SAndroid Build Coastguard Worker after the decimal point. Set at **BC_OVERFLOW_MAX-1**. 1503*5a6e8488SAndroid Build Coastguard Worker 1504*5a6e8488SAndroid Build Coastguard Worker**BC_RAND_MAX** 1505*5a6e8488SAndroid Build Coastguard Worker 1506*5a6e8488SAndroid Build Coastguard Worker: The maximum integer (inclusive) returned by the **bcl_rand_int()** function. 1507*5a6e8488SAndroid Build Coastguard Worker Set at **2\^BC_LONG_BIT-1**. 1508*5a6e8488SAndroid Build Coastguard Worker 1509*5a6e8488SAndroid Build Coastguard WorkerExponent 1510*5a6e8488SAndroid Build Coastguard Worker 1511*5a6e8488SAndroid Build Coastguard Worker: The maximum allowable exponent (positive or negative). Set at 1512*5a6e8488SAndroid Build Coastguard Worker **BC_OVERFLOW_MAX**. 1513*5a6e8488SAndroid Build Coastguard Worker 1514*5a6e8488SAndroid Build Coastguard WorkerThese limits are meant to be effectively non-existent; the limits are so large 1515*5a6e8488SAndroid Build Coastguard Worker(at least on 64-bit machines) that there should not be any point at which they 1516*5a6e8488SAndroid Build Coastguard Workerbecome a problem. In fact, memory should be exhausted before these limits should 1517*5a6e8488SAndroid Build Coastguard Workerbe hit. 1518*5a6e8488SAndroid Build Coastguard Worker 1519*5a6e8488SAndroid Build Coastguard Worker# SEE ALSO 1520*5a6e8488SAndroid Build Coastguard Worker 1521*5a6e8488SAndroid Build Coastguard Workerbc(1) and dc(1) 1522*5a6e8488SAndroid Build Coastguard Worker 1523*5a6e8488SAndroid Build Coastguard Worker# STANDARDS 1524*5a6e8488SAndroid Build Coastguard Worker 1525*5a6e8488SAndroid Build Coastguard Workerbcl(3) is compliant with the arithmetic defined in the IEEE Std 1003.1-2017 1526*5a6e8488SAndroid Build Coastguard Worker(“POSIX.1-2017”) specification at 1527*5a6e8488SAndroid Build Coastguard Workerhttps://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html for bc(1). 1528*5a6e8488SAndroid Build Coastguard Worker 1529*5a6e8488SAndroid Build Coastguard WorkerNote that the specification explicitly says that bc(1) only accepts numbers that 1530*5a6e8488SAndroid Build Coastguard Workeruse a period (**.**) as a radix point, regardless of the value of 1531*5a6e8488SAndroid Build Coastguard Worker**LC_NUMERIC**. This is also true of bcl(3). 1532*5a6e8488SAndroid Build Coastguard Worker 1533*5a6e8488SAndroid Build Coastguard Worker# BUGS 1534*5a6e8488SAndroid Build Coastguard Worker 1535*5a6e8488SAndroid Build Coastguard WorkerNone are known. Report bugs at https://git.gavinhoward.com/gavin/bc. 1536*5a6e8488SAndroid Build Coastguard Worker 1537*5a6e8488SAndroid Build Coastguard Worker# AUTHORS 1538*5a6e8488SAndroid Build Coastguard Worker 1539*5a6e8488SAndroid Build Coastguard WorkerGavin D. Howard <[email protected]> and contributors. 1540