hp.com home products and services support and drivers solutions how to buy
cd-rom home
End of Jump to page title
HP OpenVMS systems
documentation

Jump to content


HP OpenVMS RTL Library (LIB$) Manual

HP OpenVMS RTL Library (LIB$) Manual


Previous Contents Index

Part 3
CVT$ Reference Section

This part provides a detailed discussion of the routines provided by the OpenVMS RTL (CVT$) facility.

CVT$CONVERT_FLOAT

The Convert Floating-Point Data Type routine provides a simplified options-interface for converting a floating-point data type to another supported floating-point data type.

Format

CVT$CONVERT_FLOAT input_value, input_type_code, output_value, output_type_code, options


RETURNS


OpenVMS usage: cond_value
type: longword (unsigned)
access: write only
mechanism: by value


Arguments

input_value


OpenVMS usage: varying_arg
type: unspecified
access: read only
mechanism: by reference

The address of a data area containing a floating-point number that is to be converted. The input_value argument may contain floating-point data in F_Floating, D_Floating, G_Floating, H_Floating, IEEE_S_Floating, IEEE_T_Floating, IEEE_X_Floating, IBM_Long_Floating, IBM_Short_Floating, or CRAY_Floating format. The value of the input_type_code argument determines the format and size of the input_value argument.

input_type_code


OpenVMS usage: longword_unsigned
type: longword (unsigned)
access: read only
mechanism: by value

The value of a longword bit mask specifying the type of floating-point data being passed in the input_value argument. Valid type codes are:
input_type_code Format Size in Bytes
CVT$K_VAX_F F_Floating 4
CVT$K_VAX_D D_Floating 8
CVT$K_VAX_G G_Floating 8
CVT$K_VAX_H H_Floating 16
CVT$K_IEEE_S IEEE_S_Floating 4
CVT$K_IEEE_T IEEE_T_Floating 8
CVT$K_IEEE_X IEEE_X_Floating 16
CVT$K_IBM_LONG IBM_Long_Floating 8
CVT$K_IBM_SHORT IBM_Short_Floating 4
CVT$K_CRAY CRAY_Floating 8

Declarations for the input_type_code argument are in the $CVTDEF module found in the system symbol libraries.

output_value


OpenVMS usage: varying_arg
type: unspecified
access: write only
mechanism: by reference

The address of a data area that receives the converted floating-point number. The output_value argument can contain floating-point data in F_Floating, D_Floating, G_Floating, H_Floating, IEEE_S_Floating, IEEE_T_Floating, IEEE_X_Floating, IBM_Long_Floating, IBM_Short_Floating, or CRAY_Floating format. The value of the output_type_code argument determines the size and format of the data placed into the output_value argument.

output_type_code


OpenVMS usage: longword_unsigned
type: longword (unsigned)
access: read only
mechanism: by value

The value of a longword bit mask specifying the type of floating-point data that the input_value argument will be converted into and returned in the output_value argument. Valid type codes are:
output_type_code Format Size in Bytes
CVT$K_VAX_F F_Floating 4
CVT$K_VAX_D D_Floating 8
CVT$K_VAX_G G_Floating 8
CVT$K_VAX_H H_Floating 16
CVT$K_IEEE_S IEEE_S_Floating 4
CVT$K_IEEE_T IEEE_T_Floating 8
CVT$K_IEEE_X IEEE_X_Floating 16
CVT$K_IBM_LONG IBM_Long_Floating 8
CVT$K_IBM_SHORT IBM_Short_Floating 4
CVT$K_CRAY CRAY_Floating 8

Declarations for the output_type_code argument are in the $CVTDEF module found in the system symbol libraries.

options


OpenVMS usage: mask_longword
type: longword (unsigned)
access: read only
mechanism: by value

Conversion option specifier. The options argument is the address of a longword bit mask in which each option bit set causes the corresponding option to be used during the conversion.

The following options can be specified using the options argument:
Option Description
CVT$M_ROUND_TO_NEAREST The default rounding option for conversions to IEEE data types. This IEEE Std. 754 rounding mode results in the representable output value nearest to the infinitely precise result. If the two nearest representable values are equally near, the one whose least significant bit is 0 is the result.
CVT$M_VAX_ROUNDING The default rounding option for conversions to non-IEEE data types. Performs "traditional" style rounding. This mode results in the representable output value nearest to the infinitely precise result. If the two nearest representable values are equally near, the output value is the closest to either positive infinity or negative infinity, depending on the sign of the input value.
CVT$M_TRUNCATE Round the output value toward zero (truncate).
CVT$M_ROUND_TO_POS Round the output value toward positive infinity.
CVT$M_ROUND_TO_NEG Round the output value toward negative infinity.
CVT$M_BIG_ENDIAN Interprets IEEE data types as Big Endian.
CVT$M_ERR_UNDERFLOW Report underflow conditions as errors.

Declarations for the options argument are in the $CVTDEF module found in the system symbol libraries.


Description

CVT$CONVERT_FLOAT is a general-purpose, floating-point conversion routine that converts any input_type_code floating-point data type into any output_type_code floating-point data type. The conversion is subject to the options specified in the options argument.

Note

OpenVMS compilers do not support arithmetic operations for all of the above floating-point data types. Additional floating-point data types are supported by this routine for data conversion purposes only.

Condition Values Returned

CVT$_NORMAL Normal successful completion.
CVT$_INPCONERR Input conversion error.
CVT$_INVINPTYP Invalid input type code.
CVT$_INVOPT Invalid option argument.
CVT$_INVOUTTYP Invalid output type code.
CVT$_INVVAL Input value was an invalid number or NaN.
CVT$_NEGINF Input value was negative infinity.
CVT$_OUTCONERR Output conversion error.
CVT$_OVERFLOW Overflow detected during conversion.
CVT$_POSINF Input value was positive infinity.
CVT$_UNDERFLOW Underflow detected during conversion.

Return status values are in the $CVTMSG module found in the system symbol libraries.


Example


/* 
** =================================================================== 
** 
**  Example of CVT$CONVERT_FLOAT 
** 
** ------------------------------------------------------------------- 
** 
**  This example program reads IEEE T floating-point numbers from an 
**  input file, converts them to VAX D floating-point numbers and 
**  writes the result to an output file. 
** 
**  The input and output file names can be specified as the first and 
**  second arguments on the command line as follows: 
** 
**     $ EXAMPLE IEEE_T_INPUT_FILE.DAT VAX_D_OUTPUT_FILE.DAT 
** 
**  If the input or output files are not included on the command 
**  line then the program prompts the user for them. 
** 
** =================================================================== 
*/ 
#include <stdio.h> 
 
unsigned long CVT$CONVERT_FLOAT(void    *input_value, 
                                unsigned long input_type, 
                                void    *output_value, 
                                unsigned long output_type, 
                                unsigned long options); 
 
globalvalue CVT$K_VAX_D; 
globalvalue CVT$K_IEEE_T; 
globalvalue CVT$M_ROUND_TO_NEAREST; 
globalvalue CVT$_NORMAL; 
 
main(int argc, char *argv[]) 
 
{ 
 
  double        D_Float_number; 
  unsigned long IEEE_Double_number[2]; 
  unsigned long options; 
  char          in_filename[80]; 
  char          out_filename[80]; 
  FILE          *in_file, *out_file; 
  unsigned long ret_status; 
 
/* 
** Find out where we are going to get the data from.  
** First look at the first argument of the command line.  
** If nothing is there, then attempt to use IEEE_T_IN.DAT. 
** ================================================================= 
*/ 
if (argc == 1) 
{ 
  printf("Enter input data file: [IEEE_T_IN.DAT]: "); 
  if (gets(in_filename) == NULL) 
    exit(1); 
 
  if (strlen(in_filename) == 0)  
    strcpy(in_filename, "IEEE_T_IN.DAT"); 
}    
else 
  strcpy(in_filename, argv[1]); 
 
/* 
** Find out where we are going to put the output data. 
** First look at the second argument of the command line.  
** If nothing is there, then put it in VAX_D_OUT.DAT 
** ================================================================= 
*/ 
if (argc <= 2) 
{ 
  printf("Enter output data file: [VAX_D_OUT.DAT]: "); 
  if (gets(out_filename) == NULL) 
    exit(1); 
 
  if (strlen(out_filename) == 0)  
    strcpy(out_filename, "VAX_D_OUT.DAT"); 
}    
else 
  strcpy(out_filename, argv[2]); 
 
/* 
** Open the input and output files. 
** ----------------------------------------------------------------- 
*/ 
if ((in_file = fopen(in_filename, "r")) == NULL) 
{ 
  fprintf(stderr, "%s couldn't open file %s\n", argv[0], in_filename); 
  exit(1); 
} 
 
out_file = fopen(out_filename, "wb"); 
 
options     = CVT$M_ROUND_TO_NEAREST; 
ret_status  = CVT$_NORMAL; 
 
/* 
** Read in each number from the file, convert it, and write it to 
** the output file. 
** ================================================================= 
*/ 
while ((fread (&IEEE_Double_number[0], 
               sizeof(IEEE_Double_number), 
               1, 
               in_file) == 1) && 
       (ret_status == CVT$_NORMAL)) 
{ 
  ret_status = CVT$CONVERT_FLOAT(&IEEE_Double_number[0], CVT$K_IEEE_T, 
                                 &D_Float_number, CVT$K_VAX_D, 
                                 options); 
 
  if (ret_status == CVT$NORMAL) 
  { 
    fwrite(&D_Float_number, sizeof(D_Float_number), 1, out_file); 
    printf("Converted data: %lf.\n", D_Float_number); 
  } 
} 
fclose(in_file); 
fclose(out_file); 
 
if (ret_status == CVT$_NORMAL) 
  exit(1); 
else 
  exit(ret_status); 
} 
      


CVT$FTOF

The Convert Floating-Point Data Type routine converts floating-point data types to other supported floating-point data types and allows additional control over the converted results. CVT$FTOF functionality is also available on other platforms supported by HP.

Format

status = CVT$FTOF input_value, input_type_code, output_value, output_type_code, options


RETURNS


OpenVMS usage: mask_longword
type: longword (unsigned)
access: write only
mechanism: by value

The status return value is an unsigned longword bit mask containing the condition codes raised by the function. CVT$FTOF returns CVT$K_NORMAL; otherwise, it sets one or more recoverable and unrecoverable conditions. Use the following condition names to determine which conditions are set:
Condition Name Condition (always reported by default)
CVT$K_NORMAL Normal successful completion.
CVT$M_INVALID_INPUT_TYPE Invalid input type code.
CVT$M_INVALID_OUTPUT_TYPE Invalid output type code.
CVT$M_INVALID_OPTION Invalid option argument.
Condition Name Condition (reported only if the CVT$M_REPORT_ALL option is selected)
CVT$M_RESULT_INFINITE Conversion produced an infinite result. 1
CVT$M_RESULT_DENORMALIZED Conversion produced a denormalized result. 1
CVT$M_RESULT_OVERFLOW_RANGE Conversion yielded an exponent greater than 60000 (8). 2
CVT$M_RESULT_UNDERFLOW_RANGE Conversion yielded an exponent less than 20000 (8). 2
CVT$M_RESULT_UNNORMALIZED Conversion produced an unnormalized result. 3
CVT$M_RESULT_INVALID Conversion result is either ROP (reserved operand), NaN (not a number), or closest equivalent. CRAY and IBM data types return 0. 4
CVT$M_RESULT_OVERFLOW Conversion resulted in overflow. 4
CVT$M_RESULT_UNDERFLOW Conversion resulted in underflow. 4
CVT$M_RESULT_INEXACT Conversion resulted in a loss of precision. 4


1For IEEE data type conversions.
2For CRAY data type conversions.
3For IBM data type conversions.
4For all data type conversions.

Return status values are in the $CVTDEF module in the system symbol libraries.


Arguments

input_value


OpenVMS usage: varying_arg
type: unspecified
access: read only
mechanism: by reference

The address of a data area containing a floating-point number to be converted. The number can be floating-point data in one of the following formats:
F_Floating Big_Endian_IEEE_S_Floating
D_Floating Big_Endian_IEEE_T_Floating
G_Floating Big_Endian_IEEE_X_Floating
H_Floating IBM_Long_Floating
IEEE_S_Floating IBM_Short_Floating
IEEE_T_Floating CRAY_Floating_Single
IEEE_X_Floating  

The value of the input_type_code argument determines the format and size of the input_value argument.

input_type_code


OpenVMS usage: longword_unsigned
type: longword (unsigned)
access: read only
mechanism: by value

The value of a longword bit mask specifying the type of floating-point data being passed in the input_value argument. Valid type codes are:
Input_type_code Format Size in Bytes
CVT$K_VAX_F F_Floating 4
CVT$K_VAX_D D_Floating 8
CVT$K_VAX_G G_Floating 8
CVT$K_VAX_H H_Floating 16
CVT$K_IEEE_S IEEE_S_Floating 4
CVT$K_IEEE_T IEEE_T_Floating 8
CVT$K_IEEE_X IEEE_X_Floating 16
CVT$K_BIG_ENDIAN_IEEE_S Big_Endian_IEEE_S_Floating 4
CVT$K_BIG_ENDIAN_IEEE_T Big_Endian_IEEE_T_Floating 8
CVT$K_BIG_ENDIAN_IEEE_X Big_Endian_IEEE_X_Floating 16
CVT$K_IBM_LONG IBM_Long_Floating 8
CVT$K_IBM_SHORT IBM_Short_Floating 4
CVT$K_CRAY_SINGLE CRAY_Floating 8

Declarations for the input_type_code argument are in the $CVTDEF module found in the system symbol libraries.

output_value


OpenVMS usage: varying_arg
type: unspecified
access: write only
mechanism: by reference

The address of a data area that receives the converted floating-point number. The number can be floating-point data in F_Floating, D_Floating, G_Floating, H_Floating, IEEE_S_Floating, IEEE_T_Floating, IEEE_X_Floating, Big_Endian_IEEE_S_Floating, Big_Endian_IEEE_T_Floating, Big_Endian_IEEE_X_Floating, IBM_Long_Floating, IBM_Short_Floating, or CRAY_Floating_Single format. The value of the output_type_code argument determines the size and format of the converted floating-point number.

output_type_code


OpenVMS usage: longword_unsigned
type: longword (unsigned)
access: read only
mechanism: by value

The value of a longword bit mask specifying the type of floating-point data that the input_value argument will be converted into and returned in the output_value argument. Valid type codes are:
Output_type_code Format Size in Bytes
CVT$K_VAX_F F_Floating 4
CVT$K_VAX_D D_Floating 8
CVT$K_VAX_G G_Floating 8
CVT$K_VAX_H H_Floating 16
CVT$K_IEEE_S IEEE_S_Floating 4
CVT$K_IEEE_T IEEE_T_Floating 8
CVT$K_IEEE_X IEEE_X_Floating 16
CVT$K_BIG_ENDIAN_IEEE_S Big_Endian_IEEE_S_Floating 4
CVT$K_BIG_ENDIAN_IEEE_T Big_Endian_IEEE_T_Floating 8
CVT$K_BIG_ENDIAN_IEEE_X Big_Endian_IEEE_X_Floating 16
CVT$K_IBM_LONG IBM_Long_Floating 8
CVT$K_IBM_SHORT IBM_Short_Floating 4
CVT$K_CRAY_SINGLE CRAY_Floating 8

Declarations for the output_type_code argument are in the $CVTDEF module found in the system symbol libraries.

options


OpenVMS usage: mask_longword
type: longword (unsigned)
access: read only
mechanism: by value

Conversion option specifier. The options argument is the address of a longword bit mask in which each option bit set causes the corresponding option to be used during the conversion. Provide a zero (0) value to the options argument to select default behavior or choose one or more options (status condition option, rounding options, "FORCE" options, CRAY and IBM options) from the following tables. Specify only the options that apply to your conversion. A conflicting or incompatible options argument is reported as an error (CVT$M_INVALID_OPTION).
Applicable Conversion Option Description
  Status Condition Option
All CVT$M_REPORT_ALL Report all applicable status conditions as the default. The reporting of recoverable status conditions is disabled by default when this option is not used.
  Rounding Options
All CVT$M_ROUND_TO_NEAREST The default rounding option for conversions to IEEE data types. This IEEE Std. 754 rounding mode results in the representable output value nearest to the infinitely precise result. If the two nearest representable values are equally near, the one whose least significant bit is 0 is the result.
All CVT$M_BIASED_ROUNDING The default rounding option for conversions to non-IEEE data types. Performs "traditional" style rounding. This mode results in the representable output value nearest to the infinitely precise result. If the two nearest representable values are equally near, the output value is the closest to either positive infinity or negative infinity depending on the sign of the input value.
All CVT$M_ROUND_TO_ZERO Round the output value toward zero (truncate).
All CVT$M_ROUND_TO_POS Round the output value toward positive infinity.
All CVT$M_ROUND_TO_NEG Round the output value toward negative infinity.
  "FORCE" Options
All CVT$M_FORCE_ALL_SPECIAL_VALUES Apply all applicable "FORCE" options for the current conversion.
IEEE CVT$M_FORCE_DENORM_TO_ZERO 1 Force a denormalized IEEE output value to zero.
IEEE CVT$M_FORCE_INF_TO_MAX_FLOAT 1 Force a positive IEEE infinite output value to +max_float and force a negative IEEE infinite output value to --max_float.
IEEE or VAX CVT$M_FORCE_INVALID_TO_ZERO 2 Force an invalid IEEE NaN (not a number) output value or a VAX ROP (reserved operand) output value to zero.
  CRAY Format Conversion Options
CRAY CVT$M_ALLOW_OVRFLW_RANGE_VALUES Allow an input/output exponent value > 60000 (8).
CRAY CVT$M_ALLOW_UDRFLW_RANGE_VALUES Allow an input/output exponent value < 20000 (8).
IBM Format Conversion Option
IBM CVT$M_ALLOW_UNNORMALIZED_VALUES Allow unnormalized input arguments. Allow an unnormalized output value for a small value that would normalize to zero.

1This option is valid only for conversions to IEEE output values.
2This option is valid only for conversions to IEEE or VAX output values.


Previous Next Contents Index