1*5a6e8488SAndroid Build Coastguard Worker# `bc` 2*5a6e8488SAndroid Build Coastguard Worker 3*5a6e8488SAndroid Build Coastguard Worker***WARNING: New user registration for <https://git.gavinhoward.com/> is disabled 4*5a6e8488SAndroid Build Coastguard Workerbecause of spam. If you need to report a bug with `bc`, email gavin at this site 5*5a6e8488SAndroid Build Coastguard Workerminus the `git.` part for an account, and I will create one for you. Or you can 6*5a6e8488SAndroid Build Coastguard Workerreport an issue at [GitHub][29].*** 7*5a6e8488SAndroid Build Coastguard Worker 8*5a6e8488SAndroid Build Coastguard Worker***WARNING: This project has moved to [https://git.gavinhoward.com/][20] for 9*5a6e8488SAndroid Build Coastguard Worker[these reasons][21], though GitHub will remain a mirror.*** 10*5a6e8488SAndroid Build Coastguard Worker 11*5a6e8488SAndroid Build Coastguard WorkerThis is an implementation of the [POSIX `bc` calculator][12] that implements 12*5a6e8488SAndroid Build Coastguard Worker[GNU `bc`][1] extensions, as well as the period (`.`) extension for the BSD 13*5a6e8488SAndroid Build Coastguard Workerflavor of `bc`. 14*5a6e8488SAndroid Build Coastguard Worker 15*5a6e8488SAndroid Build Coastguard WorkerFor more information, see this `bc`'s full manual. 16*5a6e8488SAndroid Build Coastguard Worker 17*5a6e8488SAndroid Build Coastguard WorkerThis `bc` also includes an implementation of `dc` in the same binary, accessible 18*5a6e8488SAndroid Build Coastguard Workervia a symbolic link, which implements all FreeBSD and GNU extensions. (If a 19*5a6e8488SAndroid Build Coastguard Workerstandalone `dc` binary is desired, `bc` can be copied and renamed to `dc`.) The 20*5a6e8488SAndroid Build Coastguard Worker`!` command is omitted; I believe this poses security concerns and that such 21*5a6e8488SAndroid Build Coastguard Workerfunctionality is unnecessary. 22*5a6e8488SAndroid Build Coastguard Worker 23*5a6e8488SAndroid Build Coastguard WorkerFor more information, see the `dc`'s full manual. 24*5a6e8488SAndroid Build Coastguard Worker 25*5a6e8488SAndroid Build Coastguard WorkerThis `bc` also provides `bc`'s math as a library with C bindings, called `bcl`. 26*5a6e8488SAndroid Build Coastguard Worker 27*5a6e8488SAndroid Build Coastguard WorkerFor more information, see the full manual for `bcl`. 28*5a6e8488SAndroid Build Coastguard Worker 29*5a6e8488SAndroid Build Coastguard Worker## License 30*5a6e8488SAndroid Build Coastguard Worker 31*5a6e8488SAndroid Build Coastguard WorkerThis `bc` is Free and Open Source Software (FOSS). It is offered under the BSD 32*5a6e8488SAndroid Build Coastguard Worker2-clause License. Full license text may be found in the [`LICENSE.md`][4] file. 33*5a6e8488SAndroid Build Coastguard Worker 34*5a6e8488SAndroid Build Coastguard Worker## Prerequisites 35*5a6e8488SAndroid Build Coastguard Worker 36*5a6e8488SAndroid Build Coastguard WorkerThis `bc` only requires either: 37*5a6e8488SAndroid Build Coastguard Worker 38*5a6e8488SAndroid Build Coastguard Worker1. Windows 10 or later, or 39*5a6e8488SAndroid Build Coastguard Worker2. A C99-compatible compiler and a (mostly) POSIX 2008-compatible system with 40*5a6e8488SAndroid Build Coastguard Worker the XSI (X/Open System Interfaces) option group. 41*5a6e8488SAndroid Build Coastguard Worker 42*5a6e8488SAndroid Build Coastguard WorkerSince POSIX 2008 with XSI requires the existence of a C99 compiler as `c99`, any 43*5a6e8488SAndroid Build Coastguard WorkerPOSIX and XSI-compatible system will have everything needed. 44*5a6e8488SAndroid Build Coastguard Worker 45*5a6e8488SAndroid Build Coastguard WorkerPOSIX-compatible systems that are known to work: 46*5a6e8488SAndroid Build Coastguard Worker 47*5a6e8488SAndroid Build Coastguard Worker* Linux 48*5a6e8488SAndroid Build Coastguard Worker* FreeBSD 49*5a6e8488SAndroid Build Coastguard Worker* OpenBSD 50*5a6e8488SAndroid Build Coastguard Worker* NetBSD 51*5a6e8488SAndroid Build Coastguard Worker* macOS 52*5a6e8488SAndroid Build Coastguard Worker* Solaris* (as long as the Solaris version supports POSIX 2008) 53*5a6e8488SAndroid Build Coastguard Worker* AIX 54*5a6e8488SAndroid Build Coastguard Worker* HP-UX* (except for history) 55*5a6e8488SAndroid Build Coastguard Worker 56*5a6e8488SAndroid Build Coastguard WorkerIn addition, there is compatibility code to make this `bc` work on Windows. 57*5a6e8488SAndroid Build Coastguard Worker 58*5a6e8488SAndroid Build Coastguard WorkerPlease submit bug reports if this `bc` does not build out of the box on any 59*5a6e8488SAndroid Build Coastguard Workersystem. 60*5a6e8488SAndroid Build Coastguard Worker 61*5a6e8488SAndroid Build Coastguard Worker## Build 62*5a6e8488SAndroid Build Coastguard Worker 63*5a6e8488SAndroid Build Coastguard WorkerThis `bc` should build unmodified on any POSIX-compliant system or on Windows 64*5a6e8488SAndroid Build Coastguard Workerstarting with Windows 10 (though earlier versions may work). 65*5a6e8488SAndroid Build Coastguard Worker 66*5a6e8488SAndroid Build Coastguard WorkerFor more complex build requirements than the ones below, see the [build 67*5a6e8488SAndroid Build Coastguard Workermanual][5]. 68*5a6e8488SAndroid Build Coastguard Worker 69*5a6e8488SAndroid Build Coastguard Worker### Windows 70*5a6e8488SAndroid Build Coastguard Worker 71*5a6e8488SAndroid Build Coastguard WorkerThere is no guarantee that this `bc` will work on any version of Windows earlier 72*5a6e8488SAndroid Build Coastguard Workerthan Windows 10 (I cannot test on earlier versions), but it is guaranteed to 73*5a6e8488SAndroid Build Coastguard Workerwork on Windows 10 at least. 74*5a6e8488SAndroid Build Coastguard Worker 75*5a6e8488SAndroid Build Coastguard WorkerAlso, if building with MSBuild, the MSBuild bundled with Visual Studio is 76*5a6e8488SAndroid Build Coastguard Workerrequired. 77*5a6e8488SAndroid Build Coastguard Worker 78*5a6e8488SAndroid Build Coastguard Worker**Note**: Unlike the POSIX-compatible platforms, only one build configuration is 79*5a6e8488SAndroid Build Coastguard Workersupported on Windows: extra math and history enabled, NLS (locale support) 80*5a6e8488SAndroid Build Coastguard Workerdisabled, with both calculators built. 81*5a6e8488SAndroid Build Coastguard Worker 82*5a6e8488SAndroid Build Coastguard Worker#### `bc` 83*5a6e8488SAndroid Build Coastguard Worker 84*5a6e8488SAndroid Build Coastguard WorkerTo build `bc`, you can open the `vs/bc.sln` file in Visual Studio, select the 85*5a6e8488SAndroid Build Coastguard Workerconfiguration, and build. 86*5a6e8488SAndroid Build Coastguard Worker 87*5a6e8488SAndroid Build Coastguard WorkerYou can also build using MSBuild with the following from the root directory: 88*5a6e8488SAndroid Build Coastguard Worker 89*5a6e8488SAndroid Build Coastguard Worker``` 90*5a6e8488SAndroid Build Coastguard Workermsbuild -property:Configuration=<config> vs/bc.sln 91*5a6e8488SAndroid Build Coastguard Worker``` 92*5a6e8488SAndroid Build Coastguard Worker 93*5a6e8488SAndroid Build Coastguard Workerwhere `<config>` is either one of `Debug` or `Release`. 94*5a6e8488SAndroid Build Coastguard Worker 95*5a6e8488SAndroid Build Coastguard WorkerOn Windows, the calculators are built as `vs/bin/<platform>/<config>/bc.exe` and 96*5a6e8488SAndroid Build Coastguard Worker`vs/bin/<Platform>/<Config>/dc.exe`, where `<platform>` can be either `Win32` or 97*5a6e8488SAndroid Build Coastguard Worker`x64`, and `<config>` can be `Debug` or `Release`. 98*5a6e8488SAndroid Build Coastguard Worker 99*5a6e8488SAndroid Build Coastguard Worker**Note**: On Windows, `dc.exe` is just copied from `bc.exe`; it is not linked. 100*5a6e8488SAndroid Build Coastguard WorkerPatches are welcome for a way to do that. 101*5a6e8488SAndroid Build Coastguard Worker 102*5a6e8488SAndroid Build Coastguard Worker#### `bcl` (Library) 103*5a6e8488SAndroid Build Coastguard Worker 104*5a6e8488SAndroid Build Coastguard WorkerTo build the library, you can open the `vs/bcl.sln` file in Visual Studio, 105*5a6e8488SAndroid Build Coastguard Workerselect the configuration, and build. 106*5a6e8488SAndroid Build Coastguard Worker 107*5a6e8488SAndroid Build Coastguard WorkerYou can also build using MSBuild with the following from the root directory: 108*5a6e8488SAndroid Build Coastguard Worker 109*5a6e8488SAndroid Build Coastguard Worker``` 110*5a6e8488SAndroid Build Coastguard Workermsbuild -property:Configuration=<config> vs/bcl.sln 111*5a6e8488SAndroid Build Coastguard Worker``` 112*5a6e8488SAndroid Build Coastguard Worker 113*5a6e8488SAndroid Build Coastguard Workerwhere `<config>` is either one of `Debug`, `ReleaseMD`, or `ReleaseMT`. 114*5a6e8488SAndroid Build Coastguard Worker 115*5a6e8488SAndroid Build Coastguard WorkerOn Windows, the library is built as `vs/lib/<platform>/<config>/bcl.lib`, where 116*5a6e8488SAndroid Build Coastguard Worker`<platform>` can be either `Win32` or `x64`, and `<config>` can be `Debug`, 117*5a6e8488SAndroid Build Coastguard Worker`ReleaseMD`, or `ReleaseMT`. 118*5a6e8488SAndroid Build Coastguard Worker 119*5a6e8488SAndroid Build Coastguard Worker### POSIX-Compatible Systems 120*5a6e8488SAndroid Build Coastguard Worker 121*5a6e8488SAndroid Build Coastguard WorkerOn POSIX-compatible systems, `bc` is built as `bin/bc` and `dc` is built as 122*5a6e8488SAndroid Build Coastguard Worker`bin/dc` by default. 123*5a6e8488SAndroid Build Coastguard Worker 124*5a6e8488SAndroid Build Coastguard Worker#### Default 125*5a6e8488SAndroid Build Coastguard Worker 126*5a6e8488SAndroid Build Coastguard WorkerFor the default build with optimization, use the following commands in the root 127*5a6e8488SAndroid Build Coastguard Workerdirectory: 128*5a6e8488SAndroid Build Coastguard Worker 129*5a6e8488SAndroid Build Coastguard Worker``` 130*5a6e8488SAndroid Build Coastguard Worker./configure.sh -O3 131*5a6e8488SAndroid Build Coastguard Workermake 132*5a6e8488SAndroid Build Coastguard Worker``` 133*5a6e8488SAndroid Build Coastguard Worker 134*5a6e8488SAndroid Build Coastguard Worker#### One Calculator 135*5a6e8488SAndroid Build Coastguard Worker 136*5a6e8488SAndroid Build Coastguard WorkerTo only build `bc`, use the following commands: 137*5a6e8488SAndroid Build Coastguard Worker 138*5a6e8488SAndroid Build Coastguard Worker``` 139*5a6e8488SAndroid Build Coastguard Worker./configure.sh --disable-dc 140*5a6e8488SAndroid Build Coastguard Workermake 141*5a6e8488SAndroid Build Coastguard Worker``` 142*5a6e8488SAndroid Build Coastguard Worker 143*5a6e8488SAndroid Build Coastguard WorkerTo only build `dc`, use the following commands: 144*5a6e8488SAndroid Build Coastguard Worker 145*5a6e8488SAndroid Build Coastguard Worker``` 146*5a6e8488SAndroid Build Coastguard Worker./configure.sh --disable-bc 147*5a6e8488SAndroid Build Coastguard Workermake 148*5a6e8488SAndroid Build Coastguard Worker``` 149*5a6e8488SAndroid Build Coastguard Worker 150*5a6e8488SAndroid Build Coastguard Worker#### Debug 151*5a6e8488SAndroid Build Coastguard Worker 152*5a6e8488SAndroid Build Coastguard WorkerFor debug builds, use the following commands in the root directory: 153*5a6e8488SAndroid Build Coastguard Worker 154*5a6e8488SAndroid Build Coastguard Worker``` 155*5a6e8488SAndroid Build Coastguard Worker./configure.sh -g 156*5a6e8488SAndroid Build Coastguard Workermake 157*5a6e8488SAndroid Build Coastguard Worker``` 158*5a6e8488SAndroid Build Coastguard Worker 159*5a6e8488SAndroid Build Coastguard Worker#### Install 160*5a6e8488SAndroid Build Coastguard Worker 161*5a6e8488SAndroid Build Coastguard WorkerTo install, use the following command: 162*5a6e8488SAndroid Build Coastguard Worker 163*5a6e8488SAndroid Build Coastguard Worker``` 164*5a6e8488SAndroid Build Coastguard Workermake install 165*5a6e8488SAndroid Build Coastguard Worker``` 166*5a6e8488SAndroid Build Coastguard Worker 167*5a6e8488SAndroid Build Coastguard WorkerBy default, `bc` and `dc` will be installed in `/usr/local`. For installing in 168*5a6e8488SAndroid Build Coastguard Workerother locations, use the `PREFIX` environment variable when running 169*5a6e8488SAndroid Build Coastguard Worker`configure.sh` or pass the `--prefix=<prefix>` option to `configure.sh`. See the 170*5a6e8488SAndroid Build Coastguard Worker[build manual][5], or run `./configure.sh --help`, for more details. 171*5a6e8488SAndroid Build Coastguard Worker 172*5a6e8488SAndroid Build Coastguard Worker#### Library 173*5a6e8488SAndroid Build Coastguard Worker 174*5a6e8488SAndroid Build Coastguard WorkerTo build the math library, pass the `-a` or `--library` options to 175*5a6e8488SAndroid Build Coastguard Worker`configure.sh`: 176*5a6e8488SAndroid Build Coastguard Worker 177*5a6e8488SAndroid Build Coastguard Worker``` 178*5a6e8488SAndroid Build Coastguard Worker./configure.sh -a 179*5a6e8488SAndroid Build Coastguard Worker``` 180*5a6e8488SAndroid Build Coastguard Worker 181*5a6e8488SAndroid Build Coastguard WorkerWhen building the library, the executables are not built. For more information, 182*5a6e8488SAndroid Build Coastguard Workersee the [build manual][5]. 183*5a6e8488SAndroid Build Coastguard Worker 184*5a6e8488SAndroid Build Coastguard WorkerThe library API can be found in [`manuals/bcl.3.md`][26] or `man bcl` once the 185*5a6e8488SAndroid Build Coastguard Workerlibrary is installed. 186*5a6e8488SAndroid Build Coastguard Worker 187*5a6e8488SAndroid Build Coastguard Worker#### Package and Distro Maintainers 188*5a6e8488SAndroid Build Coastguard Worker 189*5a6e8488SAndroid Build Coastguard WorkerThis section is for package and distro maintainers. 190*5a6e8488SAndroid Build Coastguard Worker 191*5a6e8488SAndroid Build Coastguard Worker##### Out-of-Source Builds 192*5a6e8488SAndroid Build Coastguard Worker 193*5a6e8488SAndroid Build Coastguard WorkerOut-of-source builds are supported; just call `configure.sh` from the directory 194*5a6e8488SAndroid Build Coastguard Workerwhere the actual build will happen. 195*5a6e8488SAndroid Build Coastguard Worker 196*5a6e8488SAndroid Build Coastguard WorkerFor example, if the source is in `bc`, the build should happen in `build`, then 197*5a6e8488SAndroid Build Coastguard Workercall `configure.sh` and `make` like so: 198*5a6e8488SAndroid Build Coastguard Worker 199*5a6e8488SAndroid Build Coastguard Worker``` 200*5a6e8488SAndroid Build Coastguard Worker../bc/configure.sh 201*5a6e8488SAndroid Build Coastguard Workermake 202*5a6e8488SAndroid Build Coastguard Worker``` 203*5a6e8488SAndroid Build Coastguard Worker 204*5a6e8488SAndroid Build Coastguard Worker***WARNING***: The path to `configure.sh` from the build directory must not have 205*5a6e8488SAndroid Build Coastguard Workerspaces because `make` does not support target names with spaces. 206*5a6e8488SAndroid Build Coastguard Worker 207*5a6e8488SAndroid Build Coastguard Worker##### Recommended Compiler 208*5a6e8488SAndroid Build Coastguard Worker 209*5a6e8488SAndroid Build Coastguard WorkerWhen I ran benchmarks with my `bc` compiled under `clang`, it performed much 210*5a6e8488SAndroid Build Coastguard Workerbetter than when compiled under `gcc`. I recommend compiling this `bc` with 211*5a6e8488SAndroid Build Coastguard Worker`clang`. 212*5a6e8488SAndroid Build Coastguard Worker 213*5a6e8488SAndroid Build Coastguard WorkerI also recommend building this `bc` with C11 if you can because `bc` will detect 214*5a6e8488SAndroid Build Coastguard Workera C11 compiler and add `_Noreturn` to any relevant function(s). 215*5a6e8488SAndroid Build Coastguard Worker 216*5a6e8488SAndroid Build Coastguard Worker##### Recommended Optimizations 217*5a6e8488SAndroid Build Coastguard Worker 218*5a6e8488SAndroid Build Coastguard WorkerI wrote this `bc` with Separation of Concerns, which means that there are many 219*5a6e8488SAndroid Build Coastguard Workersmall functions that could be inlined. However, they are often called across 220*5a6e8488SAndroid Build Coastguard Workerfile boundaries, and the default optimizer can only look at the current file, 221*5a6e8488SAndroid Build Coastguard Workerwhich means that they are not inlined. 222*5a6e8488SAndroid Build Coastguard Worker 223*5a6e8488SAndroid Build Coastguard WorkerThus, because of the way this `bc` is built, it will automatically be slower 224*5a6e8488SAndroid Build Coastguard Workerthan other `bc` implementations when running scripts with no math. (My `bc`'s 225*5a6e8488SAndroid Build Coastguard Workermath is *much* faster, so any non-trivial script should run faster in my `bc`.) 226*5a6e8488SAndroid Build Coastguard Worker 227*5a6e8488SAndroid Build Coastguard WorkerSome, or all, of the difference can be made up with the right optimizations. The 228*5a6e8488SAndroid Build Coastguard Workeroptimizations I recommend are: 229*5a6e8488SAndroid Build Coastguard Worker 230*5a6e8488SAndroid Build Coastguard Worker1. `-O3` 231*5a6e8488SAndroid Build Coastguard Worker2. `-flto` (link-time optimization) 232*5a6e8488SAndroid Build Coastguard Worker 233*5a6e8488SAndroid Build Coastguard Workerin that order. 234*5a6e8488SAndroid Build Coastguard Worker 235*5a6e8488SAndroid Build Coastguard WorkerLink-time optimization, in particular, speeds up the `bc` a lot. This is because 236*5a6e8488SAndroid Build Coastguard Workerwhen link-time optimization is turned on, the optimizer can look across files 237*5a6e8488SAndroid Build Coastguard Workerand inline *much* more heavily. 238*5a6e8488SAndroid Build Coastguard Worker 239*5a6e8488SAndroid Build Coastguard WorkerHowever, I recommend ***NOT*** using `-march=native`. Doing so will reduce this 240*5a6e8488SAndroid Build Coastguard Worker`bc`'s performance, at least when building with link-time optimization. See the 241*5a6e8488SAndroid Build Coastguard Worker[benchmarks][19] for more details. 242*5a6e8488SAndroid Build Coastguard Worker 243*5a6e8488SAndroid Build Coastguard Worker##### Stripping Binaries 244*5a6e8488SAndroid Build Coastguard Worker 245*5a6e8488SAndroid Build Coastguard WorkerBy default, non-debug binaries are stripped, but stripping can be disabled with 246*5a6e8488SAndroid Build Coastguard Workerthe `-T` option to `configure.sh`. 247*5a6e8488SAndroid Build Coastguard Worker 248*5a6e8488SAndroid Build Coastguard Worker##### Using This `bc` as an Alternative 249*5a6e8488SAndroid Build Coastguard Worker 250*5a6e8488SAndroid Build Coastguard WorkerIf this `bc` is packaged as an alternative to an already existing `bc` package, 251*5a6e8488SAndroid Build Coastguard Workerit is possible to rename it in the build to prevent name collision. To prepend 252*5a6e8488SAndroid Build Coastguard Workerto the name, just run the following: 253*5a6e8488SAndroid Build Coastguard Worker 254*5a6e8488SAndroid Build Coastguard Worker``` 255*5a6e8488SAndroid Build Coastguard WorkerEXECPREFIX=<some_prefix> ./configure.sh 256*5a6e8488SAndroid Build Coastguard Worker``` 257*5a6e8488SAndroid Build Coastguard Worker 258*5a6e8488SAndroid Build Coastguard WorkerTo append to the name, just run the following: 259*5a6e8488SAndroid Build Coastguard Worker 260*5a6e8488SAndroid Build Coastguard Worker``` 261*5a6e8488SAndroid Build Coastguard WorkerEXECSUFFIX=<some_suffix> ./configure.sh 262*5a6e8488SAndroid Build Coastguard Worker``` 263*5a6e8488SAndroid Build Coastguard Worker 264*5a6e8488SAndroid Build Coastguard WorkerIf a package maintainer wishes to add both a prefix and a suffix, that is 265*5a6e8488SAndroid Build Coastguard Workerallowed. 266*5a6e8488SAndroid Build Coastguard Worker 267*5a6e8488SAndroid Build Coastguard Worker**Note**: The suggested name (and package name) when `bc` is not available is 268*5a6e8488SAndroid Build Coastguard Worker`bc-gh`. 269*5a6e8488SAndroid Build Coastguard Worker 270*5a6e8488SAndroid Build Coastguard Worker##### Karatsuba Number 271*5a6e8488SAndroid Build Coastguard Worker 272*5a6e8488SAndroid Build Coastguard WorkerPackage and distro maintainers have one tool at their disposal to build this 273*5a6e8488SAndroid Build Coastguard Worker`bc` in the optimal configuration: `scripts/karatsuba.py`. 274*5a6e8488SAndroid Build Coastguard Worker 275*5a6e8488SAndroid Build Coastguard WorkerThis script is not a compile-time or runtime prerequisite; it is for package and 276*5a6e8488SAndroid Build Coastguard Workerdistro maintainers to run once when a package is being created. It finds the 277*5a6e8488SAndroid Build Coastguard Workeroptimal Karatsuba number (see the [algorithms manual][7] for more information) 278*5a6e8488SAndroid Build Coastguard Workerfor the machine that it is running on. 279*5a6e8488SAndroid Build Coastguard Worker 280*5a6e8488SAndroid Build Coastguard WorkerThe easiest way to run this script is with `make karatsuba`. 281*5a6e8488SAndroid Build Coastguard Worker 282*5a6e8488SAndroid Build Coastguard WorkerIf desired, maintainers can also skip running this script because there is a 283*5a6e8488SAndroid Build Coastguard Workersane default for the Karatsuba number. 284*5a6e8488SAndroid Build Coastguard Worker 285*5a6e8488SAndroid Build Coastguard Worker## Status 286*5a6e8488SAndroid Build Coastguard Worker 287*5a6e8488SAndroid Build Coastguard WorkerThis `bc` is robust. 288*5a6e8488SAndroid Build Coastguard Worker 289*5a6e8488SAndroid Build Coastguard WorkerIt is well-tested, fuzzed, and fully standards-compliant (though not certified) 290*5a6e8488SAndroid Build Coastguard Workerwith POSIX `bc`. The math has been tested with 40+ million random problems, so 291*5a6e8488SAndroid Build Coastguard Workerit is as correct as I can make it. 292*5a6e8488SAndroid Build Coastguard Worker 293*5a6e8488SAndroid Build Coastguard WorkerThis `bc` can be used as a drop-in replacement for any existing `bc`. This `bc` 294*5a6e8488SAndroid Build Coastguard Workeris also compatible with MinGW toolchains. 295*5a6e8488SAndroid Build Coastguard Worker 296*5a6e8488SAndroid Build Coastguard WorkerIn addition, this `bc` is considered complete; i.e., there will be no more 297*5a6e8488SAndroid Build Coastguard Workerreleases with additional features. However, it *is* actively maintained, so if 298*5a6e8488SAndroid Build Coastguard Workerany bugs are found, they will be fixed in new releases. Also, additional 299*5a6e8488SAndroid Build Coastguard Workertranslations will also be added as they are provided. 300*5a6e8488SAndroid Build Coastguard Worker 301*5a6e8488SAndroid Build Coastguard Worker### Development 302*5a6e8488SAndroid Build Coastguard Worker 303*5a6e8488SAndroid Build Coastguard WorkerIf I (Gavin D. Howard) get [hit by a bus][27] and future programmers need to 304*5a6e8488SAndroid Build Coastguard Workerhandle work themselves, the best place to start is the [Development manual][28]. 305*5a6e8488SAndroid Build Coastguard Worker 306*5a6e8488SAndroid Build Coastguard Worker## Vim Syntax 307*5a6e8488SAndroid Build Coastguard Worker 308*5a6e8488SAndroid Build Coastguard WorkerI have developed (using other people's code to start) [`vim` syntax files][17] 309*5a6e8488SAndroid Build Coastguard Workerfor this `bc` and `dc`, including the extensions. 310*5a6e8488SAndroid Build Coastguard Worker 311*5a6e8488SAndroid Build Coastguard Worker## `bc` Libs 312*5a6e8488SAndroid Build Coastguard Worker 313*5a6e8488SAndroid Build Coastguard WorkerI have gathered some excellent [`bc` and `dc` libraries][18]. These libraries 314*5a6e8488SAndroid Build Coastguard Workermay prove useful to any serious users. 315*5a6e8488SAndroid Build Coastguard Worker 316*5a6e8488SAndroid Build Coastguard Worker## Comparison to GNU `bc` 317*5a6e8488SAndroid Build Coastguard Worker 318*5a6e8488SAndroid Build Coastguard WorkerThis `bc` compares favorably to GNU `bc`. 319*5a6e8488SAndroid Build Coastguard Worker 320*5a6e8488SAndroid Build Coastguard Worker* This `bc` builds natively on Windows. 321*5a6e8488SAndroid Build Coastguard Worker* It has more extensions, which make this `bc` more useful for scripting. (See 322*5a6e8488SAndroid Build Coastguard Worker [Extensions](#extensions).) 323*5a6e8488SAndroid Build Coastguard Worker* This `bc` is a bit more POSIX compliant. 324*5a6e8488SAndroid Build Coastguard Worker* It has a much less buggy parser. The GNU `bc` will give parse errors for what 325*5a6e8488SAndroid Build Coastguard Worker is actually valid `bc` code, or should be. For example, putting an `else` on 326*5a6e8488SAndroid Build Coastguard Worker a new line after a brace can cause GNU `bc` to give a parse error. 327*5a6e8488SAndroid Build Coastguard Worker* This `bc` has fewer crashes. 328*5a6e8488SAndroid Build Coastguard Worker* GNU `bc` calculates the wrong number of significant digits for `length(x)`. 329*5a6e8488SAndroid Build Coastguard Worker* GNU `bc` will sometimes print numbers incorrectly. For example, when running 330*5a6e8488SAndroid Build Coastguard Worker it on the file `tests/bc/power.txt` in this repo, GNU `bc` gets all the right 331*5a6e8488SAndroid Build Coastguard Worker answers, but it fails to wrap the numbers at the proper place when outputting 332*5a6e8488SAndroid Build Coastguard Worker to a file. 333*5a6e8488SAndroid Build Coastguard Worker* This `bc` is faster. (See [Performance](#performance).) 334*5a6e8488SAndroid Build Coastguard Worker 335*5a6e8488SAndroid Build Coastguard Worker### Performance 336*5a6e8488SAndroid Build Coastguard Worker 337*5a6e8488SAndroid Build Coastguard WorkerBecause this `bc` packs more than `1` decimal digit per hardware integer, this 338*5a6e8488SAndroid Build Coastguard Worker`bc` is faster than GNU `bc` and can be *much* faster. Full benchmarks can be 339*5a6e8488SAndroid Build Coastguard Workerfound at [manuals/benchmarks.md][19]. 340*5a6e8488SAndroid Build Coastguard Worker 341*5a6e8488SAndroid Build Coastguard WorkerThere is one instance where this `bc` is slower: if scripts are light on math. 342*5a6e8488SAndroid Build Coastguard WorkerThis is because this `bc`'s intepreter is slightly slower than GNU `bc`, but 343*5a6e8488SAndroid Build Coastguard Workerthat is because it is more robust. See the [benchmarks][19]. 344*5a6e8488SAndroid Build Coastguard Worker 345*5a6e8488SAndroid Build Coastguard Worker### Extensions 346*5a6e8488SAndroid Build Coastguard Worker 347*5a6e8488SAndroid Build Coastguard WorkerBelow is a non-comprehensive list of extensions that this `bc` and `dc` have 348*5a6e8488SAndroid Build Coastguard Workerthat all others do not. 349*5a6e8488SAndroid Build Coastguard Worker 350*5a6e8488SAndroid Build Coastguard Worker* **The `!` operator has higher precedence than the `!` operator in other `bc` 351*5a6e8488SAndroid Build Coastguard Worker implementations.** 352*5a6e8488SAndroid Build Coastguard Worker* An extended math library. (See [here][30] for more information.) 353*5a6e8488SAndroid Build Coastguard Worker* A command-line prompt. 354*5a6e8488SAndroid Build Coastguard Worker* Turning on and off digit clamping. (Digit clamping is about how to treat 355*5a6e8488SAndroid Build Coastguard Worker "invalid" digits for a particular base. GNU `bc` uses it, and the BSD `bc` 356*5a6e8488SAndroid Build Coastguard Worker does not. Mine does both.) 357*5a6e8488SAndroid Build Coastguard Worker* A pseudo-random number generator. This includes the ability to set the seed 358*5a6e8488SAndroid Build Coastguard Worker and get reproducible streams of random numbers. 359*5a6e8488SAndroid Build Coastguard Worker* The ability to use stacks for the globals `scale`, `ibase`, and `obase` 360*5a6e8488SAndroid Build Coastguard Worker instead of needing to restore them in *every* function. 361*5a6e8488SAndroid Build Coastguard Worker* The ability to *not* use non-standard keywords. For example, `abs` is a 362*5a6e8488SAndroid Build Coastguard Worker keyword (a built-in function), but if some script actually defines a function 363*5a6e8488SAndroid Build Coastguard Worker called that, it's possible to tell my `bc` to not treat it as a keyword, which 364*5a6e8488SAndroid Build Coastguard Worker will make the script parses correctly. 365*5a6e8488SAndroid Build Coastguard Worker* The ability to turn on and off printing leading zeroes on numbers greater than 366*5a6e8488SAndroid Build Coastguard Worker `-1` and less than `1`. 367*5a6e8488SAndroid Build Coastguard Worker* Outputting in scientific and engineering notation. 368*5a6e8488SAndroid Build Coastguard Worker* Accepting input in scientific and engineering notation. 369*5a6e8488SAndroid Build Coastguard Worker* Passing strings and arrays to the `length()` built-in function. (In `dc`, the 370*5a6e8488SAndroid Build Coastguard Worker `Y` command will do this for arrays, and the `Z` command will do this for both 371*5a6e8488SAndroid Build Coastguard Worker numbers and strings.) 372*5a6e8488SAndroid Build Coastguard Worker* The `abs()` built-in function. (This is the `b` command in `dc`.) 373*5a6e8488SAndroid Build Coastguard Worker* The `is_number()` and `is_string()` built-in functions. (These tell whether a 374*5a6e8488SAndroid Build Coastguard Worker variable is holding a string or a number, for runtime type checking. The 375*5a6e8488SAndroid Build Coastguard Worker commands are `u` and `t` in `dc`.) 376*5a6e8488SAndroid Build Coastguard Worker* For `bc` only, the `divmod()` built-in function for computing a quotient and 377*5a6e8488SAndroid Build Coastguard Worker remainder at the same time. 378*5a6e8488SAndroid Build Coastguard Worker* For `bc` only, the `asciify()` built-in function for converting an array to a 379*5a6e8488SAndroid Build Coastguard Worker string. 380*5a6e8488SAndroid Build Coastguard Worker* The `$` truncation operator. (It's the same in `bc` and `dc`.) 381*5a6e8488SAndroid Build Coastguard Worker* The `@` "set scale" operator. (It's the same in `bc` and `dc`.) 382*5a6e8488SAndroid Build Coastguard Worker* The decimal shift operators. (`<<` and `>>` in `bc`, `H` and `h` in `dc`.) 383*5a6e8488SAndroid Build Coastguard Worker* Built-in functions or commands to get the max of `scale`, `ibase`, and 384*5a6e8488SAndroid Build Coastguard Worker `obase`. 385*5a6e8488SAndroid Build Coastguard Worker* The ability to put strings into variables in `bc`. (This always existed in 386*5a6e8488SAndroid Build Coastguard Worker `dc`.) 387*5a6e8488SAndroid Build Coastguard Worker* The `'` command in `dc` for the depth of the execution stack. 388*5a6e8488SAndroid Build Coastguard Worker* The `y` command in `dc` for the depth of register stacks. 389*5a6e8488SAndroid Build Coastguard Worker* Built-in functions or commands to get the value of certain environment 390*5a6e8488SAndroid Build Coastguard Worker variables that might affect execution. 391*5a6e8488SAndroid Build Coastguard Worker* The `stream` keyword to do the same thing as the `P` command in `dc`. 392*5a6e8488SAndroid Build Coastguard Worker* Defined order of evaluation. 393*5a6e8488SAndroid Build Coastguard Worker* Defined exit statuses. 394*5a6e8488SAndroid Build Coastguard Worker* All environment variables other than `POSIXLY_CORRECT`, `BC_ENV_ARGS`, and 395*5a6e8488SAndroid Build Coastguard Worker `BC_LINE_LENGTH`. 396*5a6e8488SAndroid Build Coastguard Worker* The ability for users to define their own defaults for various options during 397*5a6e8488SAndroid Build Coastguard Worker build. (See [here][31] for more information.) 398*5a6e8488SAndroid Build Coastguard Worker 399*5a6e8488SAndroid Build Coastguard Worker## Algorithms 400*5a6e8488SAndroid Build Coastguard Worker 401*5a6e8488SAndroid Build Coastguard WorkerTo see what algorithms this `bc` uses, see the [algorithms manual][7]. 402*5a6e8488SAndroid Build Coastguard Worker 403*5a6e8488SAndroid Build Coastguard Worker## Locales 404*5a6e8488SAndroid Build Coastguard Worker 405*5a6e8488SAndroid Build Coastguard WorkerCurrently, there is no locale support on Windows. 406*5a6e8488SAndroid Build Coastguard Worker 407*5a6e8488SAndroid Build Coastguard WorkerAdditionally, this `bc` only has support for English (and US English), French, 408*5a6e8488SAndroid Build Coastguard WorkerGerman, Portuguese, Dutch, Polish, Russian, Japanese, and Chinese locales. 409*5a6e8488SAndroid Build Coastguard WorkerPatches are welcome for translations; use the existing `*.msg` files in 410*5a6e8488SAndroid Build Coastguard Worker`locales/` as a starting point. 411*5a6e8488SAndroid Build Coastguard Worker 412*5a6e8488SAndroid Build Coastguard WorkerIn addition, patches for improvements are welcome; the last two messages in 413*5a6e8488SAndroid Build Coastguard WorkerPortuguese were made with Google Translate, and the Dutch, Polish, Russian, 414*5a6e8488SAndroid Build Coastguard WorkerJapanese, and Chinese locales were all generated with [DeepL][22]. 415*5a6e8488SAndroid Build Coastguard Worker 416*5a6e8488SAndroid Build Coastguard WorkerThe message files provided assume that locales apply to all regions where a 417*5a6e8488SAndroid Build Coastguard Workerlanguage is used, but this might not be true for, e.g., `fr_CA` and `fr_CH`. 418*5a6e8488SAndroid Build Coastguard WorkerAny corrections or a confirmation that the current texts are acceptable for 419*5a6e8488SAndroid Build Coastguard Workerthose regions would be appreciated, too. 420*5a6e8488SAndroid Build Coastguard Worker 421*5a6e8488SAndroid Build Coastguard Worker## Other Projects 422*5a6e8488SAndroid Build Coastguard Worker 423*5a6e8488SAndroid Build Coastguard WorkerOther projects based on this bc are: 424*5a6e8488SAndroid Build Coastguard Worker 425*5a6e8488SAndroid Build Coastguard Worker* [busybox `bc`][8]. The busybox maintainers have made their own changes, so any 426*5a6e8488SAndroid Build Coastguard Worker bugs in the busybox `bc` should be reported to them. 427*5a6e8488SAndroid Build Coastguard Worker* [toybox `bc`][9]. The maintainer has also made his own changes, so bugs in the 428*5a6e8488SAndroid Build Coastguard Worker toybox `bc` should be reported there. 429*5a6e8488SAndroid Build Coastguard Worker* [FreeBSD `bc`][23]. While the `bc` in FreeBSD is kept up-to-date, it is better 430*5a6e8488SAndroid Build Coastguard Worker to [report bugs there][24], as well as [submit patches][25], and the 431*5a6e8488SAndroid Build Coastguard Worker maintainers of the package will contact me if necessary. 432*5a6e8488SAndroid Build Coastguard Worker* [macOS `bc`][35]. Any bugs in that `bc` should be reported to me, but do 433*5a6e8488SAndroid Build Coastguard Worker expect bugs because the version is old. 434*5a6e8488SAndroid Build Coastguard Worker* [Android Open Source `bc`][32]. Any bugs in that `bc` can be reported here. 435*5a6e8488SAndroid Build Coastguard Worker* [A Fedora package][36]. If this package does not have any patches, you can 436*5a6e8488SAndroid Build Coastguard Worker report bugs to me. 437*5a6e8488SAndroid Build Coastguard Worker 438*5a6e8488SAndroid Build Coastguard WorkerThis is a non-comprehensive list of Linux distros that use this `bc` as the 439*5a6e8488SAndroid Build Coastguard Workersystem `bc`: 440*5a6e8488SAndroid Build Coastguard Worker 441*5a6e8488SAndroid Build Coastguard Worker* [Gentoo][33]; it is a first-class alternative to GNU `bc`, but not exclusive. 442*5a6e8488SAndroid Build Coastguard Worker* [Linux from Scratch][34]. 443*5a6e8488SAndroid Build Coastguard Worker 444*5a6e8488SAndroid Build Coastguard WorkerOther Linux distros package it as a second-class alternative, usually as `bc-gh` 445*5a6e8488SAndroid Build Coastguard Workeror `howard-bc`. 446*5a6e8488SAndroid Build Coastguard Worker 447*5a6e8488SAndroid Build Coastguard Worker## Language 448*5a6e8488SAndroid Build Coastguard Worker 449*5a6e8488SAndroid Build Coastguard WorkerThis `bc` is written in pure ISO C99, using POSIX 2008 APIs with custom Windows 450*5a6e8488SAndroid Build Coastguard Workercompatibility code. 451*5a6e8488SAndroid Build Coastguard Worker 452*5a6e8488SAndroid Build Coastguard Worker## Commit Messages 453*5a6e8488SAndroid Build Coastguard Worker 454*5a6e8488SAndroid Build Coastguard WorkerThis `bc` uses the commit message guidelines laid out in [this blog post][10]. 455*5a6e8488SAndroid Build Coastguard Worker 456*5a6e8488SAndroid Build Coastguard Worker## Semantic Versioning 457*5a6e8488SAndroid Build Coastguard Worker 458*5a6e8488SAndroid Build Coastguard WorkerThis `bc` uses [semantic versioning][11]. 459*5a6e8488SAndroid Build Coastguard Worker 460*5a6e8488SAndroid Build Coastguard Worker## AI-Free 461*5a6e8488SAndroid Build Coastguard Worker 462*5a6e8488SAndroid Build Coastguard WorkerThis repository is 100% AI-Free code. 463*5a6e8488SAndroid Build Coastguard Worker 464*5a6e8488SAndroid Build Coastguard Worker## Contents 465*5a6e8488SAndroid Build Coastguard Worker 466*5a6e8488SAndroid Build Coastguard WorkerItems labeled with `(maintainer use only)` are not included in release source 467*5a6e8488SAndroid Build Coastguard Workertarballs. 468*5a6e8488SAndroid Build Coastguard Worker 469*5a6e8488SAndroid Build Coastguard WorkerFiles: 470*5a6e8488SAndroid Build Coastguard Worker 471*5a6e8488SAndroid Build Coastguard Worker .gitignore The git ignore file (maintainer use only). 472*5a6e8488SAndroid Build Coastguard Worker .gitattributes The git attributes file (maintainer use only). 473*5a6e8488SAndroid Build Coastguard Worker bcl.pc.in A template pkg-config file for bcl. 474*5a6e8488SAndroid Build Coastguard Worker configure A symlink to configure.sh to make packaging easier. 475*5a6e8488SAndroid Build Coastguard Worker configure.sh The configure script. 476*5a6e8488SAndroid Build Coastguard Worker LICENSE.md A Markdown form of the BSD 2-clause License. 477*5a6e8488SAndroid Build Coastguard Worker Makefile.in The Makefile template. 478*5a6e8488SAndroid Build Coastguard Worker NEWS.md The changelog. 479*5a6e8488SAndroid Build Coastguard Worker NOTICE.md List of contributors and copyright owners. 480*5a6e8488SAndroid Build Coastguard Worker 481*5a6e8488SAndroid Build Coastguard WorkerFolders: 482*5a6e8488SAndroid Build Coastguard Worker 483*5a6e8488SAndroid Build Coastguard Worker benchmarks A folder of benchmarks for various aspects of bc performance. 484*5a6e8488SAndroid Build Coastguard Worker gen The bc math library, help texts, and code to generate C source. 485*5a6e8488SAndroid Build Coastguard Worker include All header files. 486*5a6e8488SAndroid Build Coastguard Worker locales Locale files, in .msg format. Patches welcome for translations. 487*5a6e8488SAndroid Build Coastguard Worker manuals Manuals for both programs. 488*5a6e8488SAndroid Build Coastguard Worker src All source code. 489*5a6e8488SAndroid Build Coastguard Worker scripts A bunch of shell scripts to help with development and building. 490*5a6e8488SAndroid Build Coastguard Worker tests All tests. 491*5a6e8488SAndroid Build Coastguard Worker vs Files needed for the build on Windows. 492*5a6e8488SAndroid Build Coastguard Worker 493*5a6e8488SAndroid Build Coastguard Worker[1]: https://www.gnu.org/software/bc/ 494*5a6e8488SAndroid Build Coastguard Worker[4]: ./LICENSE.md 495*5a6e8488SAndroid Build Coastguard Worker[5]: ./manuals/build.md 496*5a6e8488SAndroid Build Coastguard Worker[7]: ./manuals/algorithms.md 497*5a6e8488SAndroid Build Coastguard Worker[8]: https://git.busybox.net/busybox/tree/miscutils/bc.c 498*5a6e8488SAndroid Build Coastguard Worker[9]: https://github.com/landley/toybox/blob/master/toys/pending/bc.c 499*5a6e8488SAndroid Build Coastguard Worker[10]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html 500*5a6e8488SAndroid Build Coastguard Worker[11]: http://semver.org/ 501*5a6e8488SAndroid Build Coastguard Worker[12]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html 502*5a6e8488SAndroid Build Coastguard Worker[17]: https://git.gavinhoward.com/gavin/vim-bc 503*5a6e8488SAndroid Build Coastguard Worker[18]: https://git.gavinhoward.com/gavin/bc_libs 504*5a6e8488SAndroid Build Coastguard Worker[19]: ./manuals/benchmarks.md 505*5a6e8488SAndroid Build Coastguard Worker[20]: https://git.gavinhoward.com/gavin/bc 506*5a6e8488SAndroid Build Coastguard Worker[21]: https://gavinhoward.com/2020/04/i-am-moving-away-from-github/ 507*5a6e8488SAndroid Build Coastguard Worker[22]: https://www.deepl.com/translator 508*5a6e8488SAndroid Build Coastguard Worker[23]: https://cgit.freebsd.org/src/tree/contrib/bc 509*5a6e8488SAndroid Build Coastguard Worker[24]: https://bugs.freebsd.org/ 510*5a6e8488SAndroid Build Coastguard Worker[25]: https://reviews.freebsd.org/ 511*5a6e8488SAndroid Build Coastguard Worker[26]: ./manuals/bcl.3.md 512*5a6e8488SAndroid Build Coastguard Worker[27]: https://en.wikipedia.org/wiki/Bus_factor 513*5a6e8488SAndroid Build Coastguard Worker[28]: ./manuals/development.md 514*5a6e8488SAndroid Build Coastguard Worker[29]: https://github.com/gavinhoward/bc 515*5a6e8488SAndroid Build Coastguard Worker[30]: ./manuals/bc/A.1.md#extended-library 516*5a6e8488SAndroid Build Coastguard Worker[31]: ./manuals/build.md#settings 517*5a6e8488SAndroid Build Coastguard Worker[32]: https://android.googlesource.com/platform/external/bc/ 518*5a6e8488SAndroid Build Coastguard Worker[33]: https://github.com/gentoo/gentoo/blob/master/app-alternatives/bc/bc-0.ebuild#L8 519*5a6e8488SAndroid Build Coastguard Worker[34]: https://www.linuxfromscratch.org/lfs/view/stable/chapter08/bc.html 520*5a6e8488SAndroid Build Coastguard Worker[35]: https://github.com/apple-oss-distributions/bc/tree/main/bc 521*5a6e8488SAndroid Build Coastguard Worker[36]: https://copr.fedorainfracloud.org/coprs/tkbcopr/bc-gh/ 522