comparison gcc/real.c @ 36:855418dad1a3

gcc-4.4-20091020
author e075725
date Tue, 22 Dec 2009 21:19:31 +0900
parents a06113de4d67
children 77e2b8dfacca
comparison
equal deleted inserted replaced
19:58ad6c70ea60 36:855418dad1a3
108 const REAL_VALUE_TYPE *); 108 const REAL_VALUE_TYPE *);
109 static int do_compare (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *, int); 109 static int do_compare (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *, int);
110 static void do_fix_trunc (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *); 110 static void do_fix_trunc (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *);
111 111
112 static unsigned long rtd_divmod (REAL_VALUE_TYPE *, REAL_VALUE_TYPE *); 112 static unsigned long rtd_divmod (REAL_VALUE_TYPE *, REAL_VALUE_TYPE *);
113 static void decimal_from_integer (REAL_VALUE_TYPE *);
114 static void decimal_integer_string (char *, const REAL_VALUE_TYPE *,
115 size_t);
113 116
114 static const REAL_VALUE_TYPE * ten_to_ptwo (int); 117 static const REAL_VALUE_TYPE * ten_to_ptwo (int);
115 static const REAL_VALUE_TYPE * ten_to_mptwo (int); 118 static const REAL_VALUE_TYPE * ten_to_mptwo (int);
116 static const REAL_VALUE_TYPE * real_digit (int); 119 static const REAL_VALUE_TYPE * real_digit (int);
117 static void times_pten (REAL_VALUE_TYPE *, int); 120 static void times_pten (REAL_VALUE_TYPE *, int);
2166 } 2169 }
2167 2170
2168 normalize (r); 2171 normalize (r);
2169 } 2172 }
2170 2173
2171 if (mode != VOIDmode) 2174 if (DECIMAL_FLOAT_MODE_P (mode))
2175 decimal_from_integer (r);
2176 else if (mode != VOIDmode)
2172 real_convert (r, mode, r); 2177 real_convert (r, mode, r);
2178 }
2179
2180 /* Render R, an integral value, as a floating point constant with no
2181 specified exponent. */
2182
2183 static void
2184 decimal_integer_string (char *str, const REAL_VALUE_TYPE *r_orig,
2185 size_t buf_size)
2186 {
2187 int dec_exp, digit, digits;
2188 REAL_VALUE_TYPE r, pten;
2189 char *p;
2190 bool sign;
2191
2192 r = *r_orig;
2193
2194 if (r.cl == rvc_zero)
2195 {
2196 strcpy (str, "0.");
2197 return;
2198 }
2199
2200 sign = r.sign;
2201 r.sign = 0;
2202
2203 dec_exp = REAL_EXP (&r) * M_LOG10_2;
2204 digits = dec_exp + 1;
2205 gcc_assert ((digits + 2) < (int)buf_size);
2206
2207 pten = *real_digit (1);
2208 times_pten (&pten, dec_exp);
2209
2210 p = str;
2211 if (sign)
2212 *p++ = '-';
2213
2214 digit = rtd_divmod (&r, &pten);
2215 gcc_assert (digit >= 0 && digit <= 9);
2216 *p++ = digit + '0';
2217 while (--digits > 0)
2218 {
2219 times_pten (&r, 1);
2220 digit = rtd_divmod (&r, &pten);
2221 *p++ = digit + '0';
2222 }
2223 *p++ = '.';
2224 *p++ = '\0';
2225 }
2226
2227 /* Convert a real with an integral value to decimal float. */
2228
2229 static void
2230 decimal_from_integer (REAL_VALUE_TYPE *r)
2231 {
2232 char str[256];
2233
2234 decimal_integer_string (str, r, sizeof (str) - 1);
2235 decimal_real_from_string (r, str);
2173 } 2236 }
2174 2237
2175 /* Returns 10**2**N. */ 2238 /* Returns 10**2**N. */
2176 2239
2177 static const REAL_VALUE_TYPE * 2240 static const REAL_VALUE_TYPE *