HP OpenVMS Systems

ask the wizard
Content starts here

help with C floating syntax

» close window

The Question is:

 
Floating-point in DEC C(V5.0) & Pascal(V5.6-59)
Following code will not produce the result as I expected:
 
float vl_float;
double vl_double;
 
vl_float = 100.09;
vl_double = 1.0009D2;
 
if (vl_float < 100.09) printf("vl_float by assignment is
less than 100.09\n");
 
if (vl_double < 1.0009D2) printf("vl_double by assignment
is less than 1.0009D2\n");
 
Run this program on OpenVMS6.1/AXP and the comparison
result will not be the equal, e.g. vl_float != 100.09
and vl_double != 1.0009D2.
 
This is a very basic problem. Can anybody there explain?
Please reply ASAP. Thanks in advance.
 
Rgds,
HD Wang
 
 


The Answer is :

 
#include <stdio.h>
#include <stdlib.h>
main()
  {
  float vl_float;
  double vl_double;
 
  vl_float = 100.09;
  vl_double = 1.0009e2;
 
  if (vl_float < (float) 100.09)
    printf("vl_float by assignment is less than 100.09\n");
 
  if (vl_double < (double) 1.0009e2)
    printf("vl_double by assignment is less than 1.0009D2\n");
 
  return 1;
  }

answer written or last revised on ( 21-APR-1998 )

» close window