Casio ClassPad 300 Programming Manual page 87

Sdk programming guide
Hide thumbs Also See for ClassPad 300:
Table of Contents

Advertisement

These functions place a word (unsigned short), short, and a long into an OBCD
respectively. Here is an example using Cal_setn_OBC:
OBCD x;
Cal_setn_OBC(5, &x);
Since this function takes an unsigned short we cannot set the value to a negative number.
We would have to use the Cal_minus_OBC function as follows:
OBCD x;
Cal_setn_OBC(5, &x);
Cal_minus_OBC(&x);
We could also use the Cal_shortto_OBC or Cal_longto_OBC function to set a negative
value:
OBCD x;
OBCD y;
Cal_shortto_OBC(-5, &x);
Cal_longto_OBC(-155, &y);
When dealing with whole numbers, you do not need to worry about exponents as long as
you use these functions to set the values. The functions will set the exponent value
automatically.
As we mentioned in the OBCD Data Structure section, to create a floating-point OBCD
we must change the OBCD's exponent value. To do this, we will explicitly set the
exponent to the appropriate hex value.
Let's walk through setting the exponent for the value 205.5. First use the function
Cal_longto_OBC to set the OBCD to 2055:
OBCD x;
Cal_longto_OBC(2055, &x);
We want to set the exponent to 10^2 so the number becomes 2.055 * 10^2 = 205.5.
Since 205.5 is positive, add the exponent value to 1000: 1000 + 2 = 1002. So the
exponential value is 1002. You can set the exponent with the following code:
x.obcd1.exponential=0x1002;
x now holds the value 205.5. To make the mantissa negative, we would have set the
exponent to 6002 (6000 + 2 = 6002):
x.obcd1.exponential=0x6002;
Here are some more examples of setting exponent values:
OBCD x;
//sets x to the value 5
//sets x to the value 5
//sets x to the value -5
//sets x to the value -5
//sets y to the value -155
// 2.055 * -10^2 = -205.5
87

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents