> next up previous contents index
: Loops : Variable values : Access and affectation   目次   索引

Type conversion

In this section we describe the ProBT variables type conversion rules in assignments, expressions and passing of arguments. Remember that all the data types defined by the user are internally represented either by a plInteger or a plFloat. Consequently, the type conversion process in and statement containing ProBT variables depends on the internal types of the involved variables.

When assigning a value $v$ to a ProBT variable $V$ the first is converted to the type of the second. For example, consider the following lines:

  wine[year] = 1987.80;
  wine[quality] = 3.56;
  wine[price] = 102.12345678901234567890;

  
  cout<<"year = "<<wine[year]<<"\n";
  cout<<"quality = "<<wine[quality]<<"\n";

  cout.precision(20);
  cout<<"price = "<<wine[price]<<"\n";

The output for year and quality are

  year = 1987
  quality = 3

the output for price depends on the internal definition of plFloat. The plFloat type can be a float a double or long double depending on the ProBT version you have. For instance, the output we get in our PC computer are the following:

price = 102.12345678901234568

for plFloat $\equiv$ long double

price = 102.12345678901235146

for plFloat $\equiv$ double and,

price = 102.1234588623046875

for plFloat $\equiv$ float. You can find more information about floating-point types in the float.h or cfloat file of your system, plFloat, is defined in plMath.h. Do not change any information on these files otherwise you will have compatibility problems between the library and ``.h'' files.

Combining multiple types in an expression of the form

      <operand1><operator><operand2>

(where one of the operands is an ProBT variable), results in the following rule:

  1. If either operand is a plFloat the result is a plFloat.
  2. Otherwise, if either operand is a float, double or long double, the result is a plFloat.
  3. Otherwise, the result is a plInteger.

ProBT provides all the types conversions from plInteger and plFloat to int, unsigned int ,..., long double so that you can use ProBT variables for the passing of parameters.


next up previous contents index
: Loops : Variable values : Access and affectation   目次   索引
Juan-Manuel Ahuactzin 平成17年3月31日