227
mp_cast_to_exponential_string(MpSerializer *serializer, const MPNumber *x, gboolean eng_format)
225
mp_cast_to_exponential_string_real(MpSerializer *serializer, const MPNumber *x, GString *string, gboolean eng_format)
230
228
MPNumber t, z, base, base3, base10, base10inv, mantissa;
231
229
int exponent = 0;
234
const gchar *super_digits[] = {"⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹"};
236
string = g_string_sized_new(1024);
239
232
if (mp_is_negative(x))
273
266
fixed = mp_cast_to_string(serializer, &mantissa);
274
267
g_string_append(string, fixed);
279
g_string_append_printf(string, "×10"); // FIXME: Use the current base
281
exponent = -exponent;
282
g_string_append(string, "⁻");
285
super_value = g_strdup_printf("%d", exponent);
286
for (c = super_value; *c; c++)
287
g_string_append(string, super_digits[*c - '0']);
288
g_free (super_value);
275
append_exponent(GString *string, int exponent)
277
const gchar *super_digits[] = {"⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹"};
278
gchar *super_value, *c;
283
g_string_append_printf(string, "×10"); // FIXME: Use the current base
285
exponent = -exponent;
286
g_string_append(string, "⁻");
289
super_value = g_strdup_printf("%d", exponent);
290
for (c = super_value; *c; c++)
291
g_string_append(string, super_digits[*c - '0']);
292
g_free (super_value);
297
mp_cast_to_exponential_string(MpSerializer *serializer, const MPNumber *x, gboolean eng_format)
304
string = g_string_sized_new(1024);
306
mp_real_component(x, &x_real);
307
exponent = mp_cast_to_exponential_string_real(serializer, &x_real, string, eng_format);
308
append_exponent(string, exponent);
310
if (mp_is_complex(x)) {
312
gboolean force_sign = TRUE;
315
mp_imaginary_component(x, &x_im);
317
if (strcmp(string->str, "0") == 0) {
318
g_string_assign(string, "");
322
s = g_string_sized_new(1024);
323
exponent = mp_cast_to_exponential_string_real(serializer, &x_im, s, eng_format);
324
if (strcmp(s->str, "0") == 0 || strcmp(s->str, "+0") == 0 || strcmp(s->str, "−0") == 0) {
327
else if (strcmp(s->str, "1") == 0) {
328
g_string_append(string, "i");
330
else if (strcmp(s->str, "+1") == 0) {
331
g_string_append(string, "+i");
333
else if (strcmp(s->str, "−1") == 0) {
334
g_string_append(string, "−i");
337
if (strcmp(s->str, "+0") == 0)
338
g_string_append(string, "+");
339
else if (strcmp(s->str, "0") != 0)
340
g_string_append(string, s->str);
342
g_string_append(string, "i");
344
g_string_free(s, TRUE);
345
append_exponent(string, exponent);
291
348
result = g_strndup(string->str, string->len + 1);