-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathffpatof.c
43 lines (35 loc) · 957 Bytes
/
ffpatof.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <ctype.h>
#include <exec/types.h>
#include <proto/mathffp.h>
#include "hdrs/atof.p.h"
#include "hdrs/mand.int.d.h"
/*------------------------------------------------------------------------*/
FLOAT ffpatof(STRPTR str)
{
BOOL minus=FALSE;
FLOAT ffp=0.0;
for(;*str==' ';str++);
switch(*str){
case '-': minus=TRUE;
case '+': str++;
}
for(;isdigit(*str);str++){
ffp*=10.0;
ffp+=(FLOAT)(*str-'0');
}
if(*str=='.'){
FLOAT div;
str++;
for(div=10.0;isdigit(*str);div*=10.0,str++)
ffp+=(FLOAT)(*str-'0')/div;
}
if(minus) ffp=-ffp;
return(ffp);
}
/* *** Lattice crashes when it compile the following lines... ***
*
* LONG ffp2int(FLOAT ffp)
* {
* return((LONG)(ffp*(FLOAT)FUDGE);
* }
*/