annotate libass/ass_strtod.c @ 36418:155e6100949c

Code changes to avoid additional unnecessary re-inits.
author reimar
date Sat, 16 Nov 2013 23:23:46 +0000
parents e64df5862cea
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
1 /*
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
2 * Copyright (c) 1988-1993 The Regents of the University of California.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
3 * Copyright (c) 1994 Sun Microsystems, Inc.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
4 *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
5 * Permission to use, copy, modify, and distribute this
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
6 * software and its documentation for any purpose and without
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
7 * fee is hereby granted, provided that the above copyright
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
8 * notice appear in all copies. The University of California
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
9 * makes no representations about the suitability of this
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
10 * software for any purpose. It is provided "as is" without
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
11 * express or implied warranty.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
12 *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
13 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
14
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
15 #include <stdlib.h>
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
16 #include <ctype.h>
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
17 #include <errno.h>
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
18
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
19 const
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
20 static int maxExponent = 511; /* Largest possible base 10 exponent. Any
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
21 * exponent larger than this will already
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
22 * produce underflow or overflow, so there's
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
23 * no need to worry about additional digits.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
24 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
25
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
26 const
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
27 static double powersOf10[] = { /* Table giving binary powers of 10. Entry */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
28 10., /* is 10^2^i. Used to convert decimal */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
29 100., /* exponents into floating-point numbers. */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
30 1.0e4,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
31 1.0e8,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
32 1.0e16,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
33 1.0e32,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
34 1.0e64,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
35 1.0e128,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
36 1.0e256
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
37 };
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
38
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
39 /*
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
40 *----------------------------------------------------------------------
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
41 *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
42 * strtod --
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
43 *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
44 * This procedure converts a floating-point number from an ASCII
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
45 * decimal representation to internal double-precision format.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
46 *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
47 * Results:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
48 * The return value is the double-precision floating-point
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
49 * representation of the characters in string. If endPtr isn't
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
50 * NULL, then *endPtr is filled in with the address of the
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
51 * next character after the last one that was part of the
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
52 * floating-point number.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
53 *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
54 * Side effects:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
55 * None.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
56 *
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
57 *----------------------------------------------------------------------
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
58 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
59
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
60 double
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
61 ass_strtod(string, endPtr)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
62 const char *string; /* A decimal ASCII floating-point number,
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
63 * optionally preceded by white space.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
64 * Must have form "-I.FE-X", where I is the
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
65 * integer part of the mantissa, F is the
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
66 * fractional part of the mantissa, and X
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
67 * is the exponent. Either of the signs
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
68 * may be "+", "-", or omitted. Either I
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
69 * or F may be omitted, or both. The decimal
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
70 * point isn't necessary unless F is present.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
71 * The "E" may actually be an "e". E and X
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
72 * may both be omitted (but not just one).
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
73 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
74 char **endPtr; /* If non-NULL, store terminating character's
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
75 * address here. */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
76 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
77 int sign, expSign = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
78 double fraction, dblExp, *d;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
79 register const char *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
80 register int c;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
81 int exp = 0; /* Exponent read from "EX" field. */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
82 int fracExp = 0; /* Exponent that derives from the fractional
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
83 * part. Under normal circumstatnces, it is
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
84 * the negative of the number of digits in F.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
85 * However, if I is very long, the last digits
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
86 * of I get dropped (otherwise a long I with a
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
87 * large negative exponent could cause an
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
88 * unnecessary overflow on I alone). In this
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
89 * case, fracExp is incremented one for each
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
90 * dropped digit. */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
91 int mantSize; /* Number of digits in mantissa. */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
92 int decPt; /* Number of mantissa digits BEFORE decimal
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
93 * point. */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
94 const char *pExp; /* Temporarily holds location of exponent
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
95 * in string. */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
96
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
97 /*
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
98 * Strip off leading blanks and check for a sign.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
99 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
100
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
101 p = string;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
102 while (isspace(*p)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
103 p += 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
104 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
105 if (*p == '-') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
106 sign = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
107 p += 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
108 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
109 if (*p == '+') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
110 p += 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
111 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
112 sign = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
113 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
114
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
115 /*
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
116 * Count the number of digits in the mantissa (including the decimal
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
117 * point), and also locate the decimal point.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
118 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
119
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
120 decPt = -1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
121 for (mantSize = 0; ; mantSize += 1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
122 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
123 c = *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
124 if (!isdigit(c)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
125 if ((c != '.') || (decPt >= 0)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
126 break;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
127 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
128 decPt = mantSize;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
129 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
130 p += 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
131 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
132
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
133 /*
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
134 * Now suck up the digits in the mantissa. Use two integers to
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
135 * collect 9 digits each (this is faster than using floating-point).
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
136 * If the mantissa has more than 18 digits, ignore the extras, since
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
137 * they can't affect the value anyway.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
138 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
139
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
140 pExp = p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
141 p -= mantSize;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
142 if (decPt < 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
143 decPt = mantSize;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
144 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
145 mantSize -= 1; /* One of the digits was the point. */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
146 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
147 if (mantSize > 18) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
148 fracExp = decPt - 18;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
149 mantSize = 18;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
150 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
151 fracExp = decPt - mantSize;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
152 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
153 if (mantSize == 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
154 fraction = 0.0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
155 p = string;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
156 goto done;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
157 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
158 int frac1, frac2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
159 frac1 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
160 for ( ; mantSize > 9; mantSize -= 1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
161 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
162 c = *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
163 p += 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
164 if (c == '.') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
165 c = *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
166 p += 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
167 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
168 frac1 = 10*frac1 + (c - '0');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
169 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
170 frac2 = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
171 for (; mantSize > 0; mantSize -= 1)
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
172 {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
173 c = *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
174 p += 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
175 if (c == '.') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
176 c = *p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
177 p += 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
178 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
179 frac2 = 10*frac2 + (c - '0');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
180 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
181 fraction = (1.0e9 * frac1) + frac2;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
182 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
183
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
184 /*
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
185 * Skim off the exponent.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
186 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
187
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
188 p = pExp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
189 if ((*p == 'E') || (*p == 'e')) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
190 p += 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
191 if (*p == '-') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
192 expSign = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
193 p += 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
194 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
195 if (*p == '+') {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
196 p += 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
197 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
198 expSign = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
199 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
200 while (isdigit(*p)) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
201 exp = exp * 10 + (*p - '0');
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
202 p += 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
203 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
204 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
205 if (expSign) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
206 exp = fracExp - exp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
207 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
208 exp = fracExp + exp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
209 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
210
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
211 /*
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
212 * Generate a floating-point number that represents the exponent.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
213 * Do this by processing the exponent one bit at a time to combine
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
214 * many powers of 2 of 10. Then combine the exponent with the
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
215 * fraction.
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
216 */
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
217
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
218 if (exp < 0) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
219 expSign = 1;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
220 exp = -exp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
221 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
222 expSign = 0;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
223 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
224 if (exp > maxExponent) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
225 exp = maxExponent;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
226 errno = ERANGE;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
227 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
228 dblExp = 1.0;
31853
e64df5862cea Import libass 0.9.10
greg
parents: 30200
diff changeset
229 for (d = (double *) powersOf10; exp != 0; exp >>= 1, d += 1) {
30200
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
230 if (exp & 01) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
231 dblExp *= *d;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
232 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
233 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
234 if (expSign) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
235 fraction /= dblExp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
236 } else {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
237 fraction *= dblExp;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
238 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
239
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
240 done:
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
241 if (endPtr != NULL) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
242 *endPtr = (char *) p;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
243 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
244
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
245 if (sign) {
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
246 return -fraction;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
247 }
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
248 return fraction;
48d020c5ceca Update internal libass copy to commit 8db4a5
greg
parents:
diff changeset
249 }