2 ***********************************************************
3 $SNARK_Header: S N A R K 1 4 - A PICTURE RECONSTRUCTION PROGRAM $
4 $HeadURL: svn://dig.cs.gc.cuny.edu/snark/trunk/src/snark/getnum.cpp $
5 $LastChangedRevision: 80 $
6 $Date: 2014-07-01 21:01:54 -0400 (Tue, 01 Jul 2014) $
8 ***********************************************************
10 GETNUM SCANS THE INPUT AREA FOR THE NEXT NUMBER AND RETURNS
11 THE INTERNAL FLOATING POINT REPRESENTATION OF THE NUMBER.
12 IF THE INPUT AREA DOES NOT CONTAIN A NUMBER, ZERO IS
13 RETURNED AND EOL IS SET TO .TRUE.
25 #include "inputfile.h"
27 REAL InputFile_class::getnum(BOOLEAN NewLine, BOOLEAN* eol)
30 REAL mainval = 0, mainsign = 1;
31 REAL expval = 0, expsign = 1;
32 REAL numdigitsafterdot = 0;
38 // FIND START OF NUMBER (FIRST DIGIT OR DECIMAL POINT) AND SIGN
44 if (ptr > DATASIZ) // bug 190 - swr - 12/09/05
61 while (isdigit(nextch))
63 mainval = mainval * 10.0 + chtoin(nextch);
71 while (isdigit(nextch))
73 // try to parse (digit*)
74 mainval = mainval * 10 + chtoin(nextch);
75 numdigitsafterdot += 1; // number of digits after '.'
79 } // --period read after digit
80 } // --digit read before (if at all) period
92 "\n **** illegal floating point modifier encountered\n **** program aborted\n");
95 while (isdigit(nextch))
97 mainval = mainval * 10 + chtoin(nextch);
98 numdigitsafterdot += 1; // number of digits after '.'
102 } // --period read before any digit
105 // {digit+[.digit*],.digit+} not found
107 "\n **** illegal floating point modifier encountered\n **** program aborted\n");
112 if ((nextch == 'e') || (nextch == 'E'))
114 // try to parse ([+,-]digit[digit])
131 if (!isdigit(nextch))
134 "\n **** illegal floating point modifier encountered\n **** program aborted\n");
139 expval = chtoin(nextch);
145 // second possible digit
146 expval = expval * 10 + chtoin(nextch);
152 if (!isspace(nextch))
154 // there is junk at the end
156 "\n **** illegal floating point modifier encountered\n **** program aborted\n");
160 return mainsign * mainval * pow(10, (expsign * expval - numdigitsafterdot));