Subversion Repositories Kolibri OS

Rev

Rev 9230 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9230 Rev 9765
Line 1... Line 1...
1
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
1
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
2
#include 
2
#include 
Line -... Line 3...
-
 
3
 
3
 
4
#ifndef unconst
-
 
5
#define unconst(__v, __t) __extension__({union { const __t __cp; __t __p; } __q; __q.__cp = __v; __q.__p; })
Line 4... Line 6...
4
#define unconst(__v, __t) __extension__ ({union { const __t __cp; __t __p; } __q; __q.__cp = __v; __q.__p;})
6
#endif
5
 
7
 
6
double strtod(const char *s, char **sret)
8
double strtod(const char* s, char** sret)
7
{
9
{
Line 21... Line 23...
21
    while ((*s == ' ') || (*s == '\t'))
23
    while ((*s == ' ') || (*s == '\t'))
22
        s++;
24
        s++;
Line 23... Line 25...
23
        
25
 
24
    if (*s == '+')
26
    if (*s == '+')
25
        s++;
27
        s++;
26
    else if (*s == '-')
-
 
27
    {
28
    else if (*s == '-') {
28
        sign = -1;
29
        sign = -1;
29
        s++;
30
        s++;
Line 30... Line 31...
30
    }
31
    }
31
 
-
 
32
    while ((*s >= '0') && (*s <= '9'))
32
 
33
    {
33
    while ((*s >= '0') && (*s <= '9')) {
34
        flags |= 1;
34
        flags |= 1;
35
        r *= 10.0;
35
        r *= 10.0;
36
        r += *s - '0';
36
        r += *s - '0';
Line 37... Line 37...
37
        s++;
37
        s++;
38
    }
-
 
39
 
38
    }
40
    if (*s == '.')
39
 
Line 41... Line 40...
41
    { 
40
    if (*s == '.') {
42
        d = 0.1L;
-
 
43
        s++;
41
        d = 0.1L;
44
    
42
        s++;
45
        while ((*s >= '0') && (*s <= '9'))
43
 
46
        {
44
        while ((*s >= '0') && (*s <= '9')) {
47
            flags |= 2;
45
            flags |= 2;
48
            r += d * (*s - '0');
46
            r += d * (*s - '0');
Line 49... Line 47...
49
            s++;
47
            s++;
50
            d *= 0.1L;
-
 
51
        }
48
            d *= 0.1L;
52
    }
49
        }
53
 
50
    }
54
    if (flags == 0)
51
 
Line 55... Line 52...
55
    {
52
    if (flags == 0) {
56
        if (sret)
-
 
57
        *sret = unconst(s, char *);
53
        if (sret)
58
        return 0;
54
            *sret = unconst(s, char*);
59
    }
55
        return 0;
60
 
56
    }
61
    if ((*s == 'e') || (*s == 'E'))
-
 
62
    {
57
 
63
        s++;
58
    if ((*s == 'e') || (*s == 'E')) {
64
        if (*s == '+')
59
        s++;
Line 65... Line 60...
65
            s++;
60
        if (*s == '+')
66
        else if (*s == '-')
-
 
67
        {
61
            s++;
68
            s++;
62
        else if (*s == '-') {
69
            esign = -1;
63
            s++;
70
        }
64
            esign = -1;
Line 71... Line 65...
71
        
65
        }
72
        if ((*s < '0') || (*s > '9'))
-
 
73
        {
66
 
74
            if (sret)
67
        if ((*s < '0') || (*s > '9')) {
75
	            *sret = unconst(s, char *);
68
            if (sret)
76
            return r;
69
                *sret = unconst(s, char*);
77
        }
70
            return r;