Rev 1618 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* Project: OSLib |
2 | * Description: The OS Construction Kit |
||
3 | * Date: 1.6.2000 |
||
4 | * Idea by: Luca Abeni & Gerardo Lamastra |
||
5 | * |
||
6 | * OSLib is an SO project aimed at developing a common, easy-to-use |
||
7 | * low-level infrastructure for developing OS kernels and Embedded |
||
8 | * Applications; it partially derives from the HARTIK project but it |
||
9 | * currently is independently developed. |
||
10 | * |
||
11 | * OSLib is distributed under GPL License, and some of its code has |
||
12 | * been derived from the Linux kernel source; also some important |
||
13 | * ideas come from studying the DJGPP go32 extender. |
||
14 | * |
||
15 | * We acknowledge the Linux Community, Free Software Foundation, |
||
16 | * D.J. Delorie and all the other developers who believe in the |
||
17 | * freedom of software and ideas. |
||
18 | * |
||
19 | * For legalese, check out the included GPL license. |
||
20 | */ |
||
21 | |||
22 | #include <ll/i386/stdlib.h> |
||
23 | #include <ll/i386/string.h> |
||
24 | #include <ll/i386/limits.h> |
||
25 | #include <ll/stdarg.h> |
||
26 | #include <ll/ctype.h> |
||
27 | #include <ll/math.h> |
||
28 | |||
29 | FILE(strod); |
||
30 | |||
31 | double strtod(char *s,char **scan_end) |
||
32 | { |
||
33 | int sign,i; |
||
34 | double result = 0; |
||
35 | double value; |
||
36 | double mantissa = 0,divisor = 1; |
||
37 | unsigned short power = 0; |
||
38 | /* Evaluate sign */ |
||
39 | if (*s == '-') { |
||
40 | sign = -1; |
||
41 | s++; |
||
42 | } |
||
43 | else sign = 1; |
||
44 | /* Skip trailing zeros */ |
||
45 | while (*s == '0') s++; |
||
46 | /* Convert integer part */ |
||
47 | while (*s <= '9' && *s >= '0') { |
||
48 | value = *s++ - '0'; |
||
49 | result *= 10.0; |
||
50 | result += value; |
||
51 | } |
||
52 | /* Detect floating point & mantissa */ |
||
53 | if (*s == '.') { |
||
54 | s++; |
||
55 | while (*s <= '9' && *s >= '0') { |
||
56 | value = *s++ - '0'; |
||
57 | mantissa *= 10.0; |
||
58 | mantissa += value; |
||
59 | divisor *= 10.0; |
||
60 | } |
||
61 | } |
||
62 | mantissa /= divisor; |
||
63 | /* Adjust result */ |
||
64 | result += mantissa; |
||
65 | /* Adjust sign */ |
||
66 | result *= sign; |
||
67 | /* Detect exponent */ |
||
68 | if (*s == 'e' || *s == 'E') { |
||
69 | s++; |
||
70 | if (*s == '-') { |
||
71 | sign = -1; |
||
72 | s++; |
||
73 | } else if (*s == '+') { |
||
74 | sign = 1; |
||
75 | s++; |
||
76 | } |
||
77 | else sign = 1; |
||
78 | while (*s <= '9' && *s >= '0') { |
||
79 | value = *s++ - '0'; |
||
80 | power *= 10.0; |
||
81 | power += value; |
||
82 | } |
||
83 | } |
||
84 | /* Adjust result on exponent sign */ |
||
85 | if (sign > 0) for (i = 0; i < power; i++) result *= 10.0; |
||
86 | else for (i = 0; i < power; i++) result /= 10.0; |
||
87 | if (scan_end != 0L) *scan_end = s; |
||
88 | return(result); |
||
89 | } |