The Power of BC
Bench Calculator (bc), the Language
Bench calculator also referred to as a basic calculator is a programming language that supports precise capricious numbers and values. While separate from dc (desk calculator), bc is based on it and has many noteworthy similarities in coding. With proper syntax, inputting a mathematical expression into a command prompt or console will output a solution(s), and nothing else. In the present-day, it is most prevalent in machines that employ the Unix OS.
To fully understand the capabilities of a basic calculator, one must also learn about both desk calculators and the widely known programming language, C. dc, an incredibly old programming language that is still relevant today on Unix, was released even before the release of C. It is described as a programming language with many useful features, but rough syntax which makes it more obsolete today. The desk calculator’s sole purpose was to solve algebraic equations and basic arithmetic on Unix machines. Bench calculator, however, was an evolution of dc, and solved almost any mathematical equation it was programmed to solve.
Bench calculator, while being inspired by dc, is mostly coded in C. C was a programming language originally coded to be exclusively on Unix. However, as years passed, it was standardized for all operating systems. C, while obsolete today due to more modern iterations such as C++ and C#, is still decently efficient and definitely usable. C provides a middle ground between high-level and low-level languages, making it unique to other very popular programming languages such as Python, JS, and Lua. Due to this, the developers of bc were able to utilize the special properties of C to create their calculator masterpiece.
History
The little-known programming language bc was created as a successor to the earlier calculator language, dc. It was developed by the same programmers who made dc: Robert Morris and Lorinda Cherry. In the past, utilizing this language was always quite inconvenient for the users, but after several refinements, it has three primary implementations which allow it to be useful to programmers. Today, there are two noteworthy forms of basic calculators, which are POSIX bc and the far more flexible GNU bc.
Platforms
Bench calculator made its first appearance in Unix, but it is a cross-platform language that is available on many platforms. GNU bc, being far more inclusive, supports many platforms than POSIX bc, such as Microsoft Windows, macOS, and Linux. Contrary to its POSIX predecessor, it has gained large amounts of support for various platforms. Overall, GNU bc is not the most accessible language, but it is still very versatile and can still be downloaded on almost every mainstream operating system that is used in modern-day computers and is even backward compatible with POSIX.
As opposed to GNU, POSIX bc sees far less use not only because of its lack of optimization and enhancements, but also because of its failure to be available on widely used operating systems. Being derived from desk calculator, it is exclusively available to Unix, and Unix-like operating systems such as an OS created with an AT&T codebase.
One other obscure platform that bc is used on is Plan 9. Plan 9, developed at Bell Labs, is built from the same theories and ideas that Unix was but is not based on the same code or Unix-like. While Plan 9 is considered an obsolete OS that is only used by curious software engineers and various hobbyists, it has its own version of a basic calculator which is worth mentioning. However, it is very similar to POSIX bc, and its support is unique to only Plan 9.
Pros and Cons
GNU bc allows for programmers to experiment with precise arbitrary numbers in many different forms of arithmetic. While many other, more widely used programming languages such as Java, and Python, long chunks of complex code are needed to access this kind of math. This can easily lead to the programmer receiving errors and false solutions which could lead to even more problems for them later. Basic calculator, being a programming language made for the sole purpose of solving everything from basic mathematics to complicated formulas with random, odd numbers, can do this much more easily. In other words, GNU bc provides convenience to the programmer and is a work-around to learning unnecessary, convoluted code which could be a huge waste of time.
Despite its many pros, GNU bc is definitely a very unpopular language. It is relatively unknown, and for an unfamiliar programmer, it can be a hassle to learn it over much more prominent languages such as C++, C#, JavaScript, Python, etc. On top of this, its uses are very limited, and usually can only be used for arithmetic. Bench calculator is also inspired by C, which is seeing less use as the years go by. In computer science, C is rapidly being replaced by C++, which is also slowly being taken over by the rise of a new language: C#. Being several generations out of date, even the optimized and advanced GNU bc is becoming outdated as time goes on.
POSIX bc brings fewer benefits and more downsides than GNU bc, making it almost entirely useless unless you are heavily working with Unix or a Unix-like OS. This dialect of basic calculator can help you learn more about Unix-exclusive coding languages, which are quite rare. However, this one benefit is also its downfall. POSIX bc, being only available on Unix makes it unusable for even a more experienced computer science major. It also lacks many of the amazing enhancements and upgrades that are present in the GNU version of this language. Altogether, the POSIX dialect has far too many cons, and GNU bc is superior in almost every way.
What does bc code look like?
bc, having nearly identical syntax to C, has many of the same expressions that are used in C. For example, just like many high-level languages, the bench calculator also makes heavy use of variables, strings, print statements (these are unavailable in POSIX bc, but can be used in all other dialects), if statements, while loops, and for loops. It also features dozens of expressions for solving precise arithmetic. Being a calculator language, it also has a specific function separate from C which allows it to solve common math expressions such as s(x) and c(x), representing sine and cosine. For specifically POSIX bc has one single built-in function outside of its normal external library, which is sqrt(). This, as the syntax implies, finds the square root of a given expression.
If statements are used very commonly in many different settings. In bc, they aren’t very much different at all. An example of an if statement in bc would probably look something like this:
if x == s(x)
return(x * y)
This is very simple if statement which will return the expression x times y to the output if the condition that x equals the sine of x is met. Very basic if statements such as these are commonly used in bc programming to set conditions for code that would otherwise return way too many outputs or just not work at all.
In many programming languages, loops are used for various purposes. In a basic calculator, for loops, and while loops are both utilized to make certain arithmetic equations possible. This would be an example of a while loop in bc:
while ((x * y) > (y * z)) {
print(x)
x = x — 2
}
This very simple while loop will first check if x times y is greater than y times z. Then, it will print the value of x to the output (since POSIX bc doesn’t support print statements, this would result in an error, but this would function properly in GNU bc and Plan 9). Afterward, the code would subtract two from the variable x, and then the entire code would loop again until x times y was less than y times z.
The other incredibly common loops are for loops. In POSIX bc, for loops must follow a very specific format, while GNU bc is a lot less strict in its syntax. For POSIX bc, every for loop must follow this format:
for statement:
expression 1;
while (expression 2) {
statement;
expression 3;
}
For loops in GNU, bc don’t require a second expression, since bc will automatically use expression 1 as a substitute for expression 2. Besides this, these loops serve a very similar purpose to while loops but are more versatile. If you are experienced in coding with C, then picking up bc will prove to be incredibly easy. The syntax for bc, as seen here, is very similar to C, and besides a few exclusive built-in features, almost anything that works in C will work in GNU bc.
Industry Trends
Over the years, the overall usage of bc has significantly declined over the years. The userbase was not very large, to begin with, but it has almost completely disappeared today. POSIX bc is rarely ever used today due to how unoptimized it is. As mentioned before, it is missing many features included in newer iterations of the bench calculator. However, even GNU bc is rarely seen used today, despite its support for Windows, macOS, and other popular operating systems. This could mainly be attributed to two large factors. The first would be that C is now an outdated programming language, and has had several successors. bc, unfortunately, has not had many updates or evolutions, making it be a few generations behind modern high-level languages such as C#. The other reason would be that Unix has lost much of its popularity over the years. Bench calculator, and its predecessor, desk calculator, both originated on Unix and were only ever widely known on that platform. Because of this, bc has suffered a lot, and sadly may someday cease to exist.
Takeaway on the BC Calculator
BC and all of its forms are not the most useful coding language out there. However, it has very specific uses and excels at doing its job in the correct circumstances. If bench calculator were to receive upgrades and enhancements, it could definitely be implemented into a newer programming language such as C#. This would eliminate the issue of how situational it is, and its obscurity. Programmers today should definitely look into it, since it is able to outperform many other arbitrary precision languages.