void Cal_setwmax_OBC (OBCD *x); //Place the max possible value in x
void Cal_setwmin_OBC (OBCD *x); //Place the min possible value in x
void Cal_setpi_OBC (OBCD *x); // Place pi in x
void Cal_set2pi_OBC (OBCD *x); // Place 2*pi in x
void Cal_setpih_OBC (OBCD *x); // Place pi/2 in x
void Cal_setpiq_OBC (OBCD *x); // Place pi/4 in x
void Cal_sete_OBC (OBCD *x); // Place e in x
void Cal_setln10_OBC (OBCD *x); // Place ln(10) in x
Performing Operations on OBCDs
The next step in using OBCDs is performing calculations with them. Here are a few
common operations that take two operands:
word Cal_adds_OBC (OBCD *x, OBCD *y); // Adds x to y (x+y).
word Cal_subs_OBC (OBCD *x, OBCD *y); // Subtracts x from y (x-y).
word Cal_muls_OBC (OBCD *x, OBCD *y); // Multiplies x and y (x*y).
word Cal_divs_OBC (OBCD *x, OBCD *y); // Divides y into x (x/y).
word Cal_sqrts_OBC (OBCD *x); //Takes the square root of x.
word Cal_add_OBC (OBCD *x, OBCD *y); // Adds x to y (x+y).
word Cal_sub_OBC (OBCD *x, OBCD *y); // Subtracts x from y (x-y).
word Cal_mul_OBC (OBCD *x, OBCD *y); // Multiplies x and y (x*y).
word Cal_div_OBC (OBCD *x, OBCD *y); // Divides y into x (x/y).
word Cal_pow_OBC (OBCD *x, OBCD *y); // Raises x to y (x^y).
Notice that these functions return an error code, not the result of the operation. The result
of the operation is stored in the first parameter, x. For example:
word error;
OBCD x, y;
Cal_setn_OBC(10, &x); // set x = 10
Cal_setn_OBC(15, &y); // set y = 15
error = Cal_adds_OBC(&x, &y); // set x = x + y
if(error != IM_CAL_NORM)
{
// An Error Occurred!
}
When this code finishes, x has the value of 25. If the return value from the addition
function is anything other than IM_CAL_NORM, then an error occurred. You can view
all the return values in the ClassPad 300 SDK API Reference Guide under Math
Functions->Calculation Error Codes.
There are also several functions that operate on single operands. Some of these include:
word Cal_sqrt_OBC (OBCD *x); // Takes the square root of x
word Cal_log_OBC (OBCD *x); // Takes the log of x (log(x))
word Cal_log10_OBC (OBCD *x); // Takes the log base 10 of x
// (log_10(x))
word Cal_sin_OBC (OBCD *x, word wdrg); // Takes the sin of x
word Cal_cos_OBC (OBCD *x, word wdrg); // Takes the cos of x
word Cal_tan_OBC (OBCD *x, word wdrg) // Takes the tan of x
89