3 ***WARNING: New user registration for https://git.yzena.com/ is disabled because
4 of spam. If you need to report a bug with `bc`, email gavin at this site minus
5 the `git.` part for an account, and I will create one for you. Or you can report
6 an issue at [GitHub][29].***
8 ***WARNING: This project has moved to [https://git.yzena.com/][20] for [these
9 reasons][21], though GitHub will remain a mirror.***
11 This is an implementation of the [POSIX `bc` calculator][12] that implements
12 [GNU `bc`][1] extensions, as well as the period (`.`) extension for the BSD
15 For more information, see this `bc`'s full manual.
17 This `bc` also includes an implementation of `dc` in the same binary, accessible
18 via a symbolic link, which implements all FreeBSD and GNU extensions. (If a
19 standalone `dc` binary is desired, `bc` can be copied and renamed to `dc`.) The
20 `!` command is omitted; I believe this poses security concerns and that such
21 functionality is unnecessary.
23 For more information, see the `dc`'s full manual.
25 This `bc` also provides `bc`'s math as a library with C bindings, called `bcl`.
27 For more information, see the full manual for `bcl`.
31 This `bc` is Free and Open Source Software (FOSS). It is offered under the BSD
32 2-clause License. Full license text may be found in the [`LICENSE.md`][4] file.
36 This `bc` only requires either:
38 1. Windows 10 or later, or
39 2. A C99-compatible compiler and a (mostly) POSIX 2008-compatible system with
40 the XSI (X/Open System Interfaces) option group.
42 Since POSIX 2008 with XSI requires the existence of a C99 compiler as `c99`, any
43 POSIX and XSI-compatible system will have everything needed.
45 POSIX-compatible systems that are known to work:
52 * Solaris* (as long as the Solaris version supports POSIX 2008)
54 * HP-UX* (except for history)
56 In addition, there is compatibility code to make this `bc` work on Windows.
58 Please submit bug reports if this `bc` does not build out of the box on any
63 This `bc` should build unmodified on any POSIX-compliant system or on Windows
64 starting with Windows 10 (though earlier versions may work).
66 For more complex build requirements than the ones below, see the [build
71 There is no guarantee that this `bc` will work on any version of Windows earlier
72 than Windows 10 (I cannot test on earlier versions), but it is guaranteed to
73 work on Windows 10 at least.
75 Also, if building with MSBuild, the MSBuild bundled with Visual Studio is
78 **Note**: Unlike the POSIX-compatible platforms, only one build configuration is
79 supported on Windows: extra math and history enabled, NLS (locale support)
80 disabled, with both calculators built.
84 To build `bc`, you can open the `vs/bc.sln` file in Visual Studio, select the
85 configuration, and build.
87 You can also build using MSBuild with the following from the root directory:
90 msbuild -property:Configuration=<config> vs/bc.sln
93 where `<config>` is either one of `Debug` or `Release`.
95 On Windows, the calculators are built as `vs/bin/<platform>/<config>/bc.exe` and
96 `vs/bin/<Platform>/<Config>/dc.exe`, where `<platform>` can be either `Win32` or
97 `x64`, and `<config>` can be `Debug` or `Release`.
99 **Note**: On Windows, `dc.exe` is just copied from `bc.exe`; it is not linked.
100 Patches are welcome for a way to do that.
104 To build the library, you can open the `vs/bcl.sln` file in Visual Studio,
105 select the configuration, and build.
107 You can also build using MSBuild with the following from the root directory:
110 msbuild -property:Configuration=<config> vs/bcl.sln
113 where `<config>` is either one of `Debug`, `ReleaseMD`, or `ReleaseMT`.
115 On Windows, the library is built as `vs/lib/<platform>/<config>/bcl.lib`, where
116 `<platform>` can be either `Win32` or `x64`, and `<config>` can be `Debug`,
117 `ReleaseMD`, or `ReleaseMT`.
119 ### POSIX-Compatible Systems
121 On POSIX-compatible systems, `bc` is built as `bin/bc` and `dc` is built as
126 For the default build with optimization, use the following commands in the root
136 To only build `bc`, use the following commands:
139 ./configure.sh --disable-dc
143 To only build `dc`, use the following commands:
146 ./configure.sh --disable-bc
152 For debug builds, use the following commands in the root directory:
161 To install, use the following command:
167 By default, `bc` and `dc` will be installed in `/usr/local`. For installing in
168 other locations, use the `PREFIX` environment variable when running
169 `configure.sh` or pass the `--prefix=<prefix>` option to `configure.sh`. See the
170 [build manual][5], or run `./configure.sh --help`, for more details.
174 This `bc` does provide a way to build a math library with C bindings. This is
175 done by the `-a` or `--library` options to `configure.sh`:
181 When building the library, the executables are not built. For more information,
182 see the [build manual][5].
184 The library API can be found in [`manuals/bcl.3.md`][26] or `man bcl` once the
185 library is installed.
187 #### Package and Distro Maintainers
189 This section is for package and distro maintainers.
191 ##### Out-of-Source Builds
193 Out-of-source builds are supported; just call `configure.sh` from the directory
194 where the actual build will happen.
196 For example, if the source is in `bc`, the build should happen in `build`, then
197 call `configure.sh` and `make` like so:
204 ***WARNING***: The path to `configure.sh` from the build directory must not have
205 spaces because `make` does not support target names with spaces.
207 ##### Recommended Compiler
209 When I ran benchmarks with my `bc` compiled under `clang`, it performed much
210 better than when compiled under `gcc`. I recommend compiling this `bc` with
213 I also recommend building this `bc` with C11 if you can because `bc` will detect
214 a C11 compiler and add `_Noreturn` to any relevant function(s).
216 ##### Recommended Optimizations
218 I wrote this `bc` with Separation of Concerns, which means that there are many
219 small functions that could be inlined. However, they are often called across
220 file boundaries, and the default optimizer can only look at the current file,
221 which means that they are not inlined.
223 Thus, because of the way this `bc` is built, it will automatically be slower
224 than other `bc` implementations when running scripts with no math. (My `bc`'s
225 math is *much* faster, so any non-trivial script should run faster in my `bc`.)
227 Some, or all, of the difference can be made up with the right optimizations. The
228 optimizations I recommend are:
231 2. `-flto` (link-time optimization)
235 Link-time optimization, in particular, speeds up the `bc` a lot. This is because
236 when link-time optimization is turned on, the optimizer can look across files
237 and inline *much* more heavily.
239 However, I recommend ***NOT*** using `-march=native`. Doing so will reduce this
240 `bc`'s performance, at least when building with link-time optimization. See the
241 [benchmarks][19] for more details.
243 ##### Stripping Binaries
245 By default, non-debug binaries are stripped, but stripping can be disabled with
246 the `-T` option to `configure.sh`.
248 ##### Using This `bc` as an Alternative
250 If this `bc` is packaged as an alternative to an already existing `bc` package,
251 it is possible to rename it in the build to prevent name collision. To prepend
252 to the name, just run the following:
255 EXECPREFIX=<some_prefix> ./configure.sh
258 To append to the name, just run the following:
261 EXECSUFFIX=<some_suffix> ./configure.sh
264 If a package maintainer wishes to add both a prefix and a suffix, that is
267 **Note**: The suggested name (and package name) when `bc` is not available is
270 ##### Karatsuba Number
272 Package and distro maintainers have one tool at their disposal to build this
273 `bc` in the optimal configuration: `scripts/karatsuba.py`.
275 This script is not a compile-time or runtime prerequisite; it is for package and
276 distro maintainers to run once when a package is being created. It finds the
277 optimal Karatsuba number (see the [algorithms manual][7] for more information)
278 for the machine that it is running on.
280 The easiest way to run this script is with `make karatsuba`.
282 If desired, maintainers can also skip running this script because there is a
283 sane default for the Karatsuba number.
289 It is well-tested, fuzzed, and fully standards-compliant (though not certified)
290 with POSIX `bc`. The math has been tested with 40+ million random problems, so
291 it is as correct as I can make it.
293 This `bc` can be used as a drop-in replacement for any existing `bc`. This `bc`
294 is also compatible with MinGW toolchains.
296 In addition, this `bc` is considered complete; i.e., there will be no more
297 releases with additional features. However, it *is* actively maintained, so if
298 any bugs are found, they will be fixed in new releases. Also, additional
299 translations will also be added as they are provided.
303 If I (Gavin D. Howard) get [hit by a bus][27] and future programmers need to
304 handle work themselves, the best place to start is the [Development manual][28].
308 I have developed (using other people's code to start) [`vim` syntax files][17]
309 for this `bc` and `dc`, including the extensions.
313 I have gathered some excellent [`bc` and `dc` libraries][18]. These libraries
314 may prove useful to any serious users.
316 ## Comparison to GNU `bc`
318 This `bc` compares favorably to GNU `bc`.
320 * This `bc` builds natively on Windows.
321 * It has more extensions, which make this `bc` more useful for scripting.
322 * This `bc` is a bit more POSIX compliant.
323 * It has a much less buggy parser. The GNU `bc` will give parse errors for what
324 is actually valid `bc` code, or should be. For example, putting an `else` on
325 a new line after a brace can cause GNU `bc` to give a parse error.
326 * This `bc` has fewer crashes.
327 * GNU `bc` calculates the wrong number of significant digits for `length(x)`.
328 * GNU `bc` will sometimes print numbers incorrectly. For example, when running
329 it on the file `tests/bc/power.txt` in this repo, GNU `bc` gets all the right
330 answers, but it fails to wrap the numbers at the proper place when outputting
332 * This `bc` is faster. (See [Performance](#performance).)
336 Because this `bc` packs more than `1` decimal digit per hardware integer, this
337 `bc` is faster than GNU `bc` and can be *much* faster. Full benchmarks can be
338 found at [manuals/benchmarks.md][19].
340 There is one instance where this `bc` is slower: if scripts are light on math.
341 This is because this `bc`'s intepreter is slightly slower than GNU `bc`, but
342 that is because it is more robust. See the [benchmarks][19].
346 To see what algorithms this `bc` uses, see the [algorithms manual][7].
350 Currently, there is no locale support on Windows.
352 Additionally, this `bc` only has support for English (and US English), French,
353 German, Portuguese, Dutch, Polish, Russian, Japanese, and Chinese locales.
354 Patches are welcome for translations; use the existing `*.msg` files in
355 `locales/` as a starting point.
357 In addition, patches for improvements are welcome; the last two messages in
358 Portuguese were made with Google Translate, and the Dutch, Polish, Russian,
359 Japanese, and Chinese locales were all generated with [DeepL][22].
361 The message files provided assume that locales apply to all regions where a
362 language is used, but this might not be true for, e.g., `fr_CA` and `fr_CH`.
363 Any corrections or a confirmation that the current texts are acceptable for
364 those regions would be appreciated, too.
368 Other projects based on this bc are:
370 * [busybox `bc`][8]. The busybox maintainers have made their own changes, so any
371 bugs in the busybox `bc` should be reported to them.
373 * [toybox `bc`][9]. The maintainer has also made his own changes, so bugs in the
374 toybox `bc` should be reported there.
376 * [FreeBSD `bc`][23]. While the `bc` in FreeBSD is kept up-to-date, it is better
377 to [report bugs there][24], as well as [submit patches][25], and the
378 maintainers of the package will contact me if necessary.
382 This `bc` is written in pure ISO C99, using POSIX 2008 APIs with custom Windows
387 This `bc` uses the commit message guidelines laid out in [this blog post][10].
389 ## Semantic Versioning
391 This `bc` uses [semantic versioning][11].
395 Items labeled with `(maintainer use only)` are not included in release source
400 .gitignore The git ignore file (maintainer use only).
401 .gitattributes The git attributes file (maintainer use only).
402 bcl.pc.in A template pkg-config file for bcl.
403 configure A symlink to configure.sh to make packaging easier.
404 configure.sh The configure script.
405 LICENSE.md A Markdown form of the BSD 2-clause License.
406 Makefile.in The Makefile template.
407 NEWS.md The changelog.
408 NOTICE.md List of contributors and copyright owners.
412 benchmarks A folder of benchmarks for various aspects of bc performance.
413 gen The bc math library, help texts, and code to generate C source.
414 include All header files.
415 locales Locale files, in .msg format. Patches welcome for translations.
416 manuals Manuals for both programs.
418 scripts A bunch of shell scripts to help with development and building.
420 vs Files needed for the build on Windows.
422 [1]: https://www.gnu.org/software/bc/
424 [5]: ./manuals/build.md
425 [7]: ./manuals/algorithms.md
426 [8]: https://git.busybox.net/busybox/tree/miscutils/bc.c
427 [9]: https://github.com/landley/toybox/blob/master/toys/pending/bc.c
428 [10]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
429 [11]: http://semver.org/
430 [12]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html
431 [17]: https://git.yzena.com/gavin/vim-bc
432 [18]: https://git.yzena.com/gavin/bc_libs
433 [19]: ./manuals/benchmarks.md
434 [20]: https://git.yzena.com/gavin/bc
435 [21]: https://gavinhoward.com/2020/04/i-am-moving-away-from-github/
436 [22]: https://www.deepl.com/translator
437 [23]: https://cgit.freebsd.org/src/tree/contrib/bc
438 [24]: https://bugs.freebsd.org/
439 [25]: https://reviews.freebsd.org/
440 [26]: ./manuals/bcl.3.md
441 [27]: https://en.wikipedia.org/wiki/Bus_factor
442 [28]: ./manuals/development.md
443 [29]: https://github.com/gavinhoward/bc