{"id":32136833,"url":"https://github.com/gavinhoward/bc","last_synced_at":"2025-10-21T04:42:11.007Z","repository":{"id":28609403,"uuid":"146616613","full_name":"gavinhoward/bc","owner":"gavinhoward","description":"An implementation of the POSIX bc calculator with GNU extensions and dc. Finished.","archived":false,"fork":false,"pushed_at":"2025-08-16T15:44:12.000Z","size":12438,"stargazers_count":196,"open_issues_count":1,"forks_count":36,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-09-15T14:23:02.950Z","etag":null,"topics":["bc","dc","posix"],"latest_commit_sha":null,"homepage":"","language":"Roff","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gavinhoward.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-08-29T14:59:12.000Z","updated_at":"2025-09-14T22:36:49.000Z","dependencies_parsed_at":"2023-11-25T06:24:06.196Z","dependency_job_id":"2b0ec343-464c-4f0f-b1a1-20798eb8fcd4","html_url":"https://github.com/gavinhoward/bc","commit_stats":{"total_commits":5616,"total_committers":26,"mean_commits":216.0,"dds":"0.18892450142450146","last_synced_commit":"50439ed1f01315495b85d4c39b8867d6ac8e3343"},"previous_names":[],"tags_count":129,"template":false,"template_full_name":null,"purl":"pkg:github/gavinhoward/bc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinhoward%2Fbc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinhoward%2Fbc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinhoward%2Fbc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinhoward%2Fbc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gavinhoward","download_url":"https://codeload.github.com/gavinhoward/bc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavinhoward%2Fbc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280207158,"owners_count":26290614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bc","dc","posix"],"created_at":"2025-10-21T04:42:09.817Z","updated_at":"2025-10-21T04:42:10.998Z","avatar_url":"https://github.com/gavinhoward.png","language":"Roff","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `bc`\n\n***WARNING: This project has moved back to GitHub temporarily; self-hosted Git\nforges are not working for me, so I am trying to replace them.***\n\nThis is an implementation of the [POSIX `bc` calculator][12] that implements\n[GNU `bc`][1] extensions, as well as the period (`.`) extension for the BSD\nflavor of `bc`.\n\nFor more information, see this `bc`'s full manual.\n\nThis `bc` also includes an implementation of `dc` in the same binary, accessible\nvia a symbolic link, which implements all FreeBSD and GNU extensions. (If a\nstandalone `dc` binary is desired, `bc` can be copied and renamed to `dc`.) The\n`!` command is omitted; I believe this poses security concerns and that such\nfunctionality is unnecessary.\n\nFor more information, see the `dc`'s full manual.\n\nThis `bc` also provides `bc`'s math as a library with C bindings, called `bcl`.\n\nFor more information, see the full manual for `bcl`.\n\n## License\n\nThis `bc` is Free and Open Source Software (FOSS). It is offered under the BSD\n2-clause License. Full license text may be found in the [`LICENSE.md`][4] file.\n\n## Prerequisites\n\nThis `bc` only requires either:\n\n1.\tWindows 10 or later, or\n2.\tA C99-compatible compiler and a (mostly) POSIX 2008-compatible system with\n\tthe XSI (X/Open System Interfaces) option group.\n\nSince POSIX 2008 with XSI requires the existence of a C99 compiler as `c99`, any\nPOSIX and XSI-compatible system will have everything needed.\n\nPOSIX-compatible systems that are known to work:\n\n* Linux\n* FreeBSD\n* OpenBSD\n* NetBSD\n* macOS\n* Solaris* (as long as the Solaris version supports POSIX 2008)\n* AIX\n* HP-UX* (except for history)\n\nIn addition, there is compatibility code to make this `bc` work on Windows.\n\nPlease submit bug reports if this `bc` does not build out of the box on any\nsystem.\n\n## Build\n\nThis `bc` should build unmodified on any POSIX-compliant system or on Windows\nstarting with Windows 10 (though earlier versions may work).\n\nFor more complex build requirements than the ones below, see the [build\nmanual][5].\n\n### Windows\n\nThere is no guarantee that this `bc` will work on any version of Windows earlier\nthan Windows 10 (I cannot test on earlier versions), but it is guaranteed to\nwork on Windows 10 at least.\n\nAlso, if building with MSBuild, the MSBuild bundled with Visual Studio is\nrequired.\n\n**Note**: Unlike the POSIX-compatible platforms, only one build configuration is\nsupported on Windows: extra math and history enabled, NLS (locale support)\ndisabled, with both calculators built.\n\n#### `bc`\n\nTo build `bc`, you can open the `vs/bc.sln` file in Visual Studio, select the\nconfiguration, and build.\n\nYou can also build using MSBuild with the following from the root directory:\n\n```\nmsbuild -property:Configuration=\u003cconfig\u003e vs/bc.sln\n```\n\nwhere `\u003cconfig\u003e` is either one of `Debug` or `Release`.\n\nOn Windows, the calculators are built as `vs/bin/\u003cplatform\u003e/\u003cconfig\u003e/bc.exe` and\n`vs/bin/\u003cPlatform\u003e/\u003cConfig\u003e/dc.exe`, where `\u003cplatform\u003e` can be either `Win32` or\n`x64`, and `\u003cconfig\u003e` can be `Debug` or `Release`.\n\n**Note**: On Windows, `dc.exe` is just copied from `bc.exe`; it is not linked.\nPatches are welcome for a way to do that.\n\n#### `bcl` (Library)\n\nTo build the library, you can open the `vs/bcl.sln` file in Visual Studio,\nselect the configuration, and build.\n\nYou can also build using MSBuild with the following from the root directory:\n\n```\nmsbuild -property:Configuration=\u003cconfig\u003e vs/bcl.sln\n```\n\nwhere `\u003cconfig\u003e` is either one of `Debug`, `ReleaseMD`, or `ReleaseMT`.\n\nOn Windows, the library is built as `vs/lib/\u003cplatform\u003e/\u003cconfig\u003e/bcl.lib`, where\n`\u003cplatform\u003e` can be either `Win32` or `x64`, and `\u003cconfig\u003e` can be `Debug`,\n`ReleaseMD`, or `ReleaseMT`.\n\n### POSIX-Compatible Systems\n\nOn POSIX-compatible systems, `bc` is built as `bin/bc` and `dc` is built as\n`bin/dc` by default.\n\n#### Default\n\nFor the default build with optimization, use the following commands in the root\ndirectory:\n\n```\n./configure.sh -O3\nmake\n```\n\n#### One Calculator\n\nTo only build `bc`, use the following commands:\n\n```\n./configure.sh --disable-dc\nmake\n```\n\nTo only build `dc`, use the following commands:\n\n```\n./configure.sh --disable-bc\nmake\n```\n\n#### Debug\n\nFor debug builds, use the following commands in the root directory:\n\n```\n./configure.sh -g\nmake\n```\n\n#### Install\n\nTo install, use the following command:\n\n```\nmake install\n```\n\nBy default, `bc` and `dc` will be installed in `/usr/local`. For installing in\nother locations, use the `PREFIX` environment variable when running\n`configure.sh` or pass the `--prefix=\u003cprefix\u003e` option to `configure.sh`. See the\n[build manual][5], or run `./configure.sh --help`, for more details.\n\n#### Library\n\nTo build the math library, pass the `-a` or `--library` options to\n`configure.sh`:\n\n```\n./configure.sh -a\n```\n\nWhen building the library, the executables are not built. For more information,\nsee the [build manual][5].\n\nThe library API can be found in [`manuals/bcl.3.md`][26] or `man bcl` once the\nlibrary is installed.\n\n#### Package and Distro Maintainers\n\nThis section is for package and distro maintainers.\n\n##### Out-of-Source Builds\n\nOut-of-source builds are supported; just call `configure.sh` from the directory\nwhere the actual build will happen.\n\nFor example, if the source is in `bc`, the build should happen in `build`, then\ncall `configure.sh` and `make` like so:\n\n```\n../bc/configure.sh\nmake\n```\n\n***WARNING***: The path to `configure.sh` from the build directory must not have\nspaces because `make` does not support target names with spaces.\n\n##### Recommended Compiler\n\nWhen I ran benchmarks with my `bc` compiled under `clang`, it performed much\nbetter than when compiled under `gcc`. I recommend compiling this `bc` with\n`clang`.\n\nI also recommend building this `bc` with C11 if you can because `bc` will detect\na C11 compiler and add `_Noreturn` to any relevant function(s).\n\n##### Recommended Optimizations\n\nI wrote this `bc` with Separation of Concerns, which means that there are many\nsmall functions that could be inlined. However, they are often called across\nfile boundaries, and the default optimizer can only look at the current file,\nwhich means that they are not inlined.\n\nThus, because of the way this `bc` is built, it will automatically be slower\nthan other `bc` implementations when running scripts with no math. (My `bc`'s\nmath is *much* faster, so any non-trivial script should run faster in my `bc`.)\n\nSome, or all, of the difference can be made up with the right optimizations. The\noptimizations I recommend are:\n\n1.\t`-O3`\n2.\t`-flto` (link-time optimization)\n\nin that order.\n\nLink-time optimization, in particular, speeds up the `bc` a lot. This is because\nwhen link-time optimization is turned on, the optimizer can look across files\nand inline *much* more heavily.\n\nHowever, I recommend ***NOT*** using `-march=native`. Doing so will reduce this\n`bc`'s performance, at least when building with link-time optimization. See the\n[benchmarks][19] for more details.\n\n##### Stripping Binaries\n\nBy default, non-debug binaries are stripped, but stripping can be disabled with\nthe `-T` option to `configure.sh`.\n\n##### Using This `bc` as an Alternative\n\nIf this `bc` is packaged as an alternative to an already existing `bc` package,\nit is possible to rename it in the build to prevent name collision. To prepend\nto the name, just run the following:\n\n```\nEXECPREFIX=\u003csome_prefix\u003e ./configure.sh\n```\n\nTo append to the name, just run the following:\n\n```\nEXECSUFFIX=\u003csome_suffix\u003e ./configure.sh\n```\n\nIf a package maintainer wishes to add both a prefix and a suffix, that is\nallowed.\n\n**Note**: The suggested name (and package name) when `bc` is not available is\n`bc-gh`.\n\n##### Karatsuba Number\n\nPackage and distro maintainers have one tool at their disposal to build this\n`bc` in the optimal configuration: `scripts/karatsuba.py`.\n\nThis script is not a compile-time or runtime prerequisite; it is for package and\ndistro maintainers to run once when a package is being created. It finds the\noptimal Karatsuba number (see the [algorithms manual][7] for more information)\nfor the machine that it is running on.\n\nThe easiest way to run this script is with `make karatsuba`.\n\nIf desired, maintainers can also skip running this script because there is a\nsane default for the Karatsuba number.\n\n##### `timeconst.bc`\n\nThe test suite will print a warning in normal usage. The warning is about a\nmissing `timeconst.bc`. This file [comes from][37] the [Linux kernel][38], which\nhas an incompatible license. The warning can be ignored.\n\n## Status\n\nThis `bc` is robust.\n\nIt is well-tested, fuzzed, and fully standards-compliant (though not certified)\nwith POSIX `bc`. The math has been tested with 40+ million random problems, so\nit is as correct as I can make it.\n\nThis `bc` can be used as a drop-in replacement for any existing `bc`. This `bc`\nis also compatible with MinGW toolchains.\n\nIn addition, this `bc` is considered complete; i.e., there will be no more\nreleases with additional features. However, it *is* actively maintained, so if\nany bugs are found, they will be fixed in new releases. Also, additional\ntranslations will also be added as they are provided.\n\n### Development\n\nIf I (Gavin D. Howard) get [hit by a bus][27] and future programmers need to\nhandle work themselves, the best place to start is the [Development manual][28].\n\n## Vim Syntax\n\nI have developed (using other people's code to start) [`vim` syntax files][17]\nfor this `bc` and `dc`, including the extensions.\n\n## `bc` Libs\n\nI have gathered some excellent [`bc` and `dc` libraries][18]. These libraries\nmay prove useful to any serious users.\n\n## Comparison to GNU `bc`\n\nThis `bc` compares favorably to GNU `bc`.\n\n* This `bc` builds natively on Windows.\n* It has more extensions, which make this `bc` more useful for scripting. (See\n  [Extensions](#extensions).)\n* This `bc` is a bit more POSIX compliant.\n* It has a much less buggy parser. The GNU `bc` will give parse errors for what\n  is actually valid `bc` code, or should be. For example, putting an `else` on\n  a new line after a brace can cause GNU `bc` to give a parse error.\n* This `bc` has fewer crashes.\n* GNU `bc` calculates the wrong number of significant digits for `length(x)`.\n* GNU `bc` will sometimes print numbers incorrectly. For example, when running\n  it on the file `tests/bc/power.txt` in this repo, GNU `bc` gets all the right\n  answers, but it fails to wrap the numbers at the proper place when outputting\n  to a file.\n* This `bc` is faster. (See [Performance](#performance).)\n\n### Performance\n\nBecause this `bc` packs more than `1` decimal digit per hardware integer, this\n`bc` is faster than GNU `bc` and can be *much* faster. Full benchmarks can be\nfound at [manuals/benchmarks.md][19].\n\nThere is one instance where this `bc` is slower: if scripts are light on math.\nThis is because this `bc`'s intepreter is slightly slower than GNU `bc`, but\nthat is because it is more robust. See the [benchmarks][19].\n\n### Extensions\n\nBelow is a non-comprehensive list of extensions that this `bc` and `dc` have\nthat all others do not.\n\n* **The `!` operator has higher precedence than the `!` operator in other `bc`\n  implementations.**\n* An extended math library. (See [here][30] for more information.)\n* A command-line prompt.\n* Turning on and off digit clamping. (Digit clamping is about how to treat\n  \"invalid\" digits for a particular base. GNU `bc` uses it, and the BSD `bc`\n  does not. Mine does both.)\n* A pseudo-random number generator. This includes the ability to set the seed\n  and get reproducible streams of random numbers.\n* The ability to use stacks for the globals `scale`, `ibase`, and `obase`\n  instead of needing to restore them in *every* function.\n* The ability to *not* use non-standard keywords. For example, `abs` is a\n  keyword (a built-in function), but if some script actually defines a function\n  called that, it's possible to tell my `bc` to not treat it as a keyword, which\n  will make the script parses correctly.\n* The ability to turn on and off printing leading zeroes on numbers greater than\n  `-1` and less than `1`.\n* Outputting in scientific and engineering notation.\n* Accepting input in scientific and engineering notation.\n* Passing strings and arrays to the `length()` built-in function. (In `dc`, the\n  `Y` command will do this for arrays, and the `Z` command will do this for both\n  numbers and strings.)\n* The `abs()` built-in function. (This is the `b` command in `dc`.)\n* The `is_number()` and `is_string()` built-in functions. (These tell whether a\n  variable is holding a string or a number, for runtime type checking. The\n  commands are `u` and `t` in `dc`.)\n* For `bc` only, the `divmod()` built-in function for computing a quotient and\n  remainder at the same time.\n* For `bc` only, the `asciify()` built-in function for converting an array to a\n  string.\n* The `$` truncation operator. (It's the same in `bc` and `dc`.)\n* The `@` \"set scale\" operator. (It's the same in `bc` and `dc`.)\n* The decimal shift operators. (`\u003c\u003c` and `\u003e\u003e` in `bc`, `H` and `h` in `dc`.)\n* Built-in functions or commands to get the max of `scale`, `ibase`, and\n  `obase`.\n* The ability to put strings into variables in `bc`. (This always existed in\n  `dc`.)\n* The `'` command in `dc` for the depth of the execution stack.\n* The `y` command in `dc` for the depth of register stacks.\n* Built-in functions or commands to get the value of certain environment\n  variables that might affect execution.\n* The `stream` keyword to do the same thing as the `P` command in `dc`.\n* Defined order of evaluation.\n* Defined exit statuses.\n* All environment variables other than `POSIXLY_CORRECT`, `BC_ENV_ARGS`, and\n  `BC_LINE_LENGTH`.\n* The ability for users to define their own defaults for various options during\n  build. (See [here][31] for more information.)\n\n## Algorithms\n\nTo see what algorithms this `bc` uses, see the [algorithms manual][7].\n\n## Locales\n\nCurrently, there is no locale support on Windows.\n\nAdditionally, this `bc` only has support for English (and US English), French,\nGerman, Portuguese, Dutch, Polish, Russian, Japanese, and Chinese locales.\nPatches are welcome for translations; use the existing `*.msg` files in\n`locales/` as a starting point.\n\nIn addition, patches for improvements are welcome; the last two messages in\nPortuguese were made with Google Translate, and the Dutch, Polish, Russian,\nJapanese, and Chinese locales were all generated with [DeepL][22].\n\nThe message files provided assume that locales apply to all regions where a\nlanguage is used, but this might not be true for, e.g., `fr_CA` and `fr_CH`.\nAny corrections or a confirmation that the current texts are acceptable for\nthose regions would be appreciated, too.\n\n## Other Projects\n\nOther projects based on this bc are:\n\n* [busybox `bc`][8]. The busybox maintainers have made their own changes, so any\n  bugs in the busybox `bc` should be reported to them.\n* [toybox `bc`][9]. The maintainer has also made his own changes, so bugs in the\n  toybox `bc` should be reported there.\n* [FreeBSD `bc`][23]. While the `bc` in FreeBSD is kept up-to-date, it is better\n  to [report bugs there][24], as well as [submit patches][25], and the\n  maintainers of the package will contact me if necessary.\n* [macOS `bc`][35]. Any bugs in that `bc` should be reported to me, but do\n  expect bugs because the version is old.\n* [Android Open Source `bc`][32]. Any bugs in that `bc` can be reported here.\n* [A Fedora package][36]. If this package does not have any patches, you can\n  report bugs to me.\n\nThis is a non-comprehensive list of Linux distros that use this `bc` as the\nsystem `bc`:\n\n* [Gentoo][33]; it is a first-class alternative to GNU `bc`, but not exclusive.\n* [Linux from Scratch][34].\n\nOther Linux distros package it as a second-class alternative, usually as `bc-gh`\nor `howard-bc`.\n\n## Language\n\nThis `bc` is written in pure ISO C99, using POSIX 2008 APIs with custom Windows\ncompatibility code.\n\n## Commit Messages\n\nThis `bc` uses the commit message guidelines laid out in [this blog post][10].\n\n## Semantic Versioning\n\nThis `bc` uses [semantic versioning][11].\n\n## AI-Free\n\nThis repository is 100% AI-Free code.\n\n## Contents\n\nItems labeled with `(maintainer use only)` are not included in release source\ntarballs.\n\nFiles:\n\n\t.gitignore           The git ignore file (maintainer use only).\n\t.gitattributes       The git attributes file (maintainer use only).\n\tbcl.pc.in            A template pkg-config file for bcl.\n\tbuild.gaml           The GAML file with options for building under Rig.\n\tbuild.pkg.rig        The Rig build package file.\n\tbuild.rig            The Rig build script.\n\tconfigure            A symlink to configure.sh to make packaging easier.\n\tconfigure.sh         The configure script.\n\tLICENSE.md           A Markdown form of the BSD 2-clause License.\n\tMakefile.in          The Makefile template.\n\tNEWS.md              The changelog.\n\tNOTICE.md            List of contributors and copyright owners.\n\tVERSION.txt          A file containing the version.\n\nFolders:\n\n\tbenchmarks  A folder of benchmarks for various aspects of bc performance.\n\tgen         The bc math library, help texts, and code to generate C source.\n\tinclude     All header files.\n\tlocales     Locale files, in .msg format. Patches welcome for translations.\n\tmanuals     Manuals for both programs.\n\tsrc         All source code.\n\tscripts     A bunch of shell scripts to help with development and building.\n\ttests       All tests.\n\tvs          Files needed for the build on Windows.\n\n[1]: https://www.gnu.org/software/bc/\n[4]: ./LICENSE.md\n[5]: ./manuals/build.md\n[7]: ./manuals/algorithms.md\n[8]: https://git.busybox.net/busybox/tree/miscutils/bc.c\n[9]: https://github.com/landley/toybox/blob/master/toys/pending/bc.c\n[10]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html\n[11]: http://semver.org/\n[12]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html\n[17]: https://git.gavinhoward.com/gavin/vim-bc\n[18]: https://git.gavinhoward.com/gavin/bc_libs\n[19]: ./manuals/benchmarks.md\n[22]: https://www.deepl.com/translator\n[23]: https://cgit.freebsd.org/src/tree/contrib/bc\n[24]: https://bugs.freebsd.org/\n[25]: https://reviews.freebsd.org/\n[26]: ./manuals/bcl.3.md\n[27]: https://en.wikipedia.org/wiki/Bus_factor\n[28]: ./manuals/development.md\n[29]: https://github.com/gavinhoward/bc\n[30]: ./manuals/bc/A.1.md#extended-library\n[31]: ./manuals/build.md#settings\n[32]: https://android.googlesource.com/platform/external/bc/\n[33]: https://github.com/gentoo/gentoo/blob/master/app-alternatives/bc/bc-0.ebuild#L8\n[34]: https://www.linuxfromscratch.org/lfs/view/stable/chapter08/bc.html\n[35]: https://github.com/apple-oss-distributions/bc/tree/main/bc\n[36]: https://copr.fedorainfracloud.org/coprs/tkbcopr/bc-gh/\n[37]: https://github.com/torvalds/linux/blob/master/kernel/time/timeconst.bc\n[38]: https://github.com/torvalds/linux\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinhoward%2Fbc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgavinhoward%2Fbc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavinhoward%2Fbc/lists"}