home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / Watcher / to_double.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-02  |  670 b   |  33 lines

  1. /*
  2.    to_double: convert a struct anything to a double, no matter what type
  3.    it is currently.
  4.  
  5.    I'm not completely happy with this; should make better use of
  6.    the info we are provided about the type of any instead of calling
  7.    this routine.
  8.  
  9.    Kenneth Ingham
  10. */
  11.  
  12. #include "defs.h"
  13. #include "y.tab.h"
  14.  
  15. double
  16. to_double(any)
  17. struct everything *any;
  18. {
  19.     switch (any->type) {
  20.         case STRING:
  21.             return (double)atof(any->data.string);
  22.         case FLOAT:
  23.             return any->data.real;
  24.         case INTEGER:
  25.             return (double)any->data.integer;
  26.         default: 
  27.             fprintf(stderr, "Unable to convert type %d",any->type);
  28.             fprintf(stderr, " to double.\n");
  29.             exit(1);
  30.     }
  31.     /*NOTREACHED*/
  32. }
  33.