| Index: > A B C D E F G H I J K L M N O P Q R S T U V W X Y Z |
|
|||||
| First Prev [ 1 2 ] Next Last |
bc on a Unix command prompt and entering a mathematical expression, such as (1 + 3) * 2, whereupon 8 will be immediately outputted.There are currently two main dialects: the rigorously defined POSIX bc, and its direct descendent, the much expanded GNU bc.
Both forms of bc can be executed as either a mathematical scripting language or as an interactive mathematical shell.
The POSIX standardised bc language is traditionally written as a program in the dc programming language to provide a higher level of access to the features of the dc language without the complexities of dc's terse syntax.
In this form, the bc language contains single letter variable, array and function names and most standard arithmetic operators as well as the familiar control flow constructs, (if(cond)..., while(cond)... and for(init;cond;inc)...) from C. Unlike C, an if clause may not be followed by an else.
Functions are defined using a define keyword and values are returned from them using a return followed by the return value in parentheses. The auto keyword (optional in C) is used to declare a variable as local to a function.
All numbers and variable contents are fixed precision floating-point numbers whose precision (in decimal places) is determined by the global scale variable.
The numeric base of input (in interactive mode), output and program constants may be specified by setting the reserved ibase (input base) and obase (output base) variables.
Output is generated by deliberately not assigning the result of a calculation to a variable.
Comments may be added to bc code by use of the C /* and */ (start and end comment) symbols.
The following POSIX bc operators behave exactly like their C counterparts:
+ - * / += -= *= /= ++ -- < > == != <= >= ( ) [ ] { }
The modulus operators:
% %=... behave exactly like their C counterparts only when the global scale variable is set to 0, i.e. all calculations are integer-only. When scale is greater than 0 the modulus is calculated relative to the smallest positive value greater than zero.
The operators:
^ ^=... resemble the C bitwise exclusive-or operators, but are in fact the bc integer exponentiation operators.
The bitwise, boolean and conditional operators:
& | ^ && || ^^ &= |= ^= &&= ||= ^^= << >> <<= >>= ?:... are not available in POSIX bc.
The sqrt() function for calculating square rootIn mathematics, the square root of a non-negative real number is denoted and represents the non-negative real number whose square (the result of multiplying the number by itself) is. For example, since. This example suggests how square roots can arise whes is POSIX bc's only built-in mathematical function. Others functions are available in an external standard library.
bc's standard library contains functions for calculating sine, cosine, arctangent, natural logarithmThe natural logarithm is the logarithm to the base e where e is approximately equal to 2. no exact fraction can be given, as e is an irrational number just like pi). The natural logarithm is defined for all positive real numbers x and can also be defined, the exponentialThe term exponential may refer to any of several topics in mathematics: Exponential distribution Exponential function Exponential growth, exponential decay Exponential time Matrix exponential Exponential map (in differential geometry) All relate in some f function and the two parameter Bessel functionIn mathematics, Bessel functions first defined by the Swiss mathematician Daniel Bernoulli and named after Friedrich Bessel, are canonical solutions y ''x of Bessel's differential equation: : for an arbitrary real number α (the order . The most comm J.