Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Project516/c-calc/llms.txt

Use this file to discover all available pages before exploring further.

c-calc supports five arithmetic operators: addition (+), subtraction (-), multiplication (*), division (/), and modulo (%). All results are computed in double-precision floating point and printed with four decimal places using the %.4f format specifier. This page documents the behavior of each operator, including edge cases such as division by zero and modulo with floating-point inputs.

Output format

Regardless of operator, every result is displayed as:
Result: <value>.0000
For example, 7 / 2 yields Result: 3.5000, and 6 + 0 yields Result: 6.0000.

Operator reference

Returns the sum of the two operands as a double.
./c-calc 3 + 4
Result: 7.0000
double add(double a, double b) {
    return a + b;
}
Returns the difference of the two operands as a double. The result is negative when the second operand is larger than the first.
./c-calc 10 - 3
Result: 7.0000
double subtract(double a, double b) {
    return a - b;
}
Returns the product of the two operands as a double.
./c-calc 6 '*' 7
Result: 42.0000
In most shells, * must be quoted to prevent glob expansion. Use single quotes ('*'), double quotes ("*"), or a backslash escape (\*).
double multiply(double a, double b) {
    return a * b;
}
Returns the quotient of the two operands as a double.
./c-calc 22 / 7
Result: 3.1429
When the divisor is 0, c-calc prints Divide by 0 error (without a trailing newline) and returns 0 instead of crashing or exiting with an error code.
./c-calc 9 / 0
Divide by 0 errorResult: 0.0000
double divide(double a, double b) {
    if (b == 0) {
        printf("Divide by 0 error");
        return 0;
    }
    return a / b;
}
Returns the integer remainder after dividing the first operand by the second.
./c-calc 7 % 3
Result: 1.0000
Both operands are truncated to int before the modulo operation is applied, regardless of whether they were supplied as decimals. For example, 7.9 % 3.9 is computed as 7 % 3, which equals 1.
case '%':
    int whole_first = first;
    int whole_second = second;
    result = whole_first % whole_second;
    break;
The truncation follows C’s behavior for converting double to int, which discards the fractional part (truncation toward zero).

Unknown operator

If the operator character passed to calculate() does not match any of the five cases, the switch statement falls through to its default branch:
Unknown operator
The function returns -1, so the printed result is:
Result: -1.0000
This applies in both interactive and non-interactive mode.

Build docs developers (and LLMs) love