home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d0xx / d056 / mcad.lha / mCAD / mp / source / ffp.c next >
Encoding:
C/C++ Source or Header  |  1987-03-02  |  839 b   |  40 lines

  1. #include <string.h>
  2. #include "ffp.h"
  3.  
  4. FFP FFPLARGE = 1.0e10, FFPSMALL = 1.0e-10;
  5.  
  6. #ifdef FASTFLOAT
  7. FFP atoFFP(string)
  8. register char *string;
  9. {
  10.    register char *s, *end;
  11.    register FFP val;
  12.    register int epart, fpart, fexp;
  13.    int sign;
  14.  
  15.    s = string;
  16.    while (*s == ' ') s++;
  17.    sign = ((*s == '-') ? -1 : 1);
  18.  
  19.    val = (FFP)abs(atoi(string));
  20.  
  21.    end = string;
  22.    while (*end == ' ') end++;
  23.    while (*end && (*end != ' ')) end++;
  24.  
  25.    if (!(s = strchr(string,'e'))) s = strchr(string,'E');
  26.    epart = ((s && s<end) ? atoi(s+1) : 0);
  27.  
  28.    s = strchr(string, '.');
  29.    if (s && s<end) {
  30.       for (++s, fpart=fexp=0; (*s <= '9') && (*s >= '0'); s++) {
  31.          fexp--;
  32.          fpart = fpart*10 + (*s - '0');
  33.       }
  34.       val += (FFP)(fpart * pow(10., (FFP)fexp)); 
  35.    }
  36.  
  37.    return ((FFP)(val * sign * pow(10., (FFP)epart)));
  38. }
  39. #endif
  40.